Struct nanocld_client::NanocldClient
source · pub struct NanocldClient {
pub url: String,
pub version: String,
pub unix_socket: Option<String>,
pub ssl: Option<SslConfig>,
}
Fields§
§url: String
§version: String
§unix_socket: Option<String>
§ssl: Option<SslConfig>
Implementations§
source§impl NanocldClient
impl NanocldClient
pub fn connect_with_unix_default() -> Self
pub fn connect_to(opts: &ConnectOpts) -> IoResult<Self>
pub fn set_version(&mut self, version: &str)
pub fn connect_with_unix_version(version: &str) -> Self
pub async fn send_get<Q>(
&self,
url: &str,
query: Option<Q>,
) -> Result<ClientResponse, HttpClientError>where
Q: Serialize,
pub fn convert_query<Q>( query: Option<&Q>, ) -> Result<GenericListQueryNsp, HttpClientError>
pub async fn send_post<Q, B>( &self, url: &str, body: Option<B>, query: Option<Q>, ) -> Result<ClientResponse, HttpClientError>
pub async fn send_post_stream<S, Q, E>( &self, url: &str, stream: S, query: Option<Q>, ) -> Result<ClientResponse, HttpClientError>
pub async fn send_delete<Q>(
&self,
url: &str,
query: Option<Q>,
) -> Result<ClientResponse, HttpClientError>where
Q: Serialize,
pub async fn send_patch<B, Q>( &self, url: &str, body: Option<B>, query: Option<Q>, ) -> Result<ClientResponse, HttpClientError>
pub async fn send_head<Q>(
&self,
url: &str,
query: Option<Q>,
) -> Result<ClientResponse, HttpClientError>where
Q: Serialize,
pub async fn send_put<B, Q>( &self, url: &str, body: Option<B>, query: Option<Q>, ) -> Result<ClientResponse, HttpClientError>
pub async fn res_json<R>(res: ClientResponse) -> Result<R, HttpClientError>where
R: DeserializeOwned + Send + 'static,
pub async fn res_stream<R>(
res: ClientResponse,
) -> Receiver<Result<R, HttpError>>where
R: DeserializeOwned + Send + 'static,
source§impl NanocldClient
impl NanocldClient
sourcepub async fn list_namespace(
&self,
query: Option<&GenericFilter>,
) -> HttpClientResult<Vec<NamespaceSummary>>
pub async fn list_namespace( &self, query: Option<&GenericFilter>, ) -> HttpClientResult<Vec<NamespaceSummary>>
sourcepub async fn create_namespace(&self, name: &str) -> HttpClientResult<Namespace>
pub async fn create_namespace(&self, name: &str) -> HttpClientResult<Namespace>
Create a namespace by it’s name
sourcepub async fn inspect_namespace(
&self,
name: &str,
) -> HttpClientResult<NamespaceInspect>
pub async fn inspect_namespace( &self, name: &str, ) -> HttpClientResult<NamespaceInspect>
sourcepub async fn delete_namespace(&self, name: &str) -> HttpClientResult<()>
pub async fn delete_namespace(&self, name: &str) -> HttpClientResult<()>
source§impl NanocldClient
impl NanocldClient
sourcepub async fn create_cargo(
&self,
item: &CargoSpecPartial,
namespace: Option<&str>,
) -> HttpClientResult<Cargo>
pub async fn create_cargo( &self, item: &CargoSpecPartial, namespace: Option<&str>, ) -> HttpClientResult<Cargo>
Create a new cargo in the system Note that the cargo is not started by default
§Example
use nanocld_client::NanocldClient;
let client = NanocldClient::connect_to("http://localhost:8585", None);
let new_cargo = CargoSpecPartial {
name: String::from("my-cargo"),
container: bollard_next::container::Config {
image: Some(String::from("alpine"))
..Default::default()
}
};
let res = client.create_cargo(new_cargo, None).await;
sourcepub async fn delete_cargo(
&self,
name: &str,
query: Option<&CargoDeleteQuery>,
) -> HttpClientResult<()>
pub async fn delete_cargo( &self, name: &str, query: Option<&CargoDeleteQuery>, ) -> HttpClientResult<()>
sourcepub async fn inspect_cargo(
&self,
name: &str,
namespace: Option<&str>,
) -> HttpClientResult<CargoInspect>
pub async fn inspect_cargo( &self, name: &str, namespace: Option<&str>, ) -> HttpClientResult<CargoInspect>
sourcepub async fn list_cargo(
&self,
query: Option<&GenericFilterNsp>,
) -> HttpClientResult<Vec<CargoSummary>>
pub async fn list_cargo( &self, query: Option<&GenericFilterNsp>, ) -> HttpClientResult<Vec<CargoSummary>>
sourcepub async fn patch_cargo(
&self,
name: &str,
spec: &CargoSpecUpdate,
namespace: Option<&str>,
) -> HttpClientResult<()>
pub async fn patch_cargo( &self, name: &str, spec: &CargoSpecUpdate, namespace: Option<&str>, ) -> HttpClientResult<()>
Patch a cargo by it’s name This will update the cargo’s spec by merging current spec with new spec and creating an history entry
§Example
use nanocld_client::NanocldClient;
let client = NanocldClient::connect_to("http://localhost:8585", None);
let cargo_spec = CargoSpecPatch {
name: "my-cargo-renamed".into(),
};
client.patch_cargo("my-cargo", cargo, None).await.unwrap();
sourcepub async fn put_cargo(
&self,
name: &str,
spec: &CargoSpecPartial,
namespace: Option<&str>,
) -> HttpClientResult<()>
pub async fn put_cargo( &self, name: &str, spec: &CargoSpecPartial, namespace: Option<&str>, ) -> HttpClientResult<()>
Put a cargo by it’s name It will create a new cargo spec and store old one in history
§Example
use nanocld_client::NanocldClient;
let client = NanocldClient::connect_to("http://localhost:8585", None);
let cargo_spec = CargoSpecPartial {
name: "my-cargo-renamed".into(),
};
client.put_cargo("my-cargo", &cargo, None).await.unwrap();
sourcepub async fn list_history_cargo(
&self,
name: &str,
namespace: Option<&str>,
) -> HttpClientResult<Vec<CargoSpec>>
pub async fn list_history_cargo( &self, name: &str, namespace: Option<&str>, ) -> HttpClientResult<Vec<CargoSpec>>
sourcepub async fn revert_cargo(
&self,
name: &str,
id: &str,
namespace: Option<&str>,
) -> HttpClientResult<Cargo>
pub async fn revert_cargo( &self, name: &str, id: &str, namespace: Option<&str>, ) -> HttpClientResult<Cargo>
sourcepub async fn list_cargo_instance(
&self,
name: &str,
namespace: Option<&str>,
) -> HttpClientResult<Vec<ContainerSummary>>
pub async fn list_cargo_instance( &self, name: &str, namespace: Option<&str>, ) -> HttpClientResult<Vec<ContainerSummary>>
source§impl NanocldClient
impl NanocldClient
sourcepub async fn create_exec(
&self,
name: &str,
exec: &CreateExecOptions,
namespace: Option<&str>,
) -> HttpClientResult<CreateExecResults>
pub async fn create_exec( &self, name: &str, exec: &CreateExecOptions, namespace: Option<&str>, ) -> HttpClientResult<CreateExecResults>
Create exec command inside a cargo
§Example
use nanocld_client::NanocldClient;
use nanocld_client::models::cargo_config::CreateExecOptions;
let client = NanocldClient::connect_to("http://localhost:8585", None);
let exec = CreateExecOptions {
cmd: vec!["echo".into(), "hello".into()],
..Default::default()
};
let result = client.create_exec("my-cargo", exec, None).await.unwrap();
println!("{}", result);
sourcepub async fn inspect_exec(
&self,
id: &str,
) -> HttpClientResult<ExecInspectResponse>
pub async fn inspect_exec( &self, id: &str, ) -> HttpClientResult<ExecInspectResponse>
Inspect an exec command inside a cargo instance.
§Example
use nanocld_client::NanocldClient;
use nanocld_client::models::cargo_config::{CreateExecOptions, StartExecOptions};
let client = NanocldClient::connect_to("http://localhost:8585", None);
let exec = CreateExecOptions {
cmd: Some(vec!["echo".into(), "hello".into()]),
..Default::default()
};
let result = client.create_exec("my-cargo", exec, None).await.unwrap();
let mut rx = client
.start_exec(&result.id, StartExecOptions::default())
.await
.unwrap();
while let Some(_out) = rx.next().await {}
client.inspect_exec(&result.id).await.unwrap();
let result = client.inspect_exec("my-cargo", exec, None).await.unwrap();
println!("{}", result);
sourcepub async fn start_exec(
&self,
id: &str,
exec: &StartExecOptions,
) -> HttpClientResult<Receiver<HttpResult<OutputLog>>>
pub async fn start_exec( &self, id: &str, exec: &StartExecOptions, ) -> HttpClientResult<Receiver<HttpResult<OutputLog>>>
Run an command inside a cargo
§Example
use futures::StreamExt;
use nanocld_client::NanocldClient;
use nanocld_client::models::cargo_config::CreateExecOptions;
let client = NanocldClient::connect_to("http://localhost:8585", None);
let exec = CreateExecOptions {
cmd: vec!["echo".into(), "hello".into()],
..Default::default()
};
let result = client.create_exec("my-cargo", exec, None).await.unwrap();
let mut rx = client.start_exec(&result.id, StartExec::default(), None).await.unwrap();
while let Some(output) = rx.next().await {
println!("{}", output);
};
source§impl NanocldClient
impl NanocldClient
sourcepub async fn get_version(&self) -> HttpClientResult<BinaryInfo>
pub async fn get_version(&self) -> HttpClientResult<BinaryInfo>
sourcepub async fn watch_events(
&self,
conditions: Option<Vec<EventCondition>>,
) -> HttpClientResult<Receiver<HttpResult<Event>>>
pub async fn watch_events( &self, conditions: Option<Vec<EventCondition>>, ) -> HttpClientResult<Receiver<HttpResult<Event>>>
Watch daemon events It will emit an event when the daemon state change
§Example
use nanocld_client::NanocldClient;
let client = NanocldClient::connect_to("http://localhost:8585", None);
let mut stream = client.watch_events(None).await?;
while let Some(event) = stream.next().await {
println!("{:?}", event);
}
sourcepub async fn ping(&self) -> HttpClientResult<()>
pub async fn ping(&self) -> HttpClientResult<()>
source§impl NanocldClient
impl NanocldClient
sourcepub async fn list_resource(
&self,
query: Option<&GenericFilter>,
) -> HttpClientResult<Vec<Resource>>
pub async fn list_resource( &self, query: Option<&GenericFilter>, ) -> HttpClientResult<Vec<Resource>>
sourcepub async fn create_resource(
&self,
data: &ResourcePartial,
) -> HttpClientResult<Resource>
pub async fn create_resource( &self, data: &ResourcePartial, ) -> HttpClientResult<Resource>
Create a new resource from a partial resource in the system.
§Example
use nanocld_client::NanocldClient;
use nanocl_stubs::resource::ResourceKind;
let client = NanocldClient::connect_to("http://localhost:8585", None);
let res = client.create_resource(&ResourcePartial {
name: "my-resource".into(),
kind: String::from("Custom")s,
// Your data
data: serde_json::json!({}),
}).await;
sourcepub async fn inspect_resource(&self, key: &str) -> HttpClientResult<Resource>
pub async fn inspect_resource(&self, key: &str) -> HttpClientResult<Resource>
sourcepub async fn put_resource(
&self,
key: &str,
config: &ResourceUpdate,
) -> HttpClientResult<Resource>
pub async fn put_resource( &self, key: &str, config: &ResourceUpdate, ) -> HttpClientResult<Resource>
sourcepub async fn delete_resource(&self, key: &str) -> HttpClientResult<()>
pub async fn delete_resource(&self, key: &str) -> HttpClientResult<()>
sourcepub async fn list_history_resource(
&self,
key: &str,
) -> HttpClientResult<Vec<ResourceSpec>>
pub async fn list_history_resource( &self, key: &str, ) -> HttpClientResult<Vec<ResourceSpec>>
sourcepub async fn revert_resource(
&self,
name: &str,
key: &str,
) -> HttpClientResult<Resource>
pub async fn revert_resource( &self, name: &str, key: &str, ) -> HttpClientResult<Resource>
Revert a resource to a previous version
§Example
use nanocld_client::NanocldClient;
let client = NanocldClient::connect_to("http://localhost:8585", None);
let history = client.list_history_resource("my-resource").await.unwrap().first().unwrap();
let res = client.revert_resource("my-resource", history.key).await;
source§impl NanocldClient
impl NanocldClient
sourcepub async fn create_vm(
&self,
vm: &VmSpecPartial,
namespace: Option<&str>,
) -> HttpClientResult<Vm>
pub async fn create_vm( &self, vm: &VmSpecPartial, namespace: Option<&str>, ) -> HttpClientResult<Vm>
Create a new virtual machine in the system.
sourcepub async fn list_vm(
&self,
query: Option<&GenericFilterNsp>,
) -> HttpClientResult<Vec<VmSummary>>
pub async fn list_vm( &self, query: Option<&GenericFilterNsp>, ) -> HttpClientResult<Vec<VmSummary>>
sourcepub async fn inspect_vm(
&self,
name: &str,
namespace: Option<&str>,
) -> HttpClientResult<VmInspect>
pub async fn inspect_vm( &self, name: &str, namespace: Option<&str>, ) -> HttpClientResult<VmInspect>
sourcepub async fn patch_vm(
&self,
name: &str,
vm: &VmSpecUpdate,
namespace: Option<&str>,
) -> HttpClientResult<()>
pub async fn patch_vm( &self, name: &str, vm: &VmSpecUpdate, namespace: Option<&str>, ) -> HttpClientResult<()>
Patch a vm by it’s name and namespace to update it’s spec
sourcepub async fn attach_vm(
&self,
name: &str,
namespace: Option<&str>,
) -> HttpClientResult<WsConnection<Base>>
pub async fn attach_vm( &self, name: &str, namespace: Option<&str>, ) -> HttpClientResult<WsConnection<Base>>
source§impl NanocldClient
impl NanocldClient
sourcepub async fn import_vm_image<S, E>(
&self,
name: &str,
stream: S,
) -> HttpClientResult<()>
pub async fn import_vm_image<S, E>( &self, name: &str, stream: S, ) -> HttpClientResult<()>
This method will import a vm image from a stream of bytes.
sourcepub async fn list_vm_image(
&self,
query: Option<&GenericFilter>,
) -> HttpClientResult<Vec<VmImage>>
pub async fn list_vm_image( &self, query: Option<&GenericFilter>, ) -> HttpClientResult<Vec<VmImage>>
sourcepub async fn delete_vm_image(&self, name: &str) -> HttpClientResult<()>
pub async fn delete_vm_image(&self, name: &str) -> HttpClientResult<()>
sourcepub async fn clone_vm_image(
&self,
name: &str,
clone_name: &str,
) -> HttpClientResult<Receiver<HttpResult<VmImageCloneStream>>>
pub async fn clone_vm_image( &self, name: &str, clone_name: &str, ) -> HttpClientResult<Receiver<HttpResult<VmImageCloneStream>>>
sourcepub async fn resize_vm_image(
&self,
name: &str,
opts: &VmImageResizePayload,
) -> HttpClientResult<VmImage>
pub async fn resize_vm_image( &self, name: &str, opts: &VmImageResizePayload, ) -> HttpClientResult<VmImage>
source§impl NanocldClient
impl NanocldClient
source§impl NanocldClient
impl NanocldClient
sourcepub async fn list_secret(
&self,
query: Option<&GenericFilter>,
) -> HttpClientResult<Vec<Secret>>
pub async fn list_secret( &self, query: Option<&GenericFilter>, ) -> HttpClientResult<Vec<Secret>>
sourcepub async fn create_secret(
&self,
item: &SecretPartial,
) -> HttpClientResult<Secret>
pub async fn create_secret( &self, item: &SecretPartial, ) -> HttpClientResult<Secret>
Create a new secret
sourcepub async fn patch_secret(
&self,
key: &str,
item: &SecretUpdate,
) -> HttpClientResult<Secret>
pub async fn patch_secret( &self, key: &str, item: &SecretUpdate, ) -> HttpClientResult<Secret>
Patch a secret by it’s key to update it with new data
sourcepub async fn inspect_secret(&self, key: &str) -> HttpClientResult<Secret>
pub async fn inspect_secret(&self, key: &str) -> HttpClientResult<Secret>
sourcepub async fn delete_secret(&self, key: &str) -> HttpClientResult<()>
pub async fn delete_secret(&self, key: &str) -> HttpClientResult<()>
source§impl NanocldClient
impl NanocldClient
sourcepub async fn list_job(
&self,
query: Option<&GenericFilter>,
) -> HttpClientResult<Vec<JobSummary>>
pub async fn list_job( &self, query: Option<&GenericFilter>, ) -> HttpClientResult<Vec<JobSummary>>
sourcepub async fn inspect_job(&self, name: &str) -> HttpClientResult<JobInspect>
pub async fn inspect_job(&self, name: &str) -> HttpClientResult<JobInspect>
sourcepub async fn create_job(&self, job: &JobPartial) -> HttpClientResult<Job>
pub async fn create_job(&self, job: &JobPartial) -> HttpClientResult<Job>
Create a job from a JobPartial
§Example
use nanocld_client::NanocldClient;
use nanocld_client::bollard_next::container::Config;
let client = NanocldClient::connect_to("http://localhost:8585", None);
let res = client.create_job(&JobPartial {
name: "my_job".to_string(),
containers: vec![
Config {
image: Some("alpine:latest".to_string()),
cmd: Some(vec!["echo".to_string(), "Hello world".to_string()]),
}
],
}).await;
sourcepub async fn delete_job(&self, name: &str) -> HttpClientResult<()>
pub async fn delete_job(&self, name: &str) -> HttpClientResult<()>
source§impl NanocldClient
impl NanocldClient
sourcepub async fn list_process(
&self,
query: Option<&GenericFilter>,
) -> HttpClientResult<Vec<Process>>
pub async fn list_process( &self, query: Option<&GenericFilter>, ) -> HttpClientResult<Vec<Process>>
sourcepub async fn logs_process(
&self,
name: &str,
query: Option<&ProcessLogQuery>,
) -> HttpClientResult<Receiver<HttpResult<ProcessOutputLog>>>
pub async fn logs_process( &self, name: &str, query: Option<&ProcessLogQuery>, ) -> HttpClientResult<Receiver<HttpResult<ProcessOutputLog>>>
Get Log of a single process by it’s name or id Cargoes, jobs, can have multiple instances, this endpoint get logs of a single instance
sourcepub async fn logs_processes(
&self,
kind: &str,
name: &str,
query: Option<&ProcessLogQuery>,
) -> HttpClientResult<Receiver<HttpResult<ProcessOutputLog>>>
pub async fn logs_processes( &self, kind: &str, name: &str, query: Option<&ProcessLogQuery>, ) -> HttpClientResult<Receiver<HttpResult<ProcessOutputLog>>>
Get logs of processes for a specific object Cargoes, jobs, can have multiple instances, this endpoint get logs all instances
sourcepub async fn start_process(
&self,
kind: &str,
name: &str,
namespace: Option<&str>,
) -> HttpClientResult<()>
pub async fn start_process( &self, kind: &str, name: &str, namespace: Option<&str>, ) -> HttpClientResult<()>
sourcepub async fn restart_process(
&self,
kind: &str,
name: &str,
namespace: Option<&str>,
) -> HttpClientResult<()>
pub async fn restart_process( &self, kind: &str, name: &str, namespace: Option<&str>, ) -> HttpClientResult<()>
sourcepub async fn stop_process(
&self,
kind: &str,
name: &str,
namespace: Option<&str>,
) -> HttpClientResult<()>
pub async fn stop_process( &self, kind: &str, name: &str, namespace: Option<&str>, ) -> HttpClientResult<()>
sourcepub async fn kill_process(
&self,
kind: &str,
name: &str,
query: Option<&CargoKillOptions>,
namespace: Option<&str>,
) -> HttpClientResult<()>
pub async fn kill_process( &self, kind: &str, name: &str, query: Option<&CargoKillOptions>, namespace: Option<&str>, ) -> HttpClientResult<()>
sourcepub async fn wait_process(
&self,
kind: &str,
name: &str,
query: Option<&ProcessWaitQuery>,
) -> HttpClientResult<Receiver<HttpResult<ProcessWaitResponse>>>
pub async fn wait_process( &self, kind: &str, name: &str, query: Option<&ProcessWaitQuery>, ) -> HttpClientResult<Receiver<HttpResult<ProcessWaitResponse>>>
sourcepub async fn stats_processes(
&self,
kind: &str,
name: &str,
query: Option<&ProcessStatsQuery>,
) -> HttpClientResult<Receiver<HttpResult<ProcessStats>>>
pub async fn stats_processes( &self, kind: &str, name: &str, query: Option<&ProcessStatsQuery>, ) -> HttpClientResult<Receiver<HttpResult<ProcessStats>>>
source§impl NanocldClient
impl NanocldClient
sourcepub async fn list_metric(
&self,
query: Option<&GenericFilter>,
) -> HttpClientResult<Vec<Metric>>
pub async fn list_metric( &self, query: Option<&GenericFilter>, ) -> HttpClientResult<Vec<Metric>>
sourcepub async fn create_metric(
&self,
metric: &MetricPartial,
) -> HttpClientResult<Metric>
pub async fn create_metric( &self, metric: &MetricPartial, ) -> HttpClientResult<Metric>
Create a new metric in the system
§Example
use nanocld_client::NanocldClient;
use nanocld_client::stubs::metric::MetricPartial;
let client = NanocldClient::connect_to("http://localhost:8585", None);
let res = client.list_metric(&MetricPartial {
kind: "my-source.io/type".to_owned(),
data: serde_json::json!({
"name": "my-metric",
"description": "My metric",
}),
}).await;
sourcepub async fn inspect_metric(&self, key: &str) -> HttpClientResult<Metric>
pub async fn inspect_metric(&self, key: &str) -> HttpClientResult<Metric>
source§impl NanocldClient
impl NanocldClient
sourcepub async fn list_resource_kind(
&self,
query: Option<&GenericFilter>,
) -> HttpClientResult<Vec<ResourceKind>>
pub async fn list_resource_kind( &self, query: Option<&GenericFilter>, ) -> HttpClientResult<Vec<ResourceKind>>
sourcepub async fn create_resource_kind(
&self,
item: &ResourceKindPartial,
) -> HttpClientResult<ResourceKind>
pub async fn create_resource_kind( &self, item: &ResourceKindPartial, ) -> HttpClientResult<ResourceKind>
Create a new secret
sourcepub async fn inspect_resource_kind(
&self,
key: &str,
) -> HttpClientResult<ResourceKindInspect>
pub async fn inspect_resource_kind( &self, key: &str, ) -> HttpClientResult<ResourceKindInspect>
sourcepub async fn inspect_resource_kind_version(
&self,
key: &str,
version: &str,
) -> HttpClientResult<ResourceKindVersion>
pub async fn inspect_resource_kind_version( &self, key: &str, version: &str, ) -> HttpClientResult<ResourceKindVersion>
sourcepub async fn delete_resource_kind(&self, key: &str) -> HttpClientResult<()>
pub async fn delete_resource_kind(&self, key: &str) -> HttpClientResult<()>
Trait Implementations§
source§impl Clone for NanocldClient
impl Clone for NanocldClient
source§fn clone(&self) -> NanocldClient
fn clone(&self) -> NanocldClient
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more