pub struct LxdClient { /* private fields */ }Expand description
A specialized LXD client for instance management.
This client provides a consistent interface for LXD operations:
- List instances (containers and virtual machines) and their information
- Retrieve instance IP addresses
- Execute LXD commands with proper error handling
Uses CommandExecutor as a collaborator for actual command execution.
Implementations§
Source§impl LxdClient
impl LxdClient
Sourcepub fn get_instance_ip(
&self,
instance_name: &InstanceName,
) -> Result<Option<IpAddr>>
pub fn get_instance_ip( &self, instance_name: &InstanceName, ) -> Result<Option<IpAddr>>
Get the IPv4 address of a specific instance
§Arguments
instance_name- Name of the instance to get the IP address for
§Returns
Ok(Some(IpAddr))- The IPv4 address if foundOk(None)- Instance not found or no IPv4 address availableErr(anyhow::Error)- Error describing what went wrong
§Errors
This function will return an error if:
- LXD command execution fails
- JSON parsing fails
Sourcepub fn wait_for_instance_ip(
&self,
instance_name: &InstanceName,
timeout_seconds: u64,
poll_interval_seconds: u64,
) -> Result<IpAddr>
pub fn wait_for_instance_ip( &self, instance_name: &InstanceName, timeout_seconds: u64, poll_interval_seconds: u64, ) -> Result<IpAddr>
Wait for an instance to get an IP address (useful for VMs that take time to boot)
§Arguments
instance_name- Name of the instance to wait fortimeout_seconds- Maximum time to wait in secondspoll_interval_seconds- How often to check in seconds
§Returns
Ok(IpAddr)- The IP address when foundErr(anyhow::Error)- Timeout or other error
§Errors
This function will return an error if:
- Timeout is reached without getting an IP
- LXD command execution fails
- JSON parsing fails
Sourcepub fn get_instance_by_name(
&self,
instance_name: &InstanceName,
) -> Result<Option<InstanceInfo>>
pub fn get_instance_by_name( &self, instance_name: &InstanceName, ) -> Result<Option<InstanceInfo>>
Get a specific instance by name
§Arguments
instance_name- Name of the instance to retrieve
§Returns
Ok(Some(InstanceInfo))- Instance information if foundOk(None)- Instance not foundErr(anyhow::Error)- Error describing what went wrong
§Errors
This function will return an error if:
- LXD command execution fails
- JSON parsing fails
Sourcepub fn delete_instance(
&self,
instance_name: &InstanceName,
force: bool,
) -> Result<()>
pub fn delete_instance( &self, instance_name: &InstanceName, force: bool, ) -> Result<()>
Delete an LXD instance
§Arguments
instance_name- Name of the instance to deleteforce- Whether to force deletion (stop running instances)
§Returns
Ok(())- Instance deleted successfully or didn’t existErr(anyhow::Error)- Error describing what went wrong
§Errors
This function will return an error if:
- The LXD command fails with an unexpected error
- LXD is not installed or accessible
Sourcepub fn delete_profile(&self, profile_name: &str) -> Result<()>
pub fn delete_profile(&self, profile_name: &str) -> Result<()>
Delete an LXD profile
§Arguments
profile_name- Name of the profile to delete
§Returns
Ok(())- Profile deleted successfully or didn’t existErr(anyhow::Error)- Error describing what went wrong
§Errors
This function will return an error if:
- The LXD command fails with an unexpected error
- LXD is not installed or accessible
- Profile is in use by existing instances
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LxdClient
impl RefUnwindSafe for LxdClient
impl Send for LxdClient
impl Sync for LxdClient
impl Unpin for LxdClient
impl UnsafeUnpin for LxdClient
impl UnwindSafe for LxdClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request