NAME

Sys::Virt::Domain - Represent & manage a libvirt guest domain

DESCRIPTION

The Sys::Virt::Domain module represents a guest domain managed by the virtual machine monitor.

METHODS

my $id = $dom->get_id()

Returns an integer with a locally unique identifier for the domain.

my $uuid = $dom->get_uuid()

Returns a 16 byte long string containing the raw globally unique identifier (UUID) for the domain.

my $uuid = $dom->get_uuid_string()

Returns a printable string representation of the raw UUID, in the format 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'.

my $name = $dom->get_name()

Returns a string with a locally unique name of the domain

my $xml = $dom->get_xml_description()

Returns an XML document containing a complete description of the domain's configuration

my $type = $dom->get_os_type()

Returns a string containing the name of the OS type running within the domain.

$dom->create()

Start a domain whose configuration was previously defined using the define_domain method in Sys::Virt.

$dom->undefine()

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.

$dom->suspend()

Temporarily stop execution of the domain, allowing later continuation by calling the resume method.

$dom->resume()

Resume execution of a domain previously halted with the suspend method.

$dom->save($filename)

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.

$dom->core_dump($filename)

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.

$dom->destroy()

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.

my $info = $dom->get_info()

Returns a hash reference summarising the execution state of the domain. The elements of the hash are as follows:

maxMem

The maximum memory allowed for this domain, in kilobytes

memory

The current memory allocated to the domain in kilobytes

cpuTime

The amount of CPU time used by the domain

nrVirtCpu

The current number of virtual CPUs enabled in the domain

state

The execution state of the machine, which will be one of the constants &Sys::Virt::Domain::STATE_*.

$dom->set_max_memory($mem)

Set the maximum memory for the domain to the value $mem. The value of the $mem parameter is specified in kilobytes.

$mem = $dom->get_max_memory()

Returns the current maximum memory allowed for this domain in kilobytes.

$dom->set_memory($mem)

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.

$dom->shutdown()

Request that the guest OS perform a graceful shutdown and poweroff.

$dom->reboot($flags)

Request that the guest OS perform a graceful shutdown and optionally restart. The $flags parameter determines how the domain restarts (if at all). It should be one of the constants &Sys::Virt::Domain::REBOOT_* listed later in this document.

$dom->get_max_vcpus()

Return the maximum number of vcpus that are configured for the domain

$dom->attach_device($xml)

Hotplug a new device whose configuration is given by $xml, to the running guest.

$dom->detach_device($xml)

Hotunplug a existing device whose configuration is given by $xml, from the running guest.

$data = $dom->block_peek($path, $offset, $size)

Peek into the guest disk $path, at byte $offset capturing $size bytes of data. The returned scalar may contain embedded NULLs.

$data = $dom->memory_peek($offset, $size)

Peek into the guest memory at byte $offset virtual address, capturing $size bytes of memory. The return scalar may contain embedded NULLs.

$flag = $dom->get_autostart();

Return a true value if the guest domain is configured to automatically start upon boot. Return false, otherwise

$dom->set_autostart($flag)

Set the state of the autostart flag, which determines whether the guest will automatically start upon boot of the host OS

$dom->set_vcpus($count)

Set the number of virtual CPUs in the guest VM to $count

$type = $dom->get_scheduler_type()

Return the scheduler type for the guest domain

%stats = $dom->block_stats($path)

Fetch the current I/O statistics for the block device given by $path. The returned hash containins keys for

my %params = $dom->get_scheduler_parameters()

Return the set of scheduler tunable parameters for the guest.

$dom->set_scheduler_parameters($params)

Update the set of scheduler tunable parameters. The value names for tunables vary, and can be discovered using the get_scheduler_params call

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

$dom->interface_stats($path)

Fetch the current I/O statistics for the block device given by $path. The returned hash containins keys for

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.

%info = $dom->get_security_label()

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.

$ddom = $dom->migrate(destcon, flags, dname, uri, bandwidth)

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 neccessary 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.

@vcpuinfo = $dom->get_vcpu_info()

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.

$dom->pin_vcpu($vcpu, $mask)

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.

CONSTANTS

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.

DOMAIN STATE

The domain state constants are useful in interpreting the state key in the hash returned by the get_info method.

Sys::Virt::Domain::STATE_NOSTATE

The domain is active, but is not running / blocked (eg idle)

Sys::Virt::Domain::STATE_RUNNING

The domain is active and running

Sys::Virt::Domain::STATE_BLOCKED

The domain is active, but execution is blocked

Sys::Virt::Domain::STATE_PAUSED

The domain is active, but execution has been paused

Sys::Virt::Domain::STATE_SHUTDOWN

The domain is active, but in the shutdown phase

Sys::Virt::Domain::STATE_SHUTOFF

The domain is inactive, and shut down.

Sys::Virt::Domain::STATE_CRASHED

The domain is inactive, and crashed.

MEMORY PEEK

The following constants can be used with the memory_peek method's flags parameter

Sys::Virt::Domain::MEMORY_VIRTUAL

Indicates that the offset is using virtual memory addressing.

VCPU STATE

The following constants are useful when interpreting the virtual CPU run state

Sys::Virt::Domain::VCPU_OFFLINE

The virtual CPU is not online

Sys::Virt::Domain::VCPU_RUNNING

The virtual CPU is executing code

Sys::Virt::Domain::VCPU_BLOCKED

The virtual CPU is waiting to be scheduled

XML DUMP OPTIONS

The following constants are used to control the information included in the XML configuration dump

Sys::Virt::Domain::XML_INACTIVE

Report the persistent inactive configuration for the guest, even if it is currently running.

Sys::Virt::Domain::XML_SECURE

Include security sensitive information in the XML dump, such as passwords.

MIGRATE OPTIONS

The following constants are used to control how migration is performed

Sys::Virt::Domain::MIGRATE_LIVE

Migrate the guest without interrupting its execution on the source host.

STATE CHANGE EVENTS

The following constants allow domain state change events to be interpreted. The events contain both a state change, and a reason.

Sys::Virt::Domain::EVENT_DEFINED

Indicates that a persistent configuration has been defined for the domain.

Sys::Virt::Domain::EVENT_DEFINED_ADDED

The defined configuration is newly added

Sys::Virt::Domain::EVENT_DEFINED_UPDATED

The defined configuration is an update to an existing configuration

Sys::Virt::Domain::EVENT_RESUMED

The domain has resumed execution

Sys::Virt::Domain::EVENT_RESUMED_MIGRATED

The domain resumed because migration has completed. This is emitted on the destination host.

Sys::Virt::Domain::EVENT_RESUMED_UNPAUSED

The domain resumed because the admin unpaused it.

Sys::Virt::Domain::EVENT_STARTED

The domain has started running

Sys::Virt::Domain::EVENT_STARTED_BOOTED

The domain was booted from shutoff state

Sys::Virt::Domain::EVENT_STARTED_MIGRATED

The domain started due to an incoming migration

Sys::Virt::Domain::EVENT_STARTED_RESTORED

The domain was restored from saved state file

Sys::Virt::Domain::EVENT_STOPPED

The domain has stopped running

Sys::Virt::Domain::EVENT_STOPPED_CRASHED

The domain stopped because guest operating system has crashed

Sys::Virt::Domain::EVENT_STOPPED_DESTROYED

The domain stopped because administrator issued a destroy command.

Sys::Virt::Domain::EVENT_STOPPED_FAILED

The domain stopped because of a fault in the host virtualization environment.

Sys::Virt::Domain::EVENT_STOPPED_MIGRATED

The domain stopped because it was migrated to another machine.

Sys::Virt::Domain::EVENT_STOPPED_SAVED

The domain was saved to a state file

Sys::Virt::Domain::EVENT_STOPPED_SHUTDOWN

The domain stopped due to graceful shutdown of the guest.

Sys::Virt::Domain::EVENT_SUSPENDED

The domain has stopped executing, but still exists

Sys::Virt::Domain::EVENT_SUSPENDED_MIGRATED

The domain has been suspended due to offline migration

Sys::Virt::Domain::EVENT_SUSPENDED_PAUSED

The domain has been suspended due to administrator pause request.

Sys::Virt::Domain::EVENT_UNDEFINED

The persistent configuration has gone away

Sys::Virt::Domain::EVENT_UNDEFINED_REMOVED

The domain configuration has gone away due to it being removed by administrator.

AUTHORS

Daniel P. Berrange <berrange@redhat.com>

COPYRIGHT

Copyright (C) 2006 Red Hat Copyright (C) 2006-2007 Daniel P. Berrange

LICENSE

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.

SEE ALSO

Sys::Virt, Sys::Virt::Error, http://libvirt.org