pub struct Client<D = Docker> { /* private fields */ }Expand description
The main entry point for interacting with local Atlas deployments.
Client provides a high-level interface for managing MongoDB Atlas local deployments
through Docker. It serves as the primary abstraction layer between your application
and the underlying Docker containers running Atlas services.
§Examples
See the module-level documentation for a complete example of creating a new client instance.
Implementations§
Source§impl<D: DockerPullImage + DockerCreateContainer + DockerStartContainer + DockerInspectContainer + Send + Sync + 'static> Client<D>
impl<D: DockerPullImage + DockerCreateContainer + DockerStartContainer + DockerInspectContainer + Send + Sync + 'static> Client<D>
Sourcepub fn create_deployment(
&self,
deployment_options: CreateDeploymentOptions,
) -> CreateDeploymentProgress ⓘ
pub fn create_deployment( &self, deployment_options: CreateDeploymentOptions, ) -> CreateDeploymentProgress ⓘ
Creates a local Atlas deployment.
Source§impl<D: DockerStopContainer + DockerRemoveContainer + DockerInspectContainer> Client<D>
impl<D: DockerStopContainer + DockerRemoveContainer + DockerInspectContainer> Client<D>
Sourcepub async fn delete_deployment(
&self,
name: &str,
) -> Result<(), DeleteDeploymentError>
pub async fn delete_deployment( &self, name: &str, ) -> Result<(), DeleteDeploymentError>
Deletes a local Atlas deployment.
Source§impl<D: DockerInspectContainer + RunCommandInContainer> Client<D>
impl<D: DockerInspectContainer + RunCommandInContainer> Client<D>
pub async fn get_connection_string( &self, container_id_or_name: String, ) -> Result<String, GetConnectionStringError>
Source§impl<D: DockerInspectContainer> Client<D>
impl<D: DockerInspectContainer> Client<D>
Sourcepub async fn get_deployment(
&self,
container_id_or_name: &str,
) -> Result<Deployment, GetDeploymentError>
pub async fn get_deployment( &self, container_id_or_name: &str, ) -> Result<Deployment, GetDeploymentError>
Source§impl<D: DockerInspectContainer + RunCommandInContainer> Client<D>
impl<D: DockerInspectContainer + RunCommandInContainer> Client<D>
Sourcepub async fn get_deployment_id(
&self,
cluster_id_or_name: &str,
) -> Result<String, GetDeploymentIdError>
pub async fn get_deployment_id( &self, cluster_id_or_name: &str, ) -> Result<String, GetDeploymentIdError>
Gets the Atlas deployment ID for a local Atlas deployment.
Source§impl<D: DockerLogContainer> Client<D>
impl<D: DockerLogContainer> Client<D>
Sourcepub async fn get_logs(
&self,
container_id_or_name: &str,
options: Option<LogsOptions>,
) -> Result<Vec<LogOutput>, GetLogsError>
pub async fn get_logs( &self, container_id_or_name: &str, options: Option<LogsOptions>, ) -> Result<Vec<LogOutput>, GetLogsError>
Gets the logs from a container.
§Arguments
container_id_or_name- The ID or name of the container to get logs from.options- Optional logging options (e.g., tail, timestamps, etc.)
§Returns
A Result containing a vector of log entries from the container, or an error if the logs could not be retrieved.
§Examples
See the complete working example:
cargo run --example get_logsExample code:
use anyhow::{Context, Result};
use atlas_local::{
Client,
models::{CreateDeploymentOptions, LogsOptions, Tail},
};
use bollard::Docker;
#[tokio::main]
async fn main() -> Result<()> {
let docker = Docker::connect_with_defaults().context("connecting to docker")?;
let client = Client::new(docker.clone());
let deployment_options = CreateDeploymentOptions::default();
let deployment = client
.create_deployment(deployment_options)
.await
.context("creating deployment")?;
// Configure log options
let log_options = LogsOptions::builder()
.stdout(true) // Include stdout
.stderr(true) // Include stderr
.tail(Tail::Number(100)) // Get last 100 lines
.timestamps(true) // Include timestamps
.build();
// Get logs from the deployment
let logs = client
.get_logs(&deployment.container_id, Some(log_options))
.await
.context("getting logs")?;
println!("Container logs:");
for log in logs {
// Use print! instead of println! because logs contain new line characters
print!("{}", log);
}
Ok(())
}Source§impl<D: DockerListContainers + DockerInspectContainer> Client<D>
impl<D: DockerListContainers + DockerInspectContainer> Client<D>
Sourcepub async fn list_deployments(
&self,
) -> Result<Vec<Deployment>, GetDeploymentError>
pub async fn list_deployments( &self, ) -> Result<Vec<Deployment>, GetDeploymentError>
Lists all local Atlas deployments.
Source§impl<D: DockerPauseContainer + DockerInspectContainer> Client<D>
impl<D: DockerPauseContainer + DockerInspectContainer> Client<D>
Sourcepub async fn pause_deployment(
&self,
name: &str,
) -> Result<(), PauseDeploymentError>
pub async fn pause_deployment( &self, name: &str, ) -> Result<(), PauseDeploymentError>
Pauses a local Atlas deployment.
Source§impl<D: DockerPullImage> Client<D>
impl<D: DockerPullImage> Client<D>
Sourcepub async fn pull_image(
&self,
image: &str,
tag: &str,
) -> Result<(), PullImageError>
pub async fn pull_image( &self, image: &str, tag: &str, ) -> Result<(), PullImageError>
Source§impl<D: DockerStartContainer + DockerInspectContainer> Client<D>
impl<D: DockerStartContainer + DockerInspectContainer> Client<D>
Sourcepub async fn start_deployment(
&self,
name: &str,
) -> Result<(), StartDeploymentError>
pub async fn start_deployment( &self, name: &str, ) -> Result<(), StartDeploymentError>
Starts a local Atlas deployment.
Source§impl<D: DockerStopContainer + DockerInspectContainer> Client<D>
impl<D: DockerStopContainer + DockerInspectContainer> Client<D>
Sourcepub async fn stop_deployment(
&self,
name: &str,
) -> Result<(), StopDeploymentError>
pub async fn stop_deployment( &self, name: &str, ) -> Result<(), StopDeploymentError>
Stops a local Atlas deployment.
Source§impl<D: DockerUnpauseContainer + DockerInspectContainer> Client<D>
impl<D: DockerUnpauseContainer + DockerInspectContainer> Client<D>
Sourcepub async fn unpause_deployment(
&self,
name: &str,
) -> Result<(), UnpauseDeploymentError>
pub async fn unpause_deployment( &self, name: &str, ) -> Result<(), UnpauseDeploymentError>
Unpauses a local Atlas deployment.
Source§impl<D: DockerInspectContainer> Client<D>
impl<D: DockerInspectContainer> Client<D>
Sourcepub async fn wait_for_healthy_deployment(
&self,
deployment_name: &str,
options: WatchOptions,
) -> Result<(), WatchDeploymentError>
pub async fn wait_for_healthy_deployment( &self, deployment_name: &str, options: WatchOptions, ) -> Result<(), WatchDeploymentError>
Waits for a deployment to become healthy.
This method polls the container’s health status until it becomes healthy, or until the timeout specified in the options is reached.
§Arguments
cluster_name- The name or ID of the container to watchoptions- Configuration options including timeout duration
§Returns
Returns Ok(()) when the container becomes healthy, or an error if:
- The container inspection fails
- The container becomes unhealthy
- The timeout is reached
§Examples
use atlas_local::models::WatchOptions;
use std::time::Duration;
let options = WatchOptions::builder()
.timeout_duration(Duration::from_secs(300))
.build();
client.wait_for_healthy_deployment("my-deployment", options).await?;Source§impl<D> Client<D>
impl<D> Client<D>
Sourcepub fn new(docker: D) -> Client<D>
pub fn new(docker: D) -> Client<D>
Creates a new Atlas Local client with the default MongoDB adapter.
§Arguments
docker- A connected Docker client instance from thebollardcrate
§Returns
A new Client instance ready to manage Atlas Local deployments.
§Examples
See the module-level documentation for usage examples.