Thank you for your friends to support this blog, welcome to discuss the exchange, due to limited capacity and time, mistakes are unavoidable, please correct me!
If reproduced, please retain the author's information.
Blog Address: http://blog.csdn.net/qq_21398167
Original post address: http://blog.csdn.net/qq_21398167/article/details/46422583
Http://libvirt.org/html/index.html website contains all the APIs
API Overview
The Advanced Libvirt API can be divided into 5 API parts: Hypervisor connection API, domain API, network API, storage volume API, and storage pool API.
Creating a connection for a given hypervisor generates all LIBVIRT traffic (for example, the open call shown in Listing 6). This connection provides the path for all other APIs to be used. In the C API, this behavior is provided through Virconnectopen calls (and other authentication calls). The return value of these functions is a Virconnectptr object that represents a connection to the hypervisor. This object serves as the basis for all other administrative functions and is necessary for a given hypervisor to make concurrent API calls. Important concurrent calls are virconnectgetcapabilities and Virnodegetinfo, which return the functionality of the hypervisor and driver, which gets information about the node. This information is returned as an XML document, so that you can understand the behavior that might occur by parsing.
After you enter the hypervisor, you can reuse the various resources on the hypervisor using a set of API call functions. The Virconnectlistdomains API call function returns a list of domain identifiers that represent the active domain on the hypervisor.
The API implements a large number of domain-specific functions. To explore or manage a domain, you first need a Virdomainptr object. There are several ways you can get the handle (using ID, UUID, or domain name). To continue with the example of a repeating field, you can use the index table returned by the function and call Virdomainlookupbyid to get the domain handle. With this domain handle, you can do a lot of things, from exploring domains (Virdomaingetuuid, Virdomaingetinfo, Virdomaingetxmldesc, Virdomainmemorypeek) to the control domain (virdomaincreate, virdomainsuspend, Virdomainresume, Virdomaindestroy, and VirDomainMigrate).
You can also use the API to manage and examine virtual networks and storage resources. Once the API model is established, a Virnetworkptr object is required to manage and examine the virtual network, and a virstoragepoolptr (storage pool) or virstoragevolptr (volume) object is required to manage these resources.
The API also supports an event mechanism that you can use to register to be notified when a particular event occurs, such as when a domain is started, aborted, resumed, or stopped.
(1) Connect Hypervisor related APIs: A series of functions starting with virconnect.
Virtual machine management operations can only be performed after a connection has been established with Hypervisor, so the API to connect Hypervisor is a precondition for all other APIs to use. The connection established with Hypervisor provides a path for the execution of other APIs and is the basis for other virtualization management functions.
The Virconnectopen function can establish a connection whose return value is a Virconnectptr object that represents a connection to hypervisor, and a null value (NULL) if the connection is faulted.
The Virconnectopenreadonly function establishes a read-only connection that allows you to use some of the functionality of the query without creating, modifying, and so on.
The Virconnectopenauth function provides a more authentication-established connection.
The Virconnectgetcapabilities function is an XML-formatted string that returns a description of the Hypervisor and driver functionality. The Virconnectlistdomains function returns a list of field identifiers that represent the active domain on the Hypervisor.
Virconnectgethostname
Virconnectgetmaxvcpus
Virconnectgettype
Virconnectgetversion
Virconnectgetlibversion
Virconnectgeturi
virconnectisencrypted
Virconnectissecure
Virconnectclose Closing the connection
(2) domain-managed API: A series of functions that begin with Virdomain.
Virtual machine management, the most basic function is the management of the domain on each node, so Libvirt API implemented a lot of domain management functions. To manage a domain, you first need to get the Virdomainptr domain object before you can manipulate the domain. There are many ways to get domain objects, such as Virdomainptr
The Virdomainlookupbyid (virconnectptr conn, int id) function finds the appropriate domain based on the ID value of the domain to conn this connection. , Virdomainlookupbyname, Virdomainlookupbyuuid, and so on, respectively, according to the name and UUID of the domain to find the corresponding domain. After you get the object for a domain, you can do a lot of things, which can be the information of the query domain
Virdomaingethostname
Virdomaingetinfo
Virdomaingetvcpus
Virdomaingetvcpusflags
Virdomaingetcpustats
It can also be the life cycle of the control domain, such as:
Virdomaincreate
Virdomainsuspend
Virdomainresume
Virdomaindestroy
Virdomainmigrate
Create a virtual machine
Virdomaindefinexml ()
Virfilereadall () The function prototype is intvirfilereadall (const char *path, int maxlen, char **buf), the function is to read the file contents of the path specified by the parameter "path" into a buffer, The buffer address is recorded in the parameter "*buf", and the parameter "MaxLen" specifies the maximum length of the file. With this API, we can put the XML configuration file into a buffer to facilitate the next use
Virdomaincreatexml () The function prototype is Virdomainptr virdomaincreatexml (virconnectptrconn, const char * xmldesc, unsigned i NT flags), a function that creates a domain and returns a pointer to the domain according to the configuration defined by the parameter "Xmldesc". The parameter "conn" is a pointer to the virtual Machine Manager, and by setting a different "flags" flag, you can make the created domain have different properties.
(3) node-managed API: A series of functions that begin with Virnode.
The domain is run on the physical node, Libvirt also provides the function of querying and controlling the information of the node. Most functions of node management need to use a connection Hypervisor object as one of the incoming parameters, so that information can be queried or modified to the nodes on that connection.
The Virnodegetinfo function is the physical hardware information that gets the node, http://my.oschina.net/u/274153/blog/55011
The Virnodegetcpustats function can get usage statistics for each CPU on a node
The Virnodegetmemorystats function can get usage statistics for memory on a node
The Virnodegetfreememory function can get the free memory size available on the node. There are also functions that set or control the node Virnodesetmemoryparameters function to set parameters for memory scheduling on a node
The Virnodesuspendforduration function allows a node (host) to pause for a period of time
Virnodegetcellsfreememory
(4) network management API: A series of functions beginning with virnetwork and some functions beginning with virinterface.
Libvirt also provides a rich API for network management in virtualized environments. Libvirt first needs to create a Virnetworkptr object before you can query or control the virtual network. Some functions that query network-related information, such as:
Virnetworkgetname (Virnetworkptr Network) function to get the name of the net
Network:a Network Object
Returns:a Pointer to the name or NULL, the string need not is deallocated its lifetime would be is the same as the network Object.
The Virnetworkgetbridgename function can get the name of the bridge in the network
Virnetworkgetuuid function to get the UUID identifier of the network
The VIRNETWORKGETXMLDESC function can obtain the network's descriptive information in XML format.
The Virnetworkisactive function can query whether the network is in use. Some of the functions that control or change network settings are:
int virnetworkcreate (VIRNETWORKPTR network) Get the Network property
Virnetworkcreatexml (virconnectptr conn,const char * xmldesc) function can create a network (return Virnetworkptr object) based on the supplied XML-formatted string
Conn:pointer to the hypervisor connection
Xmldesc:an XML Description of the network
RETURNS:A new Network object or NULL in case of failure
Virdomaininterfaceptr
The Virnetworkdestroy function destroys a network (and also shuts down domains that use that network)
The Virnetworkfree function can reclaim a network (but does not close the running domain)
The Virnetworkupdate function updates an existing network based on the network configuration provided in the XML format. Other than that
Virinterfacecreate,
Virinterfacefree,
Virinterfacedestroy,
Virinterfacegetname,
Functions such as virinterfaceisactive can be used to create, release, and destroy network interfaces, as well as to query the name and activation status of network interfaces.
(5) Storage volume Management API: A series of functions beginning with Virstoragevol.
Libvirt management of the storage volume (volume), mainly the management of the image files of the domain, which may be raw, qcow2, VMDK, QED and other formats. Libvirt management of a storage volume, you first need to create an object that virstoragevolptr this storage volume before you can query or control it. Libvirt provides 3 functions to obtain a storage volume object in different ways, such as:
The Virstoragevollookupbykey function can obtain a storage volume object based on globally unique key values
The Virstoragevollookupbyname function can get a storage volume object in a storage resource pool (storage pool) by name Virstoragevollookupbypath The function can fetch a storage volume object based on its path on the node. Some functions are used to query information about a stored volume, such as: The Virstoragevolgetinfo function can query the usage of a storage volume
The Virstoragevolgetname function can get the name of the storage volume
The Virstoragevolgetpath function can get the path to the storage volume
The Virstoragevolgetconnect function can query the connection of a storage volume. Some functions are used to create and modify storage volumes, such as:
The Virstoragevolcreatexml function can create a storage volume based on the XML description provided
The Virstoragevolfree function frees the handle to the storage volume (but the storage volume still exists)
The Virstoragevoldelete function can delete a storage volume, and the Virstoragevolresize function can resize the storage volume.
(6) Storage pool Management API: A series of functions that begin with Virstoragepool.
Libvirt Management of storage pools (pool), including local basic file system, common network shared file system, iSCSI shared file system, LVM partition, etc. Libvirt needs to be based on the VIRSTORAGEPOOLPTR storage pool object for query and control operations. Some functions can obtain a storage pool object through a query, such as:
The Virstoragepoollookupbyname function can obtain a storage pool object based on the name of the storage pool
Virstoragepoollookupbyvolume can return its corresponding storage pool object based on a storage volume
The Virstoragepoolcreatexml function can create a storage pool based on the XML description (which is activated by default)
The Virstoragepooldefinexml function can statically define a storage pool based on the XML description information (not yet activated)
The Virstoragepoolcreate function can activate a storage pool.
Virstoragepoolgetinfo,
Virstoragepoolgetname,
The Virstoragepoolgetuuid function can obtain the information, name, and UUID identifier of the storage pool, respectively.
The Virstoragepoolisactive function can query whether the storage pool is in use state.
The Virstoragepoolfree function frees storage pool-related memory (but does not change its state in the host)
The Virstoragepooldestroy function can be used to destroy a storage pool (but does not release the Virstoragepoolptr object and can then reactivate it with the Virstoragepoolcreate function).
The Virstoragepooldelete function can physically delete a storage pool resource (the operation is not recoverable).
(7) API for event management: A series of functions beginning with virevent.
Libvirt supports an event mechanism that, when registered with this mechanism, can receive some of its own defined notifications when specific events occur, such as the start, pause, resume, and stop of a domain.
(8) API for Data Flow Management: A series of functions beginning with Virstream.
Libvirt also provides a series of functions for the transmission of data streams.
(9) Error handing
Virseterrorfunc
Virconnseterrorfunc
Vircopylasterror
Virgetlasterror
Virsavelasterror
Virreseterror
Virfreeerror
Virconnreseterror
Virconncopylasterror
Virconngetlasterror
Virdomainmigrate Virtual Machine Migration
Virdomainreboot Virtual Machine Restart
int virdomainref (virdomainptr domain)
int Virdomainreset (virdomainptr domain,
unsigned int flags)
int Virdomainrestore (Virconnectptr conn,
const char * from)
int Virdomainrestoreflags (Virconnectptr conn,
const char * from,
const char * dxml,
(go) Libvirt Section API Introduction