cloud_hypervisor_client/lib.rs
1//!Unofficial Rust crate for accessing the [cloud-hypervisor REST API](https://github.com/cloud-hypervisor/cloud-hypervisor/blob/main/docs/api.md)
2//!
3//!# Overview
4//!
5//!The `cloud-hypervisor-client` crate can be used for managing the endpoints provided by the cloud-hypervisor REST API socket in your Rust project.
6//!
7//!The API client code of this crate has been auto-generated from the [Official OpenAPI Description for the cloud-hypervisor REST API](https://raw.githubusercontent.com/cloud-hypervisor/cloud-hypervisor/master/vmm/src/api/openapi/cloud-hypervisor.yaml) using [OpenAPI Generator](https://openapi-generator.tech/).
8//!
9//!# Example
10//!
11//!Get information about a VM:
12//!
13//!```rust,no_run
14//! use cloud_hypervisor_client::apis::DefaultApi;
15//! use cloud_hypervisor_client::socket_based_api_client;
16//!
17//! #[tokio::main]
18//! async fn main() -> Result<(), String> {
19//! let client = socket_based_api_client("cloud_hypervisor_vm_socket.sock");
20//!
21//! let vm_info = client.vm_info_get()
22//! .await
23//! .map_err(|err| format!("API call to vm_info_get failed: {:?}", err))?;
24//!
25//! println!("Received vm info: {vm_info:?}");
26//!
27//! Ok(())
28//! }
29//!```
30//!
31//! For more examples check out the [examples](https://github.com/lpotthast/cloud-hypervisor-client) folder in the Git repository.
32//!
33//!# Selecting TLS implementation
34//!
35//!The underlying TLS implementation for `reqwest` can be selected using [Cargo features](https://doc.rust-lang.org/stable/cargo/reference/manifest.html#the-features-section):
36//!- **default-tls** *(enabled by default)*: Provides TLS support to connect over HTTPS.
37//!- **native-tls**: Enables TLS functionality provided by `native-tls`.
38//!- **native-tls-vendored**: Enables the `vendored` feature of `native-tls`.
39//!- **rustls-tls**: Enables TLS functionality provided by `rustls`.
40//!
41//!(Refer to [Optional Features](https://docs.rs/reqwest/latest/reqwest/#optional-features) in the `reqwest` documentation.)
42//!
43//!Example for using the TLS functionality provided by `rustls`:
44//!```toml
45//![dependencies]
46//!cloud_hypervisor_client = { version = "*", default-features = false, features = ["rustls-tls"] }
47//!```
48
49#![allow(unused_imports)]
50#![allow(clippy::too_many_arguments)]
51
52extern crate futures;
53extern crate hyper;
54extern crate serde;
55extern crate serde_json;
56extern crate serde_repr;
57extern crate url;
58
59use crate::apis::configuration::Configuration;
60use crate::apis::DefaultApiClient;
61use std::path::Path;
62use std::sync::Arc;
63
64pub mod apis;
65pub mod models;
66
67pub type SocketBasedApiClient = DefaultApiClient<hyperlocal::UnixConnector>;
68
69pub fn socket_based_api_client(vmm_socket_path: impl AsRef<Path>) -> SocketBasedApiClient {
70 use hyperlocal::UnixClientExt;
71
72 let uri: hyper::Uri = hyperlocal::Uri::new(vmm_socket_path, "/api/v1").into();
73 let client = hyper_util::client::legacy::Client::unix();
74 let configuration = Configuration {
75 base_path: uri.to_string(),
76 user_agent: None,
77 client,
78 basic_auth: None,
79 oauth_access_token: None,
80 api_key: None,
81 };
82 DefaultApiClient::new(Arc::new(configuration))
83}