NAME
Sys::Virt - Represent and manage a libvirt hypervisor connection
SYNOPSIS
my $vmm = Sys::Virt->new(address => $addr);
my @domains = $vmm->list_domains();
foreach my $dom (@domains) {
print "Domain ", $dom->get_id, " ", $dom->get_name, "\n";
}
DESCRIPTION
The Sys::Virt module provides a Perl XS binding to the libvirt virtual machine management APIs. This allows machines running within arbitrary virtualization containers to be managed with a consistent API.
ERROR HANDLING
Any operations in the Sys::Virt API which have failure scenarios will result in an instance of the Sys::Virt::Error module being thrown. To catch these errors, simply wrap the method in an eval block. For details of the information contained in the error objects, consult the Sys::Virt::Error manual page.
METHODS
- my $vmm = Sys::Virt->new(uri => $uri, readonly => $ro);
-
Attach to the virtual machine monitor with the address of
address
. The uri parameter may be omitted, in which case the default connection made will be to the local Xen hypervisor. Some example URIs include:- xen:///
-
Xen on the local machine
- test:///default
-
Dummy "in memory" driver for test suites
- qemu:///system
-
System-wide driver for QEMU / KVM virtualization
- qemu:///session
-
Per-user driver for QEMU virtualization
- qemu+tls://somehost/system
-
System-wide QEMU driver on
somehost
using TLS security - xen+tcp://somehost/
-
Xen driver on
somehost
using TCP / SASL security
For further details consult
http://libvirt.org/uri.html
If the optional
readonly
parameter is supplied, then an unprivileged connection to the VMM will be attempted. If it is not supplied, then it defaults to making a fully privileged connection to the VMM. If the calling application is not running as root, it may be neccessary to provide authentication callbacks. - my $dom = $vmm->create_domain($xml);
-
Create a new domain based on the XML description passed into the
$xml
parameter. The returned object is an instance of the Sys::Virt::Domain class. This method is not available with unprivileged connections to the VMM. - my $dom = $vmm->define_domain($xml);
-
Defines, but does not start, a new domain based on the XML description passed into the
$xml
parameter. The returned object is an instance of the Sys::Virt::Domain class. This method is not available with unprivileged connections to the VMM. The define can be later started by calling thecreate
method on the returnedSys::Virt::Domain
object. - my $dom = $vmm->create_network($xml);
-
Create a new network based on the XML description passed into the
$xml
parameter. The returned object is an instance of the Sys::Virt::Network class. This method is not available with unprivileged connections to the VMM. - my $dom = $vmm->define_network($xml);
-
Defines, but does not start, a new network based on the XML description passed into the
$xml
parameter. The returned object is an instance of the Sys::Virt::Network class. This method is not available with unprivileged connections to the VMM. The define can be later started by calling thecreate
method on the returnedSys::Virt::Network
object. - my @doms = $vmm->list_domains()
-
Return a list of all domains currently known to the VMM. The elements in the returned list are instances of the Sys::Virt::Domain class.
- my $nids = $vmm->num_of_domains()
-
Return the number of running domains known to the VMM. This can be used as the
maxids
parameter tolist_domain_ids
. - my @domIDs = $vmm->list_domain_ids($maxids)
-
Return a list of all domain IDs currently known to the VMM. The IDs can be used with the
get_domain_by_id
method. - my @doms = $vmm->list_defined_domains()
-
Return a list of all domains defined, but not currently running, on the VMM. The elements in the returned list are instances of the Sys::Virt::Domain class.
- my $nids = $vmm->num_of_defined_domains()
-
Return the number of running domains known to the VMM. This can be used as the
maxnames
parameter tolist_defined_domain_names
. - my @doms = $vmm->list_defined_domain_names($maxnames)
-
Return a list of names of all domains defined, but not currently running, on the VMM. The names can be used with the
get_domain_by_name
method. - my $dom = $vmm->get_domain_by_name($name)
-
Return the domain with a name of
$name
. The returned object is an instance of the Sys::Virt::Domain class. - my @nets = $vmm->list_networks()
-
Return a list of all networks currently known to the VMM. The elements in the returned list are instances of the Sys::Virt::Network class.
- my $nnames = $vmm->num_of_networks()
-
Return the number of running networks known to the VMM. This can be used as the
maxids
parameter tolist_network_ids
. - my @netNames = $vmm->list_network_names($maxnames)
-
Return a list of all network IDs currently known to the VMM. The IDs can be used with the
get_network_by_id
method. - my @nets = $vmm->list_defined_networks()
-
Return a list of all networks defined, but not currently running, on the VMM. The elements in the returned list are instances of the Sys::Virt::Network class.
- my $nids = $vmm->num_of_defined_networks()
-
Return the number of running networks known to the VMM. This can be used as the
maxnames
parameter tolist_defined_network_names
. - my @doms = $vmm->list_defined_network_names($maxnames)
-
Return a list of names of all networks defined, but not currently running, on the VMM. The names can be used with the
get_network_by_name
method. - my $dom = $vmm->get_domain_by_name($name)
-
Return the domain with a name of
$name
. The returned object is an instance of the Sys::Virt::Domain class. - my $dom = $vmm->get_domain_by_id($id)
-
Return the domain with a local id of
$id
. The returned object is an instance of the Sys::Virt::Domain class. - my $dom = $vmm->get_domain_by_uuid($uuid)
-
Return the domain with a globally unique id of
$uuid
. The returned object is an instance of the Sys::Virt::Domain class. - my $dom = $vmm->get_network_by_name($name)
-
Return the network with a name of
$name
. The returned object is an instance of the Sys::Virt::Network class. - my $dom = $vmm->get_network_by_uuid($uuid)
-
Return the network with a globally unique id of
$uuid
. The returned object is an instance of the Sys::Virt::Network class. - $vmm->restore_domain($savefile)
-
Recreate a domain from the saved state file given in the
$savefile
parameter. - $vmm->get_max_vcpus($domtype)
-
Return the maximum number of vcpus that can be configured for a domain of type
$domtype
- $vmm->get_hostname()
-
Return the name of the host with which this connection is associated.
- my $type = $vmm->get_type()
-
Return the type of virtualization backend accessed by this VMM object. Currently the only supported type is
Xen
. - my $ver = $vmm->get_version()
-
Return the complete version number as a string encoded in the formula
(major * 1000000) + (minor * 1000) + micro
. - my $ver = $vmm->get_major_version
-
Return the major version number of the libvirt library.
- my $ver = $vmm->get_minor_version
-
Return the minor version number of the libvirt library.
- my $ver = $vmm->get_micro_version
-
Return the micro version number of the libvirt library.
- my $info = $con->get_node_info()
-
Returns a hash reference summarising the capabilities of the host node. The elements of the hash are as follows:
- memory
-
The amount of physical memory in the host
- model
-
The model of the CPU, eg x86_64
- cpus
-
The total number of logical CPUs
- mhz
-
The peak MHZ of the CPU
- nodes
-
The number of NUMA cells
- sockets
-
The number of CPU sockets
- cores
-
The number of cores per socket
- threads
-
The number of threads per core
- my $xml = $con->get_capabilities();
-
Returns an XML document describing the hypervisor capabilities
BUGS
Hopefully none, but the XS code needs to be audited to ensure it is not leaking memory.
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::Domain, Sys::Virt::Network, Sys::Virt::Error, http://libvirt.org