### Run Examples Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/README.md Commands to run different examples provided by the libvirt Rust bindings. Some examples may require specific features or arguments. ```bash # cargo run --example hello ``` ```bash # cargo run --example migrate -- qemu:///system tcp+qemu://192.168.0.1/system myguest ``` ```bash # cargo run -F qemu --example guest_agent -- qemu:///system myguest ``` -------------------------------- ### Get Autostart Status Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Checks whether the domain is configured to automatically start when the host system boots. Returns a boolean. ```rust pub fn autostart(&self) -> Result ``` -------------------------------- ### StoragePool::autostart Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/storage.md Gets the autostart setting for the storage pool. ```APIDOC ## StoragePool::autostart ### Description Gets pool autostart setting. ### Method GET ### Endpoint `/storage_pool/{pool_name}/autostart` (Conceptual) ### Parameters None ### Response #### Success Response (200) - **autostart** (boolean) - True if autostart is enabled, false otherwise. ### Response Example ```json { "autostart": true } ``` ``` -------------------------------- ### Create Network Interface Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/network-interface-nodedev.md Starts an inactive network interface. ```rust pub fn create(&self, flags: u32) -> Result<(), Error> ``` -------------------------------- ### StoragePool::create Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/storage.md Starts (activates) an inactive storage pool. ```APIDOC ## StoragePool::create ### Description Starts (activates) an inactive storage pool. ### Method POST ### Endpoint `/storage_pool/{pool_name}/start` (Conceptual) ### Parameters #### Query Parameters - **flags** (virStoragePoolCreateFlags) - Optional - Flags to control pool creation. ### Response #### Success Response (204) No Content. ### Response Example ```json (No content) ``` ``` -------------------------------- ### boot Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Starts a defined domain with specified flags. This method allows for more control over the domain startup process. ```APIDOC ## boot ### Description Starts a defined domain with flags. ### Method Rust Method ### Parameters #### Path Parameters - **flags** (sys::virDomainCreateFlags) - Required - Flags to control domain creation. ### Signature `pub fn boot(&self, flags: sys::virDomainCreateFlags) -> Result<(), Error>` ``` -------------------------------- ### create Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Starts a defined but inactive domain. This method transitions a domain from a defined state to a running state. ```APIDOC ## create ### Description Starts a defined (inactive) domain. ### Method Rust Method ### Signature `pub fn create(&self) -> Result<(), Error>` ``` -------------------------------- ### Create (Activate) Storage Pool Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/storage.md Starts or activates an inactive storage pool. ```rust pub fn create(&self, flags: sys::virStoragePoolCreateFlags) -> Result<(), Error> ``` -------------------------------- ### Create and Use a Storage Pool Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/storage.md Demonstrates the workflow for creating, building, starting, and listing volumes within a storage pool. Requires an active libvirt connection. ```rust use virt::connect::Connect; let conn = Connect::open(Some("qemu:///system"))?; // Define pool let pool_xml = r###" mypool /mnt/storage "###; let pool = conn.define_storage_pool_xml(pool_xml, 0)?; // Build and start pool pool.build(0)?; pool.create(0)?; // List volumes let volumes = pool.list_volumes()?; for vol_name in volumes { println!("Volume: {}", vol_name); } // Look up a specific volume if let Ok(vol) = pool.lookup_storage_vol_by_name("disk.img") { let info = vol.info()?; println!("Capacity: {} bytes", info.capacity); println!("Allocation: {} bytes", info.allocation); } ``` -------------------------------- ### Boot Domain with Flags Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Starts a defined domain using specific flags to control the boot process. This offers more granular control over domain startup. ```rust pub fn boot(&self, flags: sys::virDomainCreateFlags) -> Result<(), Error> ``` -------------------------------- ### Connect::version Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Gets the local libvirt library version as a single integer. ```APIDOC ## Connect::version ### Description Gets the local libvirt library version as a single integer. ### Method `pub fn version() -> Result` ### Returns `Result` - Version number as a single integer (e.g., 5002000 for 5.2.0) ### Example ```rust let ver = Connect::version().unwrap(); println!("Libvirt version: {}", ver); ``` ``` -------------------------------- ### get_autostart Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Checks if the domain's autostart behavior is enabled. This method returns a boolean indicating if the domain will start automatically on host boot. ```APIDOC ## get_autostart ### Description Checks if domain autostart is enabled. ### Method Rust Method ### Signature `pub fn autostart(&self) -> Result` ``` -------------------------------- ### Set Autostart Behavior Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Configures whether the domain should automatically start when the host system boots. Accepts a boolean value to enable or disable autostart. ```rust pub fn set_autostart(&self, autostart: bool) -> Result<(), Error> ``` -------------------------------- ### Create Domain Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Starts a defined but inactive domain. This operation transitions the domain from a defined state to a running state. ```rust pub fn create(&self) -> Result<(), Error> ``` -------------------------------- ### Method Documentation Details Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/COMPLETION_SUMMARY.txt Each method in the libvirt-rust API is documented with its full signature, parameter details, return type, error conditions, and usage examples. ```APIDOC ## Method Documentation For each documented method, the following information is provided: ### Method Signature - Full signature including all parameter types. ### Parameters - A table detailing each parameter: - **name**: Parameter name. - **type**: Parameter type. - **default**: Default value, if applicable. - **description**: Explanation of the parameter's purpose. ### Return Type - The type of the value returned by the method. - Description of the return value's meaning. ### Error Conditions - Specific error conditions under which the method might fail (when applicable). ### Usage Example - A minimal code example demonstrating how to use the method. ### Source Reference - The source file path and line number where the method is defined. ``` -------------------------------- ### Get Interface XML Description Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/network-interface-nodedev.md Retrieves the XML configuration of the network interface. ```rust pub fn xml_desc(&self, flags: u32) -> Result ``` -------------------------------- ### Get Network XML Description Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/network-interface-nodedev.md Retrieves the XML configuration description for the virtual network. ```rust pub fn xml_desc(&self, flags: sys::virNetworkXMLFlags) -> Result ``` -------------------------------- ### Define Persistent Domain from XML Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Defines a domain from an XML configuration, making it persistent but not starting it. Use this to set up domains before they are launched. ```rust pub fn define_domain_xml(&self, xml: &str) -> Result ``` -------------------------------- ### Get host capabilities Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Retrieves an XML document describing the host's capabilities, including supported hypervisors, architectures, and features. ```rust pub fn capabilities(&self) -> Result ``` -------------------------------- ### Get Storage Pool XML Description Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/storage.md Retrieves the XML configuration of the storage pool. ```rust pub fn xml_desc(&self, flags: sys::virStorageXMLFlags) -> Result ``` -------------------------------- ### Get Hypervisor Version Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Returns the version number of the hypervisor. This is useful for compatibility checks or informational purposes. ```rust pub fn hyp_version(&self) -> Result ``` -------------------------------- ### Define and Manage Storage Pool Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/README.md Defines, builds, and starts a directory-based storage pool, then lists and displays information about volumes within it. ```rust // Define and start a storage pool let pool_xml = r###" mypool /var/lib/libvirt/images "###; let pool = conn.define_storage_pool_xml(pool_xml, 0)?; pool.build(0)?; // Initialize pool.create(0)?; // Start // List volumes in pool let volumes = pool.list_volumes()?; for vol_name in volumes { println!("Volume: {}", vol_name); let vol = pool.lookup_storage_vol_by_name(&vol_name)?; let info = vol.info()?; println!(" Capacity: {} bytes", info.capacity); } ``` -------------------------------- ### Run Local Tests with Rustfmt Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/README.md Ensures code is formatted correctly using rustfmt before submitting patches. Requires rustfmt to be installed. ```bash cargo fmt -v -- --check ``` -------------------------------- ### Type Documentation Details Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/COMPLETION_SUMMARY.txt All types, including enums and structs, are fully documented with their definitions, field details, and usage examples. ```APIDOC ## Type Documentation For each documented type (structs and enums), the following information is provided: ### Structure Definition - The complete structure or enum definition in Rust code. ### Fields - A table detailing each field (for structs): - **name**: Field name. - **type**: Field type. - **required**: Indicates if the field is required. - **description**: Explanation of the field's purpose. ### Cross-references - Links to methods that utilize this type. ### Usage Examples - Examples demonstrating how the type is used in practice. ``` -------------------------------- ### Define and Create a Network from XML Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/network-interface-nodedev.md Defines an inactive network from an XML string and then starts it. Ensure the XML is valid and includes necessary network configurations like name, bridge, and IP addressing with DHCP. ```rust let net_xml = r###"\n mynet\n \n \n \n \n \n \n \n"###; let net = conn.define_network_xml(net_xml)?; net.create()?; // Start the network ``` -------------------------------- ### Get Connection Information Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/README.md Queries and prints the hypervisor type and libvirt library version from the active connection. Requires an established connection object. ```rust println!("Hypervisor: {}", conn.driver_type()?); println!("Version: {}", conn.lib_version()?); ``` -------------------------------- ### Create and Manage Domain Snapshots Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/secrets-snapshots-advanced.md Demonstrates creating a new domain snapshot, retrieving the current snapshot, and reverting to it. Ensure a domain named 'myvm' exists and the connection to libvirt is established. ```rust use virt::connect::Connect; let conn = Connect::open(Some("qemu:///system"))?; let domain = conn.lookup_domain_by_name("myvm")?; // Create snapshot let snap_xml = r###" pre-update-1 Before system update "###; let snap = domain.snapshot_create_xml(snap_xml, 0)?; println!("Created snapshot: {}", snap.name()?); // List snapshots let current = domain.snapshot_current(0)?; println!("Current: {}", current.name()?); // Revert to snapshot if needed current.revert(0)?; ``` -------------------------------- ### Get Maximum Memory Allocation Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Retrieves the maximum memory that can be allocated to a domain in KBytes. No setup is required beyond having a domain object. ```rust pub fn max_memory(&self) -> Result ``` -------------------------------- ### Define and Create Persistent Domain Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/README.md Defines a persistent domain from an XML configuration, which will survive host reboots. The `create()` method starts the domain if it's not set to auto-start. ```rust let domain = conn.define_domain_xml(xml)?; domain.create()?; ``` -------------------------------- ### Get Block Device I/O Tuning Parameters Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Fetches the I/O tuning parameters for a specified block device. Returns a vector of (parameter_name, value) tuples. ```rust pub fn get_block_io_tune(&self, disk: &str, flags: u32) -> Result, Error> ``` -------------------------------- ### Get CPU Statistics Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Fetches CPU statistics for a specified range of virtual CPUs (vCPUs). Requires specifying the starting vCPU and the number of vCPUs to query. ```rust pub fn cpu_stats(&self, start_cpu: i32, ncpus: i32, flags: u32) -> Result, Error> ``` -------------------------------- ### Connect and List Domains Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/README.md Opens a connection to the QEMU system hypervisor and lists running domains, displaying their state, memory, and CPU count. ```rust use virt::connect::Connect; // Open connection to hypervisor let conn = Connect::open(Some("qemu:///system"))?; // List running domains let domain_ids = conn.list_domains()?; for id in domain_ids { let domain = conn.lookup_domain_by_id(id)?; println!("Domain: {}", domain.name()?); let info = domain.info()?; println!(" State: {:?}", info.state); println!(" Memory: {} KiB", info.memory); println!(" CPUs: {}", info.nr_virt_cpu); } ``` -------------------------------- ### Get Domain Info Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Retrieves a structure containing detailed information about the domain's current state and configuration. ```rust pub fn info(&self) -> Result ``` -------------------------------- ### Get Free Memory per NUMA Node Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Retrieves the free memory for individual NUMA nodes. Specify the starting cell and the maximum number of cells to query. ```rust pub fn cells_free_memory(&self, start_cell: i32, max_cells: i32) -> Result, Error> ``` -------------------------------- ### Get Domain Capabilities Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Retrieves an XML description of domain capabilities for the hypervisor. Optional parameters allow filtering by emulator binary, architecture, machine type, and virtualization type. ```rust pub fn domain_capabilities( &self, emulatorbin: Option<&str>, arch: Option<&str>, machine: Option<&str>, virttype: Option<&str>, flags: u32, ) -> Result ``` -------------------------------- ### Get host system information Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Retrieves host system information, including SMBIOS and sysinfo data, in XML format. Requires specifying query flags. ```rust pub fn sys_info(&self, flags: u32) -> Result ``` -------------------------------- ### Get Network Interface Parameters Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Fetches parameters for a network interface associated with the domain. The `device` parameter specifies the interface name. ```rust pub fn get_interface_parameters( &self, device: &str, flags: u32, ) -> Result, Error> ``` -------------------------------- ### Getting the Last Error Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/errors.md Retrieves the most recent error that occurred. This is crucial when interacting directly with virt-sys functions to get the actual error from libvirt. ```rust let err = Error::last_error(); ``` -------------------------------- ### Get Domain Information Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/README.md Retrieves and displays the state and memory usage of a virtual machine. Requires a valid domain object. ```rust let info = domain.info?; println!("State: {:?}", info.state); println!("Memory: {} KiB", info.memory); ``` -------------------------------- ### Get All Domain Statistics Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Fetches statistics for all active domains. Use the `stats` parameter to specify which statistics to collect and `flags` for additional options. ```rust pub fn all_domain_stats( &self, stats: u32, flags: u32, ) -> Result, Error> ``` -------------------------------- ### Get NodeDevice Parent Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/network-interface-nodedev.md Retrieves the name of the parent device, if any. ```rust pub fn parent(&self) -> Result, Error> ``` -------------------------------- ### Create and Use a Network Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/network-interface-nodedev.md Demonstrates the workflow for defining, creating, and verifying a virtual network using libvirt-rust. Includes XML definition for the network. ```rust use virt::connect::Connect; let conn = Connect::open(Some("qemu:///system"))?; // Define network let net_xml = r###" mynet "###; let net = conn.define_network_xml(net_xml)?; // Start network net.create()?; // Verify println!("Network: {}", net.name()?); println!("Bridge: {}", net.bridge_name()?); println!("Active: {}", net.is_active()?); ``` -------------------------------- ### Get Domain State and Reason Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Retrieves the current state of the domain (e.g., running, paused, shut off) and the reason for that state. This is crucial for monitoring domain status. ```rust pub fn state(&self) -> Result<(DomainStateEnum, DomainStateReasonEnum), Error> ``` -------------------------------- ### Domain (Virtual Machine) Management API Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/INDEX.md Encompasses methods for managing the lifecycle and state of virtual machines (domains). This includes operations for creating, starting, stopping, suspending, resuming, rebooting, destroying, and undefining domains, as well as querying their status, memory, CPU, and block device information. ```APIDOC ## Domain (Virtual Machine) Management ### Description Methods for managing the lifecycle and state of virtual machines (domains). This includes operations for creating, starting, stopping, suspending, resuming, rebooting, destroying, and undefining domains, as well as querying their status, memory, CPU, and block device information. ### Lifecycle Methods - `create()`: Create and start a domain. - `boot()`: Boot a domain. - `suspend()`: Suspend a running domain. - `resume()`: Resume a suspended domain. - `reboot()`: Reboot a domain. - `shutdown()`: Gracefully shut down a domain. - `destroy()`: Forcefully destroy a domain. - `undefine()`: Undefine (remove) a domain configuration. ### State Query Methods - `state()`: Get the current state of the domain. - `info()`: Get detailed information about the domain. - `is_active()`: Check if the domain is active. - `is_persistent()`: Check if the domain is persistent. ### Memory Management Methods - `max_memory()`: Get the maximum memory the domain can use. - `set_max_memory()`: Set the maximum memory for the domain. - `memory()`: Get the current memory usage of the domain. - `set_memory()`: Set the current memory for the domain. - `memory_parameters()`: Get memory parameters. - `memory_stats()`: Get memory statistics. ### CPU Management Methods - `cpu_stats()`: Get CPU statistics for the domain. - `pin_vcpu()`: Pin a virtual CPU to a specific host CPU. - `get_vcpu_pin_info()`: Get the pinning information for virtual CPUs. - `max_vcpus`: Property for maximum virtual CPUs. ### Block Device Methods - `get_block_info()`: Get information about a block device. - `get_block_stats()`: Get statistics for a block device. - `get_block_io_tune()`: Get I/O tuning parameters for a block device. - `set_block_io_tune()`: Set I/O tuning parameters for a block device. ### Networking Methods - `get_interface_parameters()`: Get network interface parameters. - `get_interface_stats()`: Get network interface statistics. ### Snapshot Methods - `snapshot_create_xml()`: Create a snapshot from an XML description. - `snapshot_current()`: Get the current snapshot. - `snapshot_lookup_by_name()`: Look up a snapshot by name. - `has_current_snapshot()`: Check if a current snapshot exists. ### Migration Methods - `migrate()`: Migrate the domain to another host. - `migrate_to_uri()`: Migrate the domain to a specified URI. - `migrate_parameters()`: Get migration parameters. ### Configuration Methods - `xml_desc()`: Get the XML description of the domain configuration. - `update_device_flags()`: Update device flags. - `set_metadata()`: Set metadata for the domain. - `get_metadata()`: Get metadata for the domain. ### Advanced Methods - `save()`: Save the domain state. - `managed_save()`: Perform a managed save of the domain state. - `send_key()`: Send a key event to the domain. - `send_process_signal()`: Send a process signal to the domain. ### Enums - `DomainState`: Represents the state of a domain (e.g., running, paused, shut off). - `DomainRunningReason`: Reason for a domain running state. - `DomainPausedReason`: Reason for a domain being paused. - `DomainShutoffReason`: Reason for a domain being shut off. ### Structs - `DomainInfo`: Structure containing domain information. - `BlockStats`: Structure for block device statistics. - `BlockInfo`: Structure for block device information. - `CpuStats`: Structure for CPU statistics. - `MemoryParameters`: Structure for memory parameters. - `NUMAParameters`: Structure for NUMA parameters. ``` -------------------------------- ### Get NodeDevice Capability Count Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/network-interface-nodedev.md Returns the number of capabilities for the host device. ```rust pub fn num_of_caps(&self) -> Result ``` -------------------------------- ### StoragePool::build Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/storage.md Initializes pool data, such as creating a filesystem. ```APIDOC ## StoragePool::build ### Description Initializes pool data (creates filesystem, etc.). ### Method POST ### Endpoint `/storage_pool/{pool_name}/build` (Conceptual) ### Parameters #### Query Parameters - **flags** (u32) - Optional - Flags to control pool building. ### Response #### Success Response (204) No Content. ### Response Example ```json (No content) ``` ``` -------------------------------- ### Get Block Device Information Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Retrieves detailed information about a specific block device associated with the domain. The `disk` parameter specifies the device name. ```rust pub fn get_block_info(&self, disk: &str, flags: u32) -> Result ``` -------------------------------- ### List and Query Node Devices Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/network-interface-nodedev.md Shows how to list all node devices and iterate through their capabilities. Assumes an active connection and previously defined devices. ```rust // Find all PCI devices let devices = conn.list_all_node_devices(0)?; for dev in devices { println!("Device: {}", dev.name()?); let caps = dev.list_caps()?; for cap in caps { println!(" Capability: {}", cap); } } ``` -------------------------------- ### Get Interface MAC Address Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/network-interface-nodedev.md Retrieves the MAC address of the network interface. ```rust pub fn mac(&self) -> Result ``` -------------------------------- ### Connect::open Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Opens a connection to the hypervisor. It can use a specified URI or default to environment variables or auto-detection. ```APIDOC ## Connect::open ### Description Opens a connection to the hypervisor. It can use a specified URI or default to environment variables or auto-detection. ### Method `pub fn open(uri: Option<&str>) -> Result` ### Parameters #### Path Parameters - **uri** (`Option<&str>`) - Optional - Connection URI. If `None`, uses `LIBVIRT_DEFAULT_URI` environment variable or auto-detects a suitable driver. Examples: `"qemu:///system"`, `"test:///default"` ### Returns `Result` - A connection handle to the hypervisor ### Errors Returns `Error` if connection fails (invalid URI, hypervisor unavailable, connection refused, etc.) ### Example ```rust use virt::connect::Connect; let conn = match Connect::open(Some("qemu:///system")) { Ok(c) => c, Err(e) => panic!("Unable to connect: {e}"), }; ``` ``` -------------------------------- ### Get Connection Object Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/network-interface-nodedev.md Retrieves the connection object associated with the virtual network. ```rust pub fn connect(&self) -> Result ``` -------------------------------- ### define_domain_xml Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Defines a persistent domain from an XML definition. The domain is not started after definition. ```APIDOC ## define_domain_xml ### Description Defines a persistent domain from XML (not started). ### Method `define_domain_xml` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Parameters - **xml** (`&str`) - Required - Domain XML definition ### Returns - `Result` - Defined Domain object ``` -------------------------------- ### Connect::capabilities Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Returns XML describing the host's capabilities, including supported hypervisors, architectures, and features. ```APIDOC ## Connect::capabilities ### Description Returns XML describing the host's capabilities, including supported hypervisors, architectures, and features. ### Method `pub fn capabilities(&self) -> Result` ### Returns `Result` - XML document with capabilities ``` -------------------------------- ### Get connection URI Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Retrieves the connection URI string that was used to establish the connection. ```rust pub fn uri(&self) -> Result ``` -------------------------------- ### Get Node Information Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Fetches detailed information about the host's resources, including CPU model, memory, and core counts. This is useful for system introspection. ```rust pub fn node_info(&self) -> Result ``` -------------------------------- ### Open a connection with authentication Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Opens a connection to the hypervisor with support for custom authentication via a callback. ```rust pub fn open_auth( uri: Option<&str>, auth: &mut ConnectAuth, flags: sys::virConnectFlags, ) -> Result ``` -------------------------------- ### Get Domain Name Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Retrieves the name of the domain. This is a fundamental property for identifying a domain. ```rust pub fn name(&self) -> Result ``` -------------------------------- ### set_autostart Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Sets the domain's autostart behavior. This method enables or disables the automatic startup of the domain on host boot. ```APIDOC ## set_autostart ### Description Sets domain autostart behavior. ### Method Rust Method ### Parameters #### Path Parameters - **autostart** (bool) - Required - Whether to enable or disable autostart. ### Signature `pub fn set_autostart(&self, autostart: bool) -> Result<(), Error>` ``` -------------------------------- ### Create Snapshot from XML Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Creates a new domain snapshot based on an XML description. Ensure the XML is correctly formatted according to libvirt schema. ```rust pub fn snapshot_create_xml( &self, xml: &str, flags: sys::virDomainSnapshotCreateFlags, ) -> Result ``` -------------------------------- ### Create Network from XML Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Creates and activates a network from an XML description. Returns the created Network object. ```rust pub fn create_network_xml(&self, xml: &str) -> Result ``` -------------------------------- ### Get connection driver type Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Retrieves the type of the connection driver, such as 'qemu', 'xen', or 'kvm'. ```rust pub fn driver_type(&self) -> Result ``` -------------------------------- ### Get remote libvirt library version Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Retrieves the version of the remote libvirt library connected to. ```rust pub fn lib_version(&self) -> Result ``` -------------------------------- ### domain_xml_from_native Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Converts a native hypervisor configuration into libvirt XML format. ```APIDOC ## domain_xml_from_native ### Description Converts native hypervisor configuration to libvirt XML. ### Method POST ### Endpoint /connect/domain/xml/from_native ### Parameters #### Request Body - **nformat** (string) - Required - Native format (e.g., "xen-xm", "qemu-argv") - **nconfig** (string) - Required - Native configuration string - **flags** (u32) - Required - Conversion flags ### Response #### Success Response (200) - **xml** (string) - XML representation ``` -------------------------------- ### List NodeDevice Capabilities Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/network-interface-nodedev.md Returns a list of capability names for the host device. ```rust pub fn list_caps(&self) -> Result, Error> ``` -------------------------------- ### Get hypervisor hostname Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Retrieves the hostname of the system where the hypervisor is running. This can be a fully-qualified domain name. ```rust let host = conn.hostname().unwrap(); println!("Hypervisor host: {}", host); ``` -------------------------------- ### Get Secret Usage Type Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/secrets-snapshots-advanced.md Retrieves the integer code representing the type of secret usage. ```rust pub fn usage_type(&self) -> Result ``` -------------------------------- ### Open a connection to the hypervisor Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Opens a connection to the hypervisor using a specified URI. If no URI is provided, it defaults to the LIBVIRT_DEFAULT_URI environment variable or auto-detects a driver. ```rust use virt::connect::Connect; let conn = match Connect::open(Some("qemu:///system")) { Ok(c) => c, Err(e) => panic!("Unable to connect: {e}"), }; ``` -------------------------------- ### Get Number of Storage Volumes Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/storage.md Returns the count of storage volumes within the storage pool. ```rust pub fn num_of_volumes(&self) -> Result ``` -------------------------------- ### StoragePool::set_autostart Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/storage.md Sets the autostart behavior for the storage pool. ```APIDOC ## StoragePool::set_autostart ### Description Sets pool autostart behavior. ### Method PUT ### Endpoint `/storage_pool/{pool_name}/autostart` (Conceptual) ### Parameters #### Request Body - **autostart** (boolean) - Required - Set to true to enable autostart, false to disable. ### Response #### Success Response (204) No Content. ### Response Example ```json { "autostart": false } ``` ``` -------------------------------- ### Get Network Bridge Name Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/network-interface-nodedev.md Retrieves the bridge name associated with a bridged virtual network. ```rust pub fn bridge_name(&self) -> Result ``` -------------------------------- ### Create a Volume in a Pool Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/storage.md Shows how to define the XML for a new storage volume within an existing pool. Note that actual volume creation might require pool-specific tools or direct filesystem operations. ```rust let pool = conn.lookup_storage_pool_by_name("mypool")?; let vol_xml = r###" newdisk.img 10737418240 "###; // Note: Creating volumes via XML is pool-type specific // Use libvirt tools or create volumes directly on filesystem ``` -------------------------------- ### define_domain_xml_flags Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Defines a persistent domain from an XML definition with specified flags. The domain is not started after definition. ```APIDOC ## define_domain_xml_flags ### Description Defines a persistent domain with flags. ### Method `define_domain_xml_flags` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Parameters - **xml** (`&str`) - Required - Domain XML definition - **flags** (`sys::virDomainDefineFlags`) - Required - Definition flags ### Returns - `Result` - Defined Domain object ``` -------------------------------- ### Create and Revert Domain Snapshots Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/README.md Manage domain snapshots by creating a new snapshot from XML definition and reverting to an existing snapshot. Snapshots capture the VM's state. ```rust // Create snapshot let xml = r#" backup1 Before updates "#; let snap = domain.snapshot_create_xml(xml, 0)?; // Revert to snapshot snap.revert(0)?; ``` -------------------------------- ### List Network Names Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Retrieves the names of all active networks. Use this to get a list of available networks. ```rust let nets = conn.list_networks().unwrap(); for name in nets { println!("Network: {}", name); } ``` -------------------------------- ### Convert Native to XML Domain Configuration Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Converts a domain's configuration from a native hypervisor format to libvirt XML. Provide the native format, configuration string, and conversion flags. ```rust pub fn domain_xml_from_native( &self, nformat: &str, nconfig: &str, flags: u32, ) -> Result ``` -------------------------------- ### Get Parent Snapshot Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/secrets-snapshots-advanced.md Retrieves the parent snapshot object for the current snapshot. Requires specifying flags. ```rust pub fn get_parent(&self, flags: u32) -> Result ``` -------------------------------- ### Get Secret Value Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/secrets-snapshots-advanced.md Retrieves the secret's sensitive data as a byte vector. Use with caution. ```rust pub fn get_value(&self, flags: u32) -> Result, Error> ``` -------------------------------- ### domain_xml_to_native Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Converts libvirt XML domain configuration into a native hypervisor format. ```APIDOC ## domain_xml_to_native ### Description Converts libvirt XML to native hypervisor configuration. ### Method POST ### Endpoint /connect/domain/xml/to_native ### Parameters #### Request Body - **nformat** (string) - Required - Target native format - **dxml** (string) - Required - Domain XML - **flags** (u32) - Required - Conversion flags ### Response #### Success Response (200) - **nativeConfig** (string) - Native configuration string ``` -------------------------------- ### Get Domain Metadata Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Retrieves domain metadata. Specify the metadata type, an optional URI, and flags. ```rust pub fn get_metadata( &self, metadata_type: i32, uri: Option<&str>, flags: u32, ) -> Result ``` -------------------------------- ### Connect Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/types.md Represents a connection to a libvirt hypervisor and serves as the primary entry point for all libvirt operations. Connections are created using `Connect::open()`. ```APIDOC ## Struct: Connect ### Description Represents a connection to a libvirt hypervisor. ### Usage Primary entry point for all libvirt operations. Create with `Connect::open()`. ``` -------------------------------- ### Get Memory Parameters Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Fetches the memory parameters structure for a domain. The `flags` parameter can modify the retrieval behavior. ```rust pub fn memory_parameters(&self, flags: u32) -> Result ``` -------------------------------- ### Connect::sys_info Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Returns host system information, including SMBIOS/sysinfo data, as an XML string. ```APIDOC ## Connect::sys_info ### Description Returns host system information, including SMBIOS/sysinfo data, as an XML string. ### Method `pub fn sys_info(&self, flags: u32) -> Result` ### Parameters #### Path Parameters - **flags** (`u32`) - Required - Flags for system info query ### Returns `Result` - XML with SMBIOS/sysinfo data ``` -------------------------------- ### Get Storage Volume Path Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/storage.md Retrieves the host path of the storage volume. This method is part of the StorageVol type. ```rust pub fn path(&self) -> Result ``` -------------------------------- ### Get Domain ID Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Retrieves the unique integer ID of a running domain. This ID is only available for active domains. ```rust pub fn id(&self) -> Result ``` -------------------------------- ### Define and Create Virtual Network Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/README.md Defines a virtual network with NAT forwarding and DHCP, then creates it and prints its name and bridge interface. ```rust // Define a virtual network let net_xml = r###" mynet "###; let net = conn.define_network_xml(net_xml)?; net.create()?; println!("Network created: {}", net.name()?); println!("Bridge: {}", net.bridge_name()?); ``` -------------------------------- ### Connect to Test Driver Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/README.md Connect to the libvirt test driver, which simulates libvirt functionality without running actual virtual machines. Useful for development and testing purposes. ```rust // Test driver for development/testing (no actual VMs) let conn = Connect::open(Some("test:///default"))?; // Lists pre-defined test resources let domains = conn.list_domains()?; ``` -------------------------------- ### set_user_password Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Sets the password for a domain user. This operation requires the guest agent to be installed and running within the domain. ```APIDOC ## set_user_password ### Description Sets password for domain user (requires guest agent). ### Method Rust Method ### Parameters #### Path Parameters - **user** (string) - Required - The username for which to set the password. - **password** (string) - Required - The new password. - **flags** (u32) - Required - Flags to control the password setting operation. ### Signature `pub fn set_user_password(&self, user: &str, password: &str, flags: u32) -> Result<(), Error>` ``` -------------------------------- ### Basic Domain Lookup Error Handling Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/errors.md Demonstrates how to handle potential errors when looking up a domain by name. It prints the error code, domain, message, and level if the lookup fails. ```rust use virt::error::Error; match conn.lookup_domain_by_name("myvm") { Ok(domain) => println!("Found domain"), Err(e) => { eprintln!("Error code: {}", e.code()); eprintln!("Error domain: {}", e.domain()); eprintln!("Error message: {}", e.message()); eprintln!("Error level: {:?}", e.level()); } } ``` -------------------------------- ### Get Free Memory Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Retrieves the total free memory on the host in bytes. Use this to check available system memory. ```rust pub fn free_memory(&self) -> Result ``` -------------------------------- ### Set Memory Parameters for a Domain Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/README.md Configure hard and soft memory limits for a virtual machine. Ensure the correct units are used for limits. ```rust use virt::domain::MemoryParameters; let mut params = MemoryParameters::default(); params.hard_limit = Some(1_048_576); // 1 GiB params.soft_limit = Some(524_288); // 512 MiB domain.set_memory_parameters(¶ms, 0)?; ``` -------------------------------- ### Get local libvirt library version Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Retrieves the version of the local libvirt library. The version is returned as a single integer. ```rust let ver = Connect::version().unwrap(); println!("Libvirt version: {}", ver); ``` -------------------------------- ### Connection Management API Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/INDEX.md Provides methods for establishing and managing connections to hypervisors, querying connection details, and listing resources. Includes operations for opening connections (read-only, authenticated), retrieving version information, and discovering available domains, networks, and storage pools. ```APIDOC ## Connection Management ### Description Methods for establishing and managing connections to hypervisors, querying connection details, and listing resources. Includes operations for opening connections (read-only, authenticated), retrieving version information, and discovering available domains, networks, and storage pools. ### Methods - `Connect::open()`: Open hypervisor connections (system, session, test drivers). - `Connect::open_read_only()`: Establish read-only connections. - `Connect::open_auth()`: Open authenticated connections with credentials. - `Connect::version()`: Get libvirt and hypervisor version information. - `Connect::hostname()`: Get the hypervisor's hostname. - `Connect::capabilities()`: Retrieve hypervisor capabilities. - `Connect::driver_type()`: Get the hypervisor driver type. - `Connect::uri()`: Get the connection URI. - `Connect::list_domains()`: List available domains. - `Connect::list_networks()`: List available networks. - `Connect::list_storage_pools()`: List available storage pools. - `Connect::list_interfaces()`: List available network interfaces. - `Connect::list_all_*()`: Methods for listing all resources with filtering. - `Connect::num_of_*()`: Methods for getting counts of resources. - `Connect::lookup_*_by_*()`: Methods for finding specific resources. - `Connect::create_*_xml()`: Create transient resources from XML descriptions. - `Connect::define_*_xml()`: Define persistent resources from XML descriptions. - `Connect::node_info()`: Get node information. - `Connect::free_memory()`: Get free memory on the node. - `Connect::cells_free_memory()`: Get free memory per NUMA cell. - `Connect::cpu_models_names()`: Get available CPU model names. - `Connect::max_vcpus()`: Get the maximum number of virtual CPUs supported. - `Connect::compare_cpu()`: Compare CPU models. - `Connect::baseline_cpu()`: Get the baseline CPU for a given set of features. ### Types - **NodeInfo**: Structure containing node-specific information. - **ConnectCredential**: Structure for connection credentials. - **ConnectAuth**: Structure for authentication details. ``` -------------------------------- ### Get Snapshot XML Description Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/secrets-snapshots-advanced.md Retrieves the XML definition of the domain snapshot. Requires specifying flags for XML format. ```rust pub fn xml_desc(&self, flags: sys::virDomainSnapshotXMLFlags) -> Result ``` -------------------------------- ### Get Secret Usage ID Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/secrets-snapshots-advanced.md Retrieves the identifier string associated with the secret's usage (e.g., 'ceph', 'iscsi'). ```rust pub fn usage_id(&self) -> Result ``` -------------------------------- ### list_all_node_devices Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Fetches all node device objects managed by libvirt. ```APIDOC ## list_all_node_devices ### Description Returns all node device objects. ### Method `pub fn list_all_node_devices(&self, flags: sys::virConnectListAllNodeDeviceFlags) -> Result, Error>` ### Parameters #### Path Parameters - **flags** (`sys::virConnectListAllNodeDeviceFlags`) - Required - Filter flags ### Returns `Result, Error>` - Vector of NodeDevice objects ``` -------------------------------- ### Get Network Interface Statistics Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Retrieves I/O statistics for a network interface. The `device` parameter specifies the interface name. ```rust pub fn get_interface_stats(&self, device: &str) -> Result, Error> ``` -------------------------------- ### Create Domain Snapshot from XML Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/secrets-snapshots-advanced.md Creates a new domain snapshot using an XML definition. The `flags` parameter can specify creation options like quiesce or atomic operations. ```rust pub fn snapshot_create_xml( &self, xml: &str, flags: sys::virDomainSnapshotCreateFlags, ) -> Result ``` ```rust let snap_xml = r###" backup1 Backup before updates "###; let snap = domain.snapshot_create_xml(snap_xml, 0)?; ``` -------------------------------- ### Get Memory Statistics Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Retrieves memory statistics for a domain. The `flags` parameter can be used to control the type of statistics returned. ```rust pub fn memory_stats(&self, flags: u32) -> Result, Error> ``` -------------------------------- ### Get Current Memory Allocation Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Returns the current memory allocation of a domain in KBytes. This reflects the active memory usage. ```rust pub fn memory(&self) -> Result ``` -------------------------------- ### list_storage_pools Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/storage.md Retrieves a list of names for all currently active storage pools. This is useful for getting a quick overview of available pools. ```APIDOC ## list_storage_pools ### Description Returns the names of all active storage pools. ### Method `list_storage_pools` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example (Not explicitly provided in source) ### Response #### Success Response - **Vec** - A vector containing the names of active storage pools. #### Response Example (Not explicitly provided in source) #### Error Handling - Returns `Error` on failure. ``` -------------------------------- ### Get Storage Volume Key Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/storage.md Retrieves the unique key identifier for the storage volume. This method is part of the StorageVol type. ```rust pub fn key(&self) -> Result ``` -------------------------------- ### Get Domain UUID Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Retrieves the universally unique identifier (UUID) of the domain as a byte array. This is a stable identifier for a domain. ```rust pub fn uuid(&self) -> Result ``` -------------------------------- ### Connect::driver_type Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/connect.md Returns the connection driver type, such as "qemu", "xen", or "kvm". ```APIDOC ## Connect::driver_type ### Description Returns the connection driver type, such as "qemu", "xen", or "kvm". ### Method `pub fn driver_type(&self) -> Result` ### Returns `Result` - Driver name (e.g., "qemu", "xen", "kvm") ``` -------------------------------- ### Domain Lookup Error Recovery with Multiple Methods Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/errors.md Shows how to attempt domain lookup using multiple methods (name, UUID string, ID) and recover from errors by trying the next method. Requires the `?` operator for error propagation. ```rust // Try multiple lookup methods let domain = conn.lookup_domain_by_name("myvm") .or_else(|_| conn.lookup_domain_by_uuid_string("550e8400-e29b-41d4-a716-446655440000")) .or_else(|_| conn.lookup_domain_by_id(1))?; ``` -------------------------------- ### Get Storage Pool Information Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/storage.md Retrieves information about the storage pool, including state, capacity, allocation, and available space. ```rust pub fn info(&self) -> Result ``` -------------------------------- ### Migrate Domain to Another Host Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/api-reference/domain.md Initiates a live migration of the domain to a different host specified by `dconn`. Optional parameters for destination name, URI, and bandwidth control are available. ```rust pub fn migrate( &self, dconn: &Connect, flags: sys::virDomainMigrateFlags, dname: Option<&str>, uri: Option<&str>, bandwidth: u64, ) -> Result ``` -------------------------------- ### DomainInfo Struct Source: https://gitlab.com/libvirt/libvirt-rust/-/blob/master/_autodocs/types.md Contains detailed information about a virtual machine domain, including state, memory, and CPU usage. ```rust pub struct DomainInfo { pub state: DomainStateEnum, pub max_mem: u64, // Maximum memory in KBytes pub memory: u64, // Current memory in KBytes pub nr_virt_cpu: u32, // Number of virtual CPUs pub cpu_time: u64, // CPU time in nanoseconds } ```