### StorageVolume GetPath Example Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Example demonstrating how to get the path of a storage volume and handle potential errors. It ensures the volume reference is freed using defer. ```go vol, _ := pool.LookupVolumeByName("disk.img") defer vol.Free() path, err := vol.GetPath() if err == nil { fmt.Println("Path:", path) } ``` -------------------------------- ### Start a Virtual Machine Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/README.txt Looks up a virtual machine by its name, ensures its resources are freed, and then starts it. ```go dom, _ := conn.LookupDomainByName("myvm") defer dom.Free() dom.Create() ``` -------------------------------- ### GetAutostart Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Gets the autostart setting for the storage pool. ```APIDOC ## GetAutostart ### Description Gets the autostart setting for the storage pool. ### Method `GetAutostart()` ### Parameters None ### Return `bool` - True if autostart enabled ### Throws Error if the autostart setting cannot be retrieved. ``` -------------------------------- ### Install Dependencies on Ubuntu/Debian Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/00-index.md Install the necessary libvirt development files and pkg-config on Ubuntu or Debian-based systems. ```bash sudo apt-get install libvirt-dev pkg-config ``` -------------------------------- ### Install Dependencies on RHEL/CentOS Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/00-index.md Install the required libvirt development files and pkg-config on RHEL or CentOS systems. ```bash sudo yum install libvirt-devel pkgconfig ``` -------------------------------- ### Domain.CreateWithFlags Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/02-domain.md Starts an inactive domain with specified options. This allows for more control over the domain's startup behavior, such as starting it in a paused state. ```APIDOC ## Domain.CreateWithFlags ### Description Starts an inactive domain with additional options specified by flags. This allows for customized startup behavior, such as starting the domain paused or with auto-destroy enabled. ### Method `CreateWithFlags(flags DomainCreateFlags) error` ### Parameters #### Path Parameters - **flags** (DomainCreateFlags) - Required - Flags that modify the domain creation process. Examples include `DOMAIN_START_PAUSED` or `DOMAIN_START_AUTODESTROY`. ### Throws Error if the domain fails to start with the given flags. ### Example ```go // Start domain paused err := dom.CreateWithFlags(libvirt.DOMAIN_START_PAUSED) if err != nil { log.Fatal("Failed to start domain paused:", err) } ``` ``` -------------------------------- ### Install Dependencies on macOS Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/00-index.md Install libvirt and pkg-config on macOS using Homebrew. ```bash brew install libvirt pkg-config ``` -------------------------------- ### Network.Create Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Starts an inactive network. Throws an error if the network cannot be started. ```APIDOC ## Network.Create ### Description Starts an inactive network. ### Method * (n *Network) Create() ### Throws Error if network cannot start ``` -------------------------------- ### Start Inactive Domain Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/02-domain.md Starts an inactive domain. Throws an error if the domain cannot be started. ```go err := dom.Create() if err != nil { log.Fatal("Failed to start domain:", err) } ``` -------------------------------- ### Network.GetAutostart Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Gets the autostart setting for a network. Returns true if autostart is enabled, or an error. ```APIDOC ## Network.GetAutostart ### Description Gets autostart setting. ### Method * (n *Network) GetAutostart() (bool, error) ### Return * bool - True if autostart enabled ### Throws Error if unable to retrieve autostart setting ``` -------------------------------- ### Basic Setup and Connection Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/README.txt Establishes a connection to the libvirt daemon and ensures the connection is closed upon completion. ```go import "libvirt.org/go/libvirt" conn, _ := libvirt.NewConnect("qemu:///system") defer conn.Close() ``` -------------------------------- ### Example Usage of NodeGetInfo Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/01-connect.md Demonstrates how to retrieve and print node information, including CPU count and memory. ```go info, err := conn.NodeGetInfo() if err == nil { fmt.Printf("CPUs: %d, Memory: %d KB\n", info.CPUs, info.Memory) } ``` -------------------------------- ### Start Inactive Domain with Flags Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/02-domain.md Starts an inactive domain with specified options, such as starting paused or with auto-destroy. ```go err := d.CreateWithFlags(flags) ``` -------------------------------- ### Get System Information as XML Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/01-connect.md Retrieves system information in XML format. ```go func (c *Connect) GetSysinfo(flags uint32) (string, error) ``` -------------------------------- ### Domain.Create Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/02-domain.md Starts an inactive domain, bringing it to a running state. This is a fundamental operation for launching virtual machines. ```APIDOC ## Domain.Create ### Description Starts an inactive domain, transitioning it to a running state. This is the primary method for launching a virtual machine. ### Method `Create() error` ### Parameters None ### Throws Error with code `ERR_OPERATION_FAILED` if the domain cannot be started. ### Example ```go err := dom.Create() if err != nil { log.Fatal("Failed to start domain:", err) } ``` ``` -------------------------------- ### Set Network Autostart Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Configures whether the network should start automatically when the host boots. Set 'autostart' to true to enable. ```go func (n *Network) SetAutostart(autostart bool) error ``` -------------------------------- ### Connect to Libvirt and Get Version Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/07-qemu-lxc-modules.md Shows how to establish a new connection to libvirt using a URI and retrieve the hypervisor version. Includes error handling and deferred connection closing. ```go conn, err := libvirt.NewConnect("qemu:///system") if err != nil { log.Fatal(err) } deffer conn.Close() version, err := conn.GetVersion() if err != nil { log.Fatal("Could not get hypervisor version:", err) } fmt.Printf("Connected to libvirt version %d\n", version) ``` -------------------------------- ### Get Network Autostart Setting Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Retrieves the current autostart setting for the network. Returns true if autostart is enabled. ```go func (n *Network) GetAutostart() (bool, error) ``` -------------------------------- ### Create Network Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Starts an inactive virtual network. Use this to bring a defined but stopped network online. ```go func (n *Network) Create() error ``` -------------------------------- ### SetAutostart Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Sets whether the storage pool starts automatically. ```APIDOC ## SetAutostart ### Description Sets whether the storage pool starts automatically. ### Method `SetAutostart(autostart bool)` ### Parameters - **autostart** (bool) - Required - True to enable autostart ### Throws Error if the autostart setting cannot be changed. ``` -------------------------------- ### Define Domain Creation Flags Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/06-types-reference.md Flags used when creating or starting a domain. Options include starting in a paused state, auto-destroying on connection close, bypassing cache, forcing boot, or validating XML. ```go type DomainCreateFlags uint const ( DOMAIN_START_PAUSED DomainCreateFlags = 0 DOMAIN_START_AUTODESTROY DomainCreateFlags = 1 DOMAIN_START_BYPASS_CACHE DomainCreateFlags = 2 DOMAIN_START_FORCE_BOOT DomainCreateFlags = 3 DOMAIN_START_VALIDATE DomainCreateFlags = 4 ) ``` -------------------------------- ### DomainCreateFlags Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/02-domain.md Flags that can be used when starting a domain. These flags control various aspects of the domain's startup behavior, such as whether it should start paused, auto-destroy on connection close, bypass disk cache, force boot, or validate XML before starting. ```APIDOC ## Type: DomainCreateFlags Flags for starting a domain. ```go type DomainCreateFlags uint ``` **Constants**: | Constant | Description | |----------|-------------| | DOMAIN_START_PAUSED | Start domain in paused state | | DOMAIN_START_AUTODESTROY | Auto-destroy on connection close | | DOMAIN_START_BYPASS_CACHE | Bypass disk cache | | DOMAIN_START_FORCE_BOOT | Force boot instead of resume | | DOMAIN_START_VALIDATE | Validate domain XML before starting | **Source**: `domain.go:80` ``` -------------------------------- ### Example: Creating Typed Parameters Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/07-qemu-lxc-modules.md Demonstrates how to create a map of typed parameters using the TypedParamValue interface. Supported types include int64 for cpu_shares, uint64 for memory_hard_limit, and bool for enabled. ```go // Creating typed parameters params := map[string]libvirt.TypedParamValue{ "cpu_shares": int64(2048), "memory_hard_limit": uint64(4294967296), "enabled": true, } ``` -------------------------------- ### Set Storage Pool Autostart Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Sets whether the storage pool should start automatically. Pass true to enable autostart, false to disable. ```go func (sp *StoragePool) SetAutostart(autostart bool) error ``` -------------------------------- ### GetInfo Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Gets information about the storage pool. ```APIDOC ## GetInfo ### Description Gets information about the storage pool. ### Method `GetInfo()` ### Parameters None ### Return `*StoragePoolInfo` - Pool information ### Throws Error if info cannot be retrieved. ``` -------------------------------- ### Retrieve Domain Statistics Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/00-index.md Fetch state and CPU statistics for a virtual machine domain. This example shows how to access CPU time and user time. ```go stats, err := dom.GetStats( libvirt.DOMAIN_STATS_STATE | libvirt.DOMAIN_STATS_CPU, 0, ) if err == nil { fmt.Printf("CPU time: %d ns\n", stats.CPU.Time) fmt.Printf("CPU user: %d ns\n", stats.CPU.User) ``` -------------------------------- ### Network.SetAutostart Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Sets whether a network starts automatically. Accepts a boolean for autostart setting and throws an error if unable to set it. ```APIDOC ## Network.SetAutostart ### Description Sets whether network starts automatically. ### Method * (n *Network) SetAutostart(autostart bool) error ### Parameters #### Path Parameters * **autostart** (bool) - Required - True to enable autostart ### Throws Error if unable to set autostart ``` -------------------------------- ### DomainCreateFlags Type Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/02-domain.md Defines flags for starting a domain. These constants can be used to control how a domain is initiated. ```go type DomainCreateFlags uint ``` -------------------------------- ### Get Storage Pool Autostart Setting Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Retrieves the current autostart setting for the storage pool. Returns true if autostart is enabled, false otherwise. ```go func (sp *StoragePool) GetAutostart() (bool, error) ``` -------------------------------- ### Get Domain Snapshot XML Description Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/02-domain.md Fetches the XML description of the snapshot, detailing its configuration. ```go func (ds *DomainSnapshot) GetXMLDesc(flags DomainSnapshotXMLFlags) (string, error) ``` -------------------------------- ### Get Domain Name Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/02-domain.md Retrieves the name of the domain. Handles errors if the name cannot be obtained. ```go name, err := dom.GetName() if err == nil { fmt.Println("Domain:", name) } ``` -------------------------------- ### Get Hypervisor Capabilities Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/01-connect.md Retrieves an XML document describing the hypervisor's capabilities. This is useful for understanding the features supported by the hypervisor. ```go func (c *Connect) GetCapabilities() (string, error) ``` -------------------------------- ### GetQEMUVersion Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/07-qemu-lxc-modules.md Gets the version of QEMU used by the connected hypervisor. This is useful for compatibility checks and understanding the QEMU environment. ```APIDOC ## GetQEMUVersion ### Description Gets the version of QEMU used by the connected hypervisor. This is useful for compatibility checks and understanding the QEMU environment. ### Method Go Function ### Response #### Success Response - **uint64** - QEMU version as calculated version number #### Throws - Error if QEMU version unavailable ``` -------------------------------- ### Get Virtual Machine CPU Statistics Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/README.txt Retrieves CPU statistics for a virtual machine and prints the CPU time. ```go stats, _ := dom.GetStats(libvirt.DOMAIN_STATS_CPU, 0) fmt.Println(stats.CPU.Time) ``` -------------------------------- ### Get Network XML Description Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Retrieves the XML definition of the network. Pass 0 for flags as they are reserved. ```go func (n *Network) GetXMLDesc(flags uint32) (string, error) ``` -------------------------------- ### Standard Build Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/00-index.md Use this command for a standard build of the libvirt Go module, including all default features. ```bash go get libvirt.org/go/libvirt go build ./... ``` -------------------------------- ### Handle Operation Timeout Errors Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/04-errors.md Provides an example of how to detect and manage timeouts during long-running libvirt operations. This pattern is essential for preventing applications from hanging indefinitely. ```go // For long-running operations err := dom.MigrateToURI(destURI, flags, "", bandwidth) if err != nil { libvirtErr, ok := err.(*libvirt.Error) if ok && libvirtErr.Code == libvirt.ERR_OPERATION_TIMEOUT { fmt.Println("Migration operation timed out") // May need to increase timeout or check migration in progress } } ``` -------------------------------- ### Get Node Memory Statistics Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/01-connect.md Retrieves memory statistics for a specific NUMA cell or all cells. Pass -1 for cellNum to get total memory stats. Reserved flags should be passed as 0. ```go func (c *Connect) NodeGetMemoryStats(cellNum int, flags uint32) (*NodeMemoryStats, error) ``` -------------------------------- ### Execute Raw QEMU Monitor Command Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/07-qemu-lxc-modules.md Executes a raw QEMU monitor command on a specified domain. Use this for direct interaction with the QEMU monitor when specific commands are needed. Ensure the domain object is valid and the command is correctly formatted. ```go func QEMUMonitorCommand(dom *Domain, cmd string, flags QEMUMonitorCommandFlags) (string, error) ``` ```go output, err := libvirt.QEMUMonitorCommand(dom, "info status", 0) if err == nil { fmt.Println("Status:", output) } ``` -------------------------------- ### Get Node CPU Statistics Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/01-connect.md Retrieves CPU time statistics for a specific CPU or all CPUs. Pass -1 for cpuNum to get total CPU stats. Reserved flags should be passed as 0. ```go func (c *Connect) NodeGetCPUStats(cpuNum int, flags uint32) (*NodeCPUStats, error) ``` -------------------------------- ### Create Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Activates the storage pool. ```APIDOC ## Create ### Description Activates the storage pool. ### Method `Create()` ### Parameters None ### Throws Error if pool cannot be activated. ``` -------------------------------- ### Get Node Information Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/01-connect.md Retrieves general information about the host system (node). Throws an error if unable to retrieve node info. ```go func (c *Connect) NodeGetInfo() (*NodeInfo, error) ``` -------------------------------- ### Get Interface XML Description Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Retrieves the XML description of the network interface. Requires flags to specify the desired description format. ```go func (i *Interface) GetXMLDesc(flags uint32) (string, error) ``` -------------------------------- ### Get QEMU Version Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/07-qemu-lxc-modules.md Retrieves the version of QEMU used by the connected hypervisor. This function is useful for compatibility checks or to determine feature availability. ```go func GetQEMUVersion() (uint64, error) ``` -------------------------------- ### GetName Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Gets the name of the storage pool. ```APIDOC ## GetName ### Description Gets the name of the storage pool. ### Method `GetName()` ### Parameters None ### Return `string` - Pool name ### Throws Error if the name cannot be retrieved. ``` -------------------------------- ### NWFilter.GetName Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/05-events-admin-stream.md Gets the name of the network filter. ```APIDOC ## NWFilter.GetName ### Description Gets the name of the network filter. ### Method * (nf *NWFilter) GetName() (string, error) ### Parameters None ### Returns * string - The filter name. * error - Error if retrieving the name fails. ``` -------------------------------- ### NodeDevice Methods Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/05-events-admin-stream.md Provides methods for interacting with host node devices, such as freeing, getting names and descriptions, listing capabilities, detaching, reattaching, and resetting devices. ```APIDOC ## NodeDevice Methods ### Free Decrements the reference count for a NodeDevice. ### GetName Gets the name of the NodeDevice. **Return**: `string` - Device name ### GetXMLDesc Gets the XML description of the NodeDevice. **Parameters**: - **flags** (uint32) - Reserved, pass 0 **Return**: `string` - Device XML ### ListCaps Lists the capabilities of the NodeDevice. **Return**: `[]string` - Capability names ### Detach Detaches the NodeDevice from the host (for VT-d/IOMMU passthrough). **Throws**: Error if detach fails ### Reattach Reattaches the NodeDevice to the host. **Throws**: Error if reattach fails ### Reset Resets the NodeDevice. **Throws**: Error if reset fails ``` -------------------------------- ### Get Storage Pool XML Description Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Retrieves the XML description of the storage pool. The flags parameter is reserved and should be passed as 0. ```go func (sp *StoragePool) GetXMLDesc(flags uint32) (string, error) ``` -------------------------------- ### GetXMLDesc Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Gets the XML description of the storage pool. ```APIDOC ## GetXMLDesc ### Description Gets the XML description of the storage pool. ### Method `GetXMLDesc(flags uint32)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **flags** (uint32) - Required - Reserved, pass 0 ### Return `string` - Pool XML definition ### Throws Error if the XML description cannot be retrieved. ``` -------------------------------- ### Open LXC Container Namespaces Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/07-qemu-lxc-modules.md Opens container namespaces for direct access. Use this to get file descriptors for specific namespaces like network. Ensure to close the file descriptors when done. ```go fds, err := libvirt.LXCOpenNamespace(dom, 1, libvirt.LXC_OPEN_NAMESPACE_NET) if err == nil { defer func() { for _, fd := range fds { syscall.Close(fd) } }() } ``` -------------------------------- ### Get Domain State Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/02-domain.md Retrieves the current state of the domain, including optional reason codes. Throws an error if the state cannot be determined. ```go func (d *Domain) GetState() ([]DomainState, error) ``` ```go states, err := dom.GetState() if err == nil { fmt.Printf("State: %v\n", states[0]) } ``` -------------------------------- ### GetUUIDString Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Gets the UUID of the storage pool as a string. ```APIDOC ## GetUUIDString ### Description Gets the UUID of the storage pool as a string. ### Method `GetUUIDString()` ### Parameters None ### Return `string` - UUID in standard format ### Throws Error if the UUID string cannot be retrieved. ``` -------------------------------- ### NWFilter.GetUUIDString Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/05-events-admin-stream.md Gets the UUID string of the network filter. ```APIDOC ## NWFilter.GetUUIDString ### Description Gets the UUID string of the network filter. ### Method * (nf *NWFilter) GetUUIDString() (string, error) ### Parameters None ### Returns * string - The filter UUID. * error - Error if retrieving the UUID fails. ``` -------------------------------- ### NodeDevice ListCaps Method Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/05-events-admin-stream.md Lists the capabilities supported by the NodeDevice. Returns a slice of strings representing capability names. ```go func (nd *NodeDevice) ListCaps() ([]string, error) ``` -------------------------------- ### Control Domain Lifecycle Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/00-index.md Perform lifecycle operations on a virtual machine domain, such as starting, pausing, resuming, shutting down, or destroying it. Ensure the domain object is freed. ```go // Start a domain dom, _ := conn.LookupDomainByName("myvm") defer dom.Free() err := dom.Create() // Power on err = dom.Suspend() // Pause err = dom.Resume() // Unpause err = dom.Shutdown() // Graceful shutdown err = dom.Destroy() // Hard power off ``` -------------------------------- ### Establish Admin Connection Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/05-events-admin-stream.md Establishes an admin connection to libvirtd. Use a valid URI and appropriate connection flags. ```go admConn, err := libvirt.NewAdmConnect("qemu:///system", 0) if err != nil { log.Fatal(err) } deffer admConn.Close() ``` -------------------------------- ### GetUUID Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Gets the UUID of the storage pool as a 16-byte array. ```APIDOC ## GetUUID ### Description Gets the UUID of the storage pool as a 16-byte array. ### Method `GetUUID()` ### Parameters None ### Return `[]byte` - UUID ### Throws Error if the UUID cannot be retrieved. ``` -------------------------------- ### NWFilter.GetXMLDesc Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/05-events-admin-stream.md Gets the XML definition of the network filter with specified flags. ```APIDOC ## NWFilter.GetXMLDesc ### Description Gets the XML definition of the network filter with specified flags. ### Method * (nf *NWFilter) GetXMLDesc(flags uint32) (string, error) ### Parameters * **flags** (uint32) - Required - Flags to control the XML output. ### Returns * string - The filter XML definition. * error - Error if retrieving the XML fails. ``` -------------------------------- ### Run All Unit Tests Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/00-index.md Execute all unit tests within the project using the standard Go testing command. ```bash go test ./... ``` -------------------------------- ### Get Domain UUID String Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/02-domain.md Retrieves the UUID of the domain as a formatted string. ```go uuidStr, err := d.GetUUIDString() ``` -------------------------------- ### Interface.Create Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Activates the network interface. ```APIDOC ## Interface.Create ### Description Activates the interface. ### Method ```go func (i *Interface) Create() error ``` ### Throws Error if activation fails. ``` -------------------------------- ### AdmServer.GetName Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/05-events-admin-stream.md Gets the name of the admin server. This can be useful for identifying the server instance. ```APIDOC ## AdmServer.GetName ### Description Gets the server name. ### Method Go Method ### Parameters None ### Response - string - Server name - error - Error if getting name fails ``` -------------------------------- ### NewConnectWithAuth Constructor Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/01-connect.md Establishes a connection with authentication parameters, including URI, authentication credentials, and connection flags. ```go func NewConnectWithAuth(uri string, auth *ConnectAuth, flags ConnectFlags) (*Connect, error) ``` -------------------------------- ### NetworkPort.GetXMLDesc Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Gets the XML description of the network port. Returns the port XML or an error. ```APIDOC ## NetworkPort.GetXMLDesc ### Description Gets the XML description of the port. ### Method * (n *NetworkPort) GetXMLDesc(flags uint32) (string, error) ### Parameters #### Path Parameters * **flags** (uint32) - Required - Reserved, pass 0 ### Return * string - Port XML ### Throws Error if unable to retrieve XML description ``` -------------------------------- ### List All Interfaces Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/01-connect.md Lists all available network interfaces. Returns a slice of interface names. ```go func (c *Connect) ListInterfaces() ([]string, error) ``` -------------------------------- ### Get Admin Connection URI Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/05-events-admin-stream.md Retrieves the connection URI for an active admin connection. ```go func (c *AdmConnect) GetURI() (string, error) ``` -------------------------------- ### Check for Unsupported Features Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/04-errors.md Illustrates how to detect if a requested operation is not supported by the underlying hypervisor. This is useful for implementing fallback mechanisms or informing the user. ```go err := vol.Wipe(0) if err != nil { libvirtErr, ok := err.(*libvirt.Error) if ok && libvirtErr.Code == libvirt.ERR_NO_SUPPORT { fmt.Println("Wiping not supported by this hypervisor") // Fallback to alternative method } } ``` -------------------------------- ### GetCapabilities Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/01-connect.md Fetches an XML document detailing the capabilities of the connected libvirt hypervisor. ```APIDOC ## GetCapabilities ### Description Gets an XML document describing the hypervisor capabilities. ### Method `func (c *Connect) GetCapabilities() (string, error)` ### Response #### Success Response - **string** - XML capabilities document. - **error** (error) - nil if capabilities retrieval succeeded. #### Error Response - **error** (error) - Error if unable to query capabilities. ### Example ```go caps, err := conn.GetCapabilities() if err == nil { fmt.Println("Capabilities:", caps) } ``` ``` -------------------------------- ### Get Interface Name Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Retrieves the name of the network interface. Returns the interface name as a string. ```go func (i *Interface) GetName() (string, error) ``` -------------------------------- ### Distinguish Missing Resources and Connection Issues Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/04-errors.md Shows how to differentiate between various errors when looking up a domain, such as the domain not existing or the connection to libvirtd being lost. This pattern helps in providing specific user feedback. ```go dom, err := conn.LookupDomainByName(name) if err != nil { libvirtErr, ok := err.(*libvirt.Error) if ok { switch libvirtErr.Code { case libvirt.ERR_NO_DOMAIN: fmt.Println("Domain does not exist") case libvirt.ERR_NO_CONNECT: fmt.Println("Connection lost to libvirtd") case libvirt.ERR_OPERATION_DENIED: fmt.Println("Permission denied - use connection with write access") default: fmt.Printf("Error: %s\n", libvirtErr.Message) } } } ``` -------------------------------- ### NetworkPort.GetUUIDString Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Gets the UUID of the network port as a formatted string. Returns the UUID string or an error. ```APIDOC ## NetworkPort.GetUUIDString ### Description Gets the UUID of the port. ### Method * (n *NetworkPort) GetUUIDString() (string, error) ### Return * string - UUID in standard format ### Throws Error if unable to retrieve UUID string ``` -------------------------------- ### Error Handling with Libvirt Errors Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/README.txt Demonstrates how to check for errors and specifically handle libvirt errors by inspecting their codes. ```go if err != nil { if libvirtErr, ok := err.(*libvirt.Error); ok { switch libvirtErr.Code { ... } } } ``` -------------------------------- ### Network.GetUUID Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Gets the UUID of the network as a 16-byte array. Returns the UUID or an error if unable to retrieve it. ```APIDOC ## Network.GetUUID ### Description Gets the UUID of the network as a 16-byte array. ### Method * (n *Network) GetUUID() ([]byte, error) ### Return * []byte - 16-byte UUID ### Throws Error if unable to retrieve UUID ``` -------------------------------- ### Get Connection URI Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/01-connect.md Retrieves the URI of the current connection. This can be used to confirm the connection details. ```go func (c *Connect) GetURI() (string, error) ``` ```go uri, err := conn.GetURI() if err == nil { fmt.Println("Connected to:", uri) } ``` -------------------------------- ### Using Defer for Libvirt Object Cleanup Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/07-qemu-lxc-modules.md Illustrates the recommended pattern for ensuring libvirt objects are freed using the defer statement. The Free() method is guaranteed to be called, even on early returns. ```go dom, err := conn.LookupDomainByName("myvm") if err != nil { return err } defer dom.Free() // Always called, even on early return ``` -------------------------------- ### Get Domain Snapshot Name Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/02-domain.md Retrieves the name of the snapshot. Useful for identifying specific snapshots. ```go func (ds *DomainSnapshot) GetName() (string, error) ``` -------------------------------- ### NewConnect Constructor Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/01-connect.md Establishes a new connection to a libvirt hypervisor using a specified URI. Ensure to close the connection when done. ```go func NewConnect(uri string) (*Connect, error) ``` ```go conn, err := libvirt.NewConnect("qemu:///system") if err != nil { log.Fatal(err) } deffer conn.Close() ``` -------------------------------- ### Handle Domain Not Found Error Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/00-index.md Demonstrates how to specifically check for and handle the 'no domain found' error when attempting to look up a domain by name. ```go dom, err := conn.LookupDomainByName("nonexistent") if err != nil { libvirtErr, ok := err.(*libvirt.Error) if ok && libvirtErr.Code == libvirt.ERR_NO_DOMAIN { fmt.Println("Domain not found") } } ``` -------------------------------- ### Get AdmServer Name Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/05-events-admin-stream.md Retrieves the name of the server. This is useful for identifying specific server instances. ```go func (s *AdmServer) GetName() (string, error) ``` -------------------------------- ### Send Command to QEMU Guest Agent Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/07-qemu-lxc-modules.md Sends a command to the QEMU guest agent running inside a domain. This is used for interacting with services or retrieving information from within the guest OS. A timeout can be specified for the agent's response. ```go func QEMUDomainAgentCommand(dom *Domain, cmd string, timeout int, flags uint32) (string, error) ``` ```go cmd := `{"execute":"guest-info"}` resp, err := libvirt.QEMUDomainAgentCommand(dom, cmd, -1, 0) if err == nil { fmt.Println("Agent response:", resp) } ``` -------------------------------- ### Get Daemon Logging Filters Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/05-events-admin-stream.md Retrieves the current logging filter configuration for the libvirtd daemon. ```go func (c *AdmConnect) GetLoggingFilters(flags uint32) (string, error) ``` -------------------------------- ### QEMUDomainAgentCommand Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/07-qemu-lxc-modules.md Sends a command to the QEMU guest agent inside a domain. This allows for interaction with services running within the guest operating system. ```APIDOC ## QEMUDomainAgentCommand ### Description Sends a command to the QEMU guest agent inside a domain. This allows for interaction with services running within the guest operating system. ### Method Go Function ### Parameters #### Path Parameters - **dom** (*Domain) - Required - Domain with guest agent - **cmd** (string) - Required - Agent command (JSON) - **timeout** (int) - Required - Timeout in seconds (-2 for block, -1 for default) - **flags** (uint32) - Required - Reserved, pass 0 ### Response #### Success Response - **string** - Agent response (JSON) #### Throws - Error if agent unavailable or command fails ### Example ```go cmd := `{"execute":"guest-info"}` resp, err := libvirt.QEMUDomainAgentCommand(dom, cmd, -1, 0) if err == nil { fmt.Println("Agent response:", resp) } ``` ``` -------------------------------- ### Execute QEMU Monitor Command on Named Domain Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/07-qemu-lxc-modules.md Executes a QEMU monitor command on a domain identified by its name. This is an alternative to using a Domain object directly, useful when only the domain name is known. ```go func QEMUDomainMonitorCommand(conn *Connect, name string, cmd string, flags QEMUMonitorCommandFlags) (string, error) ``` -------------------------------- ### Set Memory with Options Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/02-domain.md Sets the memory allocation for the domain with additional options. ```go func (d *Domain) SetMemoryFlags(memory uint64, flags DomainMemoryModFlags) error ``` -------------------------------- ### Get Interface MAC Address Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Retrieves the MAC address of the network interface in standard string format. ```go func (i *Interface) GetMACString() (string, error) ``` -------------------------------- ### Network.GetUUIDString Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Gets the UUID of the network as a formatted string. Returns the UUID string or an error if unable to retrieve it. ```APIDOC ## Network.GetUUIDString ### Description Gets the UUID as a formatted string. ### Method * (n *Network) GetUUIDString() (string, error) ### Return * string - UUID in standard format ### Throws Error if unable to retrieve UUID string ``` -------------------------------- ### Network.GetName Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Gets the name of the network. Returns the network name as a string or an error if unable to retrieve the name. ```APIDOC ## Network.GetName ### Description Gets the name of the network. ### Method * (n *Network) GetName() (string, error) ### Return * string - Network name ### Throws Error if unable to retrieve name ``` -------------------------------- ### ListNodeDevices Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/01-connect.md Lists all node devices available on the system. ```APIDOC ## ListNodeDevices ### Description Lists all node devices. ### Method Not specified (likely a method on a Connect object) ### Endpoint Not specified ### Parameters #### Query Parameters - **flags** (uint32) - Required - Flags to filter the list of node devices. ``` -------------------------------- ### ListInterfaces Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/01-connect.md Lists all available network interfaces managed by libvirt. ```APIDOC ## ListInterfaces ### Description Lists all interfaces. ### Method Not specified (likely a method on a Connect object) ### Endpoint Not specified ### Parameters None ### Response #### Success Response - `[]string` - Interface names ``` -------------------------------- ### Get Network Name Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Retrieves the name of the virtual network. Useful for identifying networks by their human-readable name. ```go func (n *Network) GetName() (string, error) ``` -------------------------------- ### Get Domain UUID Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/02-domain.md Retrieves the UUID of the domain as a 16-byte array. Handles errors if the UUID is unavailable. ```go uuid, err := dom.GetUUID() if err == nil { fmt.Printf("UUID: %x\n", uuid) } ``` -------------------------------- ### Handle Read-Only Connection Errors Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/04-errors.md Demonstrates how to identify and handle errors that occur because the connection to libvirtd is read-only. This is crucial when attempting operations that require write access. ```go conn, _ := libvirt.NewConnectReadOnly("qemu:///system") err := dom.Create() // Requires write access if err != nil { libvirtErr, ok := err.(*libvirt.Error) if ok && libvirtErr.Code == libvirt.ERR_OPERATION_DENIED { fmt.Println("Read-only connection - connect with write access") // Reconnect with write access if needed } } ``` -------------------------------- ### Handling Specific Libvirt Errors Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/04-errors.md Demonstrates how to check for specific libvirt error codes, such as domain not found or connection loss, after an operation fails. ```go dom, err := conn.LookupDomainByName("nonexistent") if err != nil { libvirtErr, ok := err.(*libvirt.Error) if ok { switch libvirtErr.Code { case libvirt.ERR_NO_DOMAIN: fmt.Println("Domain not found") case libvirt.ERR_NO_CONNECT: fmt.Println("Connection lost") default: fmt.Printf("Unexpected error: %v\n", libvirtErr.Message) } } } ``` -------------------------------- ### IsUpdated Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/02-domain.md Checks if the domain's configuration has been updated since it was last started. Returns true if the configuration has changed. ```APIDOC ## IsUpdated ### Description Determines if domain definition was updated since last boot. ### Method func (d *Domain) IsUpdated() (bool, error) ### Return `bool` - True if domain config changed since start ``` -------------------------------- ### NewConnect Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/01-connect.md Establishes a new connection to a libvirt hypervisor using a connection URI. ```APIDOC ## NewConnect ### Description Establishes a new connection to a libvirt hypervisor. ### Method `func NewConnect(uri string) (*Connect, error)` ### Parameters #### Path Parameters - **uri** (string) - Required - Connection URI (e.g., "qemu:///system", "test:///default") ### Response #### Success Response - **Connect** (*Connect) - A new connection object. - **error** (error) - nil if connection succeeded. #### Error Response - **error** (error) - Error with code `ERR_NO_CONNECT` if unable to connect to hypervisor. ### Example ```go conn, err := libvirt.NewConnect("qemu:///system") if err != nil { log.Fatal(err) } defer conn.Close() ``` ``` -------------------------------- ### Get NetworkPort XML Description Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Retrieves the XML definition of the network port. Provides detailed configuration information. ```go func (n *NetworkPort) GetXMLDesc(flags uint32) (string, error) ``` -------------------------------- ### List Node Devices Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/01-connect.md Lists all available node devices. Returns a slice of device names. ```go func (c *Connect) ListNodeDevices(flags uint32) ([]string, error) ``` -------------------------------- ### List Libvirtd Servers Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/05-events-admin-stream.md Retrieves a list of all available libvirtd servers. Ensure flags are set to 0 as they are reserved. ```go func (c *AdmConnect) ListServers(flags uint32) ([]AdmServer, error) ``` -------------------------------- ### Get Domain Statistics Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/02-domain.md Retrieves statistics for a domain. Specify the types of statistics required and any relevant flags for collection. ```go func (d *Domain) GetStats(statTypes DomainStatsTypes, flags ConnectGetAllDomainStatsFlags) (*DomainStats, error) ``` -------------------------------- ### Get AdmClient ID Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/05-events-admin-stream.md Retrieves the unique identifier for a connected client. Returns a uint64 representing the client ID. ```go func (c *AdmClient) GetID() (uint64, error) ``` -------------------------------- ### Build with libvirt_dlopen Tag Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/07-qemu-lxc-modules.md Use this build tag to enable dynamic loading of the libvirt library. This allows the binary to work with different libvirt versions without rebuilding. ```bash go build -tags libvirt_dlopen ./ ... ``` -------------------------------- ### QEMUMonitorCommand Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/07-qemu-lxc-modules.md Executes a raw QEMU monitor command on a domain. This function allows direct interaction with the QEMU monitor for advanced control and information retrieval. ```APIDOC ## QEMUMonitorCommand ### Description Executes a raw QEMU monitor command on a domain. This function allows direct interaction with the QEMU monitor for advanced control and information retrieval. ### Method Go Function ### Parameters #### Path Parameters - **dom** (*Domain) - Required - Domain to query - **cmd** (string) - Required - QEMU monitor command - **flags** (QEMUMonitorCommandFlags) - Required - QEMU_MONITOR_COMMAND_* flags ### Response #### Success Response - **string** - Command output #### Throws - Error with code `ERR_NO_SUPPORT` if QEMU driver not available ### Example ```go output, err := libvirt.QEMUMonitorCommand(dom, "info status", 0) if err == nil { fmt.Println("Status:", output) } ``` ``` -------------------------------- ### AdmConnect.GetLoggingFilters Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/05-events-admin-stream.md Gets current daemon logging filters. Retrieves the active logging filter configuration from the libvirtd daemon. ```APIDOC ## AdmConnect.GetLoggingFilters ### Description Gets current daemon logging filters. Retrieves the active logging filter configuration from the libvirtd daemon. ### Method `(*AdmConnect) GetLoggingFilters(flags uint32)` ### Parameters #### Path Parameters - **flags** (uint32) - Required - Reserved, pass 0 ### Return - `string` - Logging filter expression ``` -------------------------------- ### NewConnectReadOnly Constructor Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/01-connect.md Opens a read-only connection to libvirt using a specified URI. ```go func NewConnectReadOnly(uri string) (*Connect, error) ``` -------------------------------- ### AdmConnect.GetURI Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/05-events-admin-stream.md Gets the URI of the admin connection. Retrieves the connection string used to establish the current admin session. ```APIDOC ## AdmConnect.GetURI ### Description Gets the URI of the admin connection. Retrieves the connection string used to establish the current admin session. ### Method `(*AdmConnect) GetURI()` ### Return - `string` - Admin connection URI ``` -------------------------------- ### QEMUDomainMonitorCommand Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/07-qemu-lxc-modules.md Executes a QEMU monitor command on a named domain. This function provides a way to send commands to a specific domain's monitor without needing a direct domain object. ```APIDOC ## QEMUDomainMonitorCommand ### Description Executes QEMU monitor command on a named domain. This function provides a way to send commands to a specific domain's monitor without needing a direct domain object. ### Method Go Function ### Parameters #### Path Parameters - **conn** (*Connect) - Required - Connection to hypervisor - **name** (string) - Required - Domain name - **cmd** (string) - Required - Monitor command - **flags** (QEMUMonitorCommandFlags) - Required - QEMU_MONITOR_COMMAND_* flags ### Response #### Success Response - **string** - Command output ``` -------------------------------- ### Migrate Domain to URI Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/02-domain.md Migrates a domain to a remote hypervisor specified by a URI. Configure migration options, an optional new domain name, and bandwidth limits. ```go func (d *Domain) MigrateToURI(uri string, flags DomainMigrateFlags, dname string, bandwidth uint64) error ``` -------------------------------- ### List All Node Devices with Flags Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/01-connect.md Lists all node devices that match the specified flags. Returns a slice of NodeDevice pointers. ```go func (c *Connect) ListAllNodeDevices(flags ConnectListAllNodeDeviceFlags) ([]*NodeDevice, error) ``` -------------------------------- ### Set Custom Libvirt Library Paths Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/07-qemu-lxc-modules.md Configure custom paths for libvirt library files during the build process using CGO_LDFLAGS and CGO_CFLAGS. ```bash # Set libvirt library paths if non-standard CGO_LDFLAGS="-L/custom/libvirt/lib" go build ./... CGO_CFLAGS="-I/custom/libvirt/include" go build ./... ``` -------------------------------- ### Lookup Libvirtd Server by Name Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/05-events-admin-stream.md Finds a specific libvirtd server instance by its name. Reserved flags should be set to 0. ```go func (c *AdmConnect) LookupServer(name string, flags uint32) (*AdmServer, error) ``` -------------------------------- ### Get Storage Pool Name Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Retrieves the name of the storage pool. This is a simple getter method for the pool's identifier. ```go func (sp *StoragePool) GetName() (string, error) ``` -------------------------------- ### Get NetworkPort UUID (String) Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Retrieves the UUID of the network port in a standard string format. Useful for identification and logging. ```go func (n *NetworkPort) GetUUIDString() (string, error) ``` -------------------------------- ### Use Batch Operations for Efficiency Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/00-index.md Utilize `ListAll*` methods for efficient data retrieval, performing a single API call. Avoid individual lookups which result in multiple API calls. ```go // Efficient: one API call domains, _ := conn.ListAllDomains(flags) // Inefficient: N API calls for name := range domainNames { conn.LookupDomainByName(name) } ``` -------------------------------- ### Get Network UUID (String) Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Retrieves the UUID of the network in a standard string format. Convenient for display or logging purposes. ```go func (n *Network) GetUUIDString() (string, error) ``` -------------------------------- ### Safe Resource Cleanup with defer Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/00-index.md Ensures resources are freed even if errors occur. Use defer immediately after successful resource acquisition. ```go resource, err := conn.Lookup...() if err != nil { return err } deferr resource.Free() // Always runs, even on error // Use resource ``` -------------------------------- ### Set Virtual CPU Configuration with Flags Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/02-domain.md Sets the vCPU configuration with specific options. Throws an error if the update fails. ```go func (d *Domain) SetVcpusFlags(count uint, flags DomainVcpuFlags) error ``` -------------------------------- ### Get All Domain Statistics Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/01-connect.md Retrieves statistics for all domains, filtered by the provided flags. Throws an error if stats collection fails. ```go func (c *Connect) GetAllDomainStats(flags ConnectGetAllDomainStatsFlags) ([]*DomainStats, error) ``` -------------------------------- ### Get Maximum Memory Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/02-domain.md Retrieves the maximum memory limit that can be configured for the domain in kilobytes. Returns the maximum memory size. ```go func (d *Domain) GetMaxMemory() (uint64, error) ``` -------------------------------- ### LXCContainerGetSecurityLabel Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/07-qemu-lxc-modules.md Gets the security label of the LXC container. This function retrieves the security label associated with a given LXC container. ```APIDOC ## LXCContainerGetSecurityLabel ### Description Gets the security label of the LXC container. This function retrieves the security label associated with a given LXC container. ### Method `LXCContainerGetSecurityLabel` ### Parameters #### Path Parameters - **dom** (*Domain) - yes - LXC container domain ### Response #### Success Response (200) - **string** - Security label value ``` -------------------------------- ### Connection Management Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/README.txt Provides methods for establishing connections to hypervisors, retrieving host system information, and managing connection lifecycles. Includes over 40 methods for hypervisor communication and 11 enumeration types for filtering. ```APIDOC ## Connect to Hypervisor ### Description Establishes a connection to a hypervisor using various connect types. ### Method Connect ### Endpoint N/A (SDK Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go // Example usage not provided in source ``` ### Response #### Success Response Connection object #### Response Example ```go // Example not provided in source ``` ## Host Information ### Description Retrieves detailed information about the host system, including CPU, memory, and NUMA configuration. ### Method NodeInfo ### Endpoint N/A (SDK Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go // Example usage not provided in source ``` ### Response #### Success Response NodeInfo structure containing CPU, memory, and NUMA details. #### Response Example ```go // Example not provided in source ``` ``` -------------------------------- ### Get Storage Pool Information Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Retrieves detailed information about the storage pool. This operation may throw an error if the information cannot be retrieved. ```go func (sp *StoragePool) GetInfo() (*StoragePoolInfo, error) ``` -------------------------------- ### Build Without QEMU Support Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/00-index.md Compile the module without QEMU support by using the 'libvirt_without_qemu' build tag. This can reduce binary size or dependencies. ```bash go build -tags libvirt_without_qemu ./... ``` -------------------------------- ### Build With Dynamic Linking Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/00-index.md Enable dynamic linking for libvirt by using the 'libvirt_dlopen' build tag. This can be useful for managing shared library dependencies. ```bash go build -tags libvirt_dlopen ./... ``` -------------------------------- ### Get Network UUID (Bytes) Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Retrieves the UUID of the network as a 16-byte array. Use this for precise identification or when byte-level operations are needed. ```go func (n *Network) GetUUID() ([]byte, error) ``` -------------------------------- ### List All Storage Pool Volumes (Objects) Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/03-network-storage-interface.md Lists all storage volumes in the pool, returning detailed objects for each. The flags parameter is reserved and should be passed as 0. ```go func (sp *StoragePool) ListAllVolumes(flags uint32) ([]*StorageVolume, error) ``` -------------------------------- ### Enter LXC Container Namespaces Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/07-qemu-lxc-modules.md Enters container namespaces directly. This function returns file descriptors for the current namespaces, which can be used to restore the original state. ```go func LXCEnterNamespace(dom *Domain, flags LXCOpenNamespaceFlags) ([]int, error) ``` -------------------------------- ### Get Memory Allocation Source: https://gitlab.com/libvirt/libvirt-go-module/-/blob/master/_autodocs/02-domain.md Retrieves the memory currently allocated to the domain in kilobytes. Returns the memory size or an error if unable to determine. ```go func (d *Domain) GetMemory() (uint64, error) ``` ```go mem, err := dom.GetMemory() if err == nil { fmt.Printf("Memory: %d MB\n", mem/1024) } ```