Sys::Virt::Domain - Represent & manage a libvirt guest domain
The Sys::Virt::Domain module represents a guest domain managed by the virtual machine monitor.
Sys::Virt::Domain
Returns an integer with a locally unique identifier for the domain.
Returns a 16 byte long string containing the raw globally unique identifier (UUID) for the domain.
Returns a printable string representation of the raw UUID, in the format 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'.
Returns a string with a locally unique name of the domain
Returns a true value if the domain is currently running
Returns a true value if the domain has a persistent configuration file defined
Returns a true value if the domain is running and has a persistent configuration file defined that is out of date compared to the current live config.
Returns an XML document containing a complete description of the domain's configuration
Returns a string containing the name of the OS type running within the domain.
Start a domain whose configuration was previously defined using the define_domain method in Sys::Virt. The $flags parameter accepts one of the DOMAIN CREATION constants documented later, and defaults to 0 if omitted.
define_domain
$flags
Remove the configuration associated with a domain previously defined with the define_domain method in Sys::Virt. If the domain is running, you probably want to use the shutdown or destroy methods instead.
shutdown
destroy
Temporarily stop execution of the domain, allowing later continuation by calling the resume method.
resume
Resume execution of a domain previously halted with the suspend method.
suspend
Take a snapshot of the domain's state and save the information to the file named in the $filename parameter. The domain can later be restored from this file with the restore_domain method on the Sys::Virt object.
$filename
restore_domain
Take a snapshot of the domain's state and save the information to a managed save location. The domain will be automatically restored with this state when it is next started. The $flags parameter is unused and defaults to zero.
Return a non-zero value if the domain has a managed save image that will be used at next start. The $flags parameter is unused and defaults to zero.
Remove the current managed save image, causing the guest to perform a full boot next time it is started. The $flags parameter is unused and defaults to zero.
Trigger a core dump of the guest virtual machine, saving its memory image to $filename so it can be analysed by tools such as crash. The optional $flags flags parameter is currently unused and if omitted will default to 0.
crash
Immediately terminate the machine, and remove it from the virtual machine monitor. The $dom handle is invalid after this call completes and should not be used again.
$dom
Returns a hash reference summarising the execution state of the domain. The elements of the hash are as follows:
The maximum memory allowed for this domain, in kilobytes
The current memory allocated to the domain in kilobytes
The amount of CPU time used by the domain
The current number of virtual CPUs enabled in the domain
The execution state of the machine, which will be one of the constants &Sys::Virt::Domain::STATE_*.
Returns a hash reference summarising the disk usage of the host backing store for a guest block device. The $dev parameter should be the path to the backing store on the host. $flags is currently unused and defaults to 0 if omitted. The returned hash contains the following elements
$dev
Logical size in bytes of the block device backing image *
Highest allocated extent in bytes of the block device backing image
Physical size in bytes of the container of the backing image
Set the maximum memory for the domain to the value $mem. The value of the $mem parameter is specified in kilobytes.
$mem
Returns the current maximum memory allowed for this domain in kilobytes.
Set the current memory for the domain to the value $mem. The value of the $mem parameter is specified in kilobytes. This must be less than, or equal to the domain's max memory limit.
Request that the guest OS perform a graceful shutdown and poweroff.
Request that the guest OS perform a graceful shutdown and optionally restart. The optional $flags parameter is currently unused and if omitted defaults to zero.
Return the maximum number of vcpus that are configured for the domain
Hotplug a new device whose configuration is given by $xml, to the running guest. The optional <$flags> parameter defaults to 0, but can accept one of the device hotplug flags described later.
$xml
Hotunplug a existing device whose configuration is given by $xml, from the running guest. The optional <$flags> parameter defaults to 0, but can accept one of the device hotplug flags described later.
Update the configuration of an existing device. The new configuration is given by $xml. The optional <$flags> parameter defaults to 0 but can accept one of the device hotplug flags described later.
Peek into the guest disk $path, at byte $offset capturing $size bytes of data. The returned scalar may contain embedded NULLs. The optional $flags parameter is currently unused and if omitted defaults to zero.
$path
$offset
$size
Peek into the guest memory at byte $offset virtual address, capturing $size bytes of memory. The return scalar may contain embedded NULLs. The optional $flags parameter is currently unused and if omitted defaults to zero.
Return a true value if the guest domain is configured to automatically start upon boot. Return false, otherwise
Set the state of the autostart flag, which determines whether the guest will automatically start upon boot of the host OS
Set the number of virtual CPUs in the guest VM to $count. The optional $flags parameter can be used to control whether the setting changes the live config or inactive config.
$count
Get the number of virtual CPUs in the guest VM. The optional $flags parameter can be used to control whether to query the setting of the live config or inactive config.
Return the scheduler type for the guest domain
Fetch the current I/O statistics for the block device given by $path. The returned hash containins keys for
Return the set of scheduler tunable parameters for the guest.
Update the set of scheduler tunable parameters. The value names for tunables vary, and can be discovered using the get_scheduler_params call
get_scheduler_params
Return a hash reference containing the set of memory tunable parameters for the guest. The keys in the hash are one of the constants MEMORY PARAMETERS described later.
Update the memory tunable parameters for the guest. The $params should be a hash reference whose keys are one of the MEMORY PARAMETERS constants.
$params
rd_req
Number of read requests
rd_bytes
Number of bytes read
wr_req
Number of write requests
wr_bytes
Number of bytes written
errs
Some kind of error count
rx_bytes
Total bytes received
rx_packets
Total packets received
rx_errs
Total packets received with errors
rx_drop
Total packets drop at reception
tx_bytes
Total bytes transmitted
tx_packets
Total packets transmitted
tx_errs
Total packets transmitted with errors
tx_drop
Total packets dropped at transmission.
Fetch the current memory statistics for the guest domain. The $flags parameter is currently unused and can be omitted. The returned hash containins keys for
swap_in
Data read from swap space
swap_out
Data written to swap space
major_fault
Page fault involving disk I/O
minor_fault
Page fault not involving disk I/O
unused
Memory not used by the system
available
Total memory seen by guest
Fetch information about the security label assigned to the guest domain. The returned hash has two keys, model gives the name of the security model in effect (eg selinux), while label provides the name of the security label applied to the domain.
model
selinux
label
Migrate a domain to an alternative host. The destcon parameter should be a Sys::Virt connection to the remote target host. If the flags parameter is zero offline migration will be performed. The Sys::Virt::Domain::MIGRATE_LIVE constant can be used to request live migration. The dname parameter allows the guest to be renamed on the target host, if set to undef, the domains' current name will be maintained. In normal circumstances, the source host determines the target hostname from the URI associated with the destcon connection. If the destination host is multi-homed it may be necessary to supply an alternate destination hostame via the uri parameter. The bandwidth parameter allows network usage to be throttled during migration. If set to zero, no throttling will be performed. The flags, dname, uri and bandwidth parameters are all optional, and if omitted default to zero, undef, undef, and zero respectively.
destcon
Sys::Virt
flags
Sys::Virt::Domain::MIGRATE_LIVE
dname
undef
uri
bandwidth
Migrate a domain to an alternative host. The destri parameter should be a valid libvirt connection URI for the remote target host. If the flags parameter is zero offline migration will be performed. The Sys::Virt::Domain::MIGRATE_LIVE constant can be used to request live migration. The dname parameter allows the guest to be renamed on the target host, if set to undef, the domains' current name will be maintained. In normal circumstances, the source host determines the target hostname from the URI associated with the destcon connection. If the destination host is multi-homed it may be necessary to supply an alternate destination hostame via the uri parameter. The bandwidth parameter allows network usage to be throttled during migration. If set to zero, no throttling will be performed. The flags, dname and bandwidth parameters are all optional, and if omitted default to zero, undef, undef, and zero respectively.
destri
Set the maximum allowed downtime during migration of the guest. A longer downtime makes it more likely that migration will complete, at the cost of longer time blackout for the guest OS at the switch over point. The downtime parameter is measured in milliseconds. The $flags parameter is currently unused and defaults to zero.
downtime
Obtain information about the state of all virtual CPUs in a running guest domain. The returned list will have one element for each vCPU, where each elements contains a hash reference. The keys in the hash are, number the vCPU number, cpu the physical CPU on which the vCPU is currently scheduled, cpuTime the cummulative execution time of the vCPU, state the running state and affinity giving the allowed shedular placement. The value for affinity is a string representing a bitmask against physical CPUs, 8 cpus per character.
number
cpu
cpuTime
state
affinity
Ping the virtual CPU given by index $vcpu to physical CPUs given by $mask. The $mask is a string representing a bitmask against physical CPUs, 8 cpus per character.
$vcpu
$mask
Returns a hash reference summarising the execution state of the background job. The elements of the hash are as follows:
Aborts the currently executing job
Return the number of saved snapshots of the domain
List the names of all saved snapshots. The names can be used with the lookup_snapshot_by_name
lookup_snapshot_by_name
Return a list of all snapshots currently known to the domain. The elements in the returned list are instances of the Sys::Virt::DomainSnapshot class.
Returns a true value if the domain has a currently active snapshot
Returns the currently active snapshot for the domain.
The type of job, one of the JOB TYPE constants listed later in this document.
The elapsed time in milliseconds
The expected remaining time in milliseconds. Only set if the type is JOB_UNBOUNDED.
type
The total amount of data expected to be processed by the job, in bytes.
The current amount of data processed by the job, in bytes.
The expected amount of data remaining to be processed by the job, in bytes.
The total amount of mem expected to be processed by the job, in bytes.
The current amount of mem processed by the job, in bytes.
The expected amount of mem remaining to be processed by the job, in bytes.
The total amount of file expected to be processed by the job, in bytes.
The current amount of file processed by the job, in bytes.
The expected amount of file remaining to be processed by the job, in bytes.
A number of the APIs take a flags parameter. In most cases passing a value of zero will be satisfactory. Some APIs, however, accept named constants to alter their behaviour. This section documents the current known constants.
The domain state constants are useful in interpreting the state key in the hash returned by the get_info method.
get_info
The domain is active, but is not running / blocked (eg idle)
The domain is active and running
The domain is active, but execution is blocked
The domain is active, but execution has been paused
The domain is active, but in the shutdown phase
The domain is inactive, and shut down.
The domain is inactive, and crashed.
The following constants can be used to control the behaviour of domain creation
Keep the guest vCPUs paused after starting the guest
The following constants can be used with the memory_peek method's flags parameter
memory_peek
Indicates that the offset is using virtual memory addressing.
The following constants are useful when interpreting the virtual CPU run state
The virtual CPU is not online
The virtual CPU is executing code
The virtual CPU is waiting to be scheduled
The following constants are used to control the information included in the XML configuration dump
Report the persistent inactive configuration for the guest, even if it is currently running.
Include security sensitive information in the XML dump, such as passwords.
The following constants are used to control device hotplug operations
Modify the domain in its current state
Modify only the live state of the domain
Modify only the persistent config of the domain
The following constants are used to control how migration is performed
Migrate the guest without interrupting its execution on the source host.
Manage the migration process over a direct peer-2-peer connection between the source and destination host libvirtd daemons.
Tunnel the migration data over the libvirt daemon connection, rather than the native hypervisor data transport. Requires PEER2PEER flag to be set.
Make the domain persistent on the destination host, defining its configuration file upon completion of migration.
Remove the domain's persistent configuration after migration completes successfully.
Do not re-start execution of the guest CPUs on the destination host after migration completes.
The following constants describe the different background job types.
No job is active
A job with a finite completion time is active
A job with an unbounded completion time is active
The job has finished, but isn't cleaned up
The job has hit an error, but isn't cleaned up
The job was aborted at user request, but isn't cleaned up
The following constants are useful when getting/setting memory parameters for guests
The maximum memory the guest can use.
The memory upper limit enforced during memory contention.
The minimum memory guaranteed to be reserved for the guest.
The maximum swap the guest can use.
The value of an unlimited memory parameter
The following constants are useful when getting/setting the VCPU count for a guest
Flag to request the live value
Flag to request the persistent config value
The following constants allow domain state change events to be interpreted. The events contain both a state change, and a reason.
Indicates that a persistent configuration has been defined for the domain.
The defined configuration is newly added
The defined configuration is an update to an existing configuration
The domain has resumed execution
The domain resumed because migration has completed. This is emitted on the destination host.
The domain resumed because the admin unpaused it.
The domain has started running
The domain was booted from shutoff state
The domain started due to an incoming migration
The domain was restored from saved state file
The domain has stopped running
The domain stopped because guest operating system has crashed
The domain stopped because administrator issued a destroy command.
The domain stopped because of a fault in the host virtualization environment.
The domain stopped because it was migrated to another machine.
The domain was saved to a state file
The domain stopped due to graceful shutdown of the guest.
The domain has stopped executing, but still exists
The domain has been suspended due to offline migration
The domain has been suspended due to administrator pause request.
The persistent configuration has gone away
The domain configuration has gone away due to it being removed by administrator.
Domain lifecycle events
Soft / warm reboot events
RTC clock adjustments
File IO errors, typically from disks
Watchdog device triggering
Graphics client connections.
File IO errors, typically from disks, with a root cause
These constants describe what action was taken due to the IO error.
No action was taken, the error was ignored & reported as success to guest
The guest is paused since the error occurred
The error has been reported to the guest OS
These constants describe what action was taken due to the watchdog firing
No action was taken, the watchdog was ignored
The guest is paused since the watchdog fired
The guest is powered off after the watchdog fired
The guest is reset after the watchdog fired
The guest attempted to gracefully shutdown after the watchdog fired
No action was taken, the watchdog was logged
These constants describe the phase of the graphics connection
The initial client connection
The client has been authenticated & the connection is running
The client has disconnected
These constants describe the format of the address
An IPv4 address
An IPv6 address
Daniel P. Berrange <berrange@redhat.com>
Copyright (C) 2006 Red Hat Copyright (C) 2006-2007 Daniel P. Berrange
This program is free software; you can redistribute it and/or modify it under the terms of either the GNU General Public License as published by the Free Software Foundation (either version 2 of the License, or at your option any later version), or, the Artistic License, as specified in the Perl README file.
Sys::Virt, Sys::Virt::Error, http://libvirt.org
http://libvirt.org
To install Sys::Virt, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Sys::Virt
CPAN shell
perl -MCPAN -e shell install Sys::Virt
For more information on module installation, please visit the detailed CPAN module installation guide.