libvirt

libvirt - core interfaces for the libvirt library

Provides the interfaces of the libvirt library to handle Xen domains from a process running in domain 0

Author(s): Daniel Veillard <veillard@redhat.com>

Synopsis

#define LIBVIR_VERSION_NUMBER;
typedef virNodeInfo * virNodeInfoPtr;
typedef virDomainInfo * virDomainInfoPtr;
typedef virDomainKernel * virDomainKernelPtr;
typedef virConnect * virConnectPtr;
typedef struct _virDomainKernel virDomainKernel;
typedef struct _virNodeInfo virNodeInfo;
typedef enum virDomainState;
typedef enum virDeviceMode;
typedef struct _virDomain virDomain;
typedef virDomain * virDomainPtr;
typedef enum virDomainRestart;
typedef struct _virConnect virConnect;
typedef enum virDomainCreateFlags;
typedef struct _virDomainInfo virDomainInfo;
int	virDomainGetInfo		(virDomainPtr domain, 
virDomainInfoPtr info); int virDomainShutdown (virDomainPtr domain); int virGetVersion (unsigned long * libVer,
const char * type,
unsigned long * typeVer); virDomainPtr virDomainLookupByName (virConnectPtr conn,
const char * name); int virDomainRestore (virConnectPtr conn,
const char * from); const char * virConnectGetType (virConnectPtr conn); int virDomainSave (virDomainPtr domain,
const char * to); int virConnectListDomains (virConnectPtr conn,
int * ids,
int maxids); virDomainPtr virDomainLookupByUUID (virConnectPtr conn,
const unsigned char * uuid); virDomainPtr virDomainLookupByID (virConnectPtr conn,
int id); char * virDomainGetOSType (virDomainPtr domain); int virNodeGetInfo (virConnectPtr conn,
virNodeInfoPtr info); int virDomainGetUUID (virDomainPtr domain,
unsigned char * uuid); int virConnectNumOfDomains (virConnectPtr conn); int virDomainSetMaxMemory (virDomainPtr domain,
unsigned long memory); unsigned long virDomainGetMaxMemory (virDomainPtr domain); int virConnectGetVersion (virConnectPtr conn,
unsigned long * hvVer); int virDomainFree (virDomainPtr domain); virConnectPtr virConnectOpen (const char * name); int virDomainSuspend (virDomainPtr domain); int virConnectClose (virConnectPtr conn); int virDomainReboot (virDomainPtr domain,
unsigned int flags); int virInitialize (void); unsigned int virDomainGetID (virDomainPtr domain); int virDomainResume (virDomainPtr domain); virDomainPtr virDomainCreateLinux (virConnectPtr conn,
const char * xmlDesc,
unsigned int flags); int virDomainSetMemory (virDomainPtr domain,
unsigned long memory); int virDomainDestroy (virDomainPtr domain); char * virDomainGetXMLDesc (virDomainPtr domain,
int flags); const char * virDomainGetName (virDomainPtr domain); virConnectPtr virConnectOpenReadOnly (const char * name);

Description

Details

Macro LIBVIR_VERSION_NUMBER

#define LIBVIR_VERSION_NUMBER;

Macro providing the version of the library as version * 1,000,000 + minor * 1000 + micro


Structure virConnect

struct _virConnect {
The content of this structure is not made public by the API.
} virConnect;


Typedef virConnectPtr

virConnect * virConnectPtr;

a virConnectPtr is pointer to a virConnect private structure, this is the type used to reference a connection to the Xen Hypervisor in the API.


Enum virDeviceMode

enum virDeviceMode {
    VIR_DEVICE_DEFAULT = 0 /* Default mode */
    VIR_DEVICE_RO = 1 /* Access read-only */
    VIR_DEVICE_RW = 2 /* Access read-write */
    VIR_DEVICE_RW_FORCE = 3 /*  Forced read-write even if already used */
};


Structure virDomain

struct _virDomain {
The content of this structure is not made public by the API.
} virDomain;


Enum virDomainCreateFlags

enum virDomainCreateFlags {
    VIR_DOMAIN_NONE = 0
};


Structure virDomainInfo

struct _virDomainInfo {
    unsigned char	state	: the running state, one of virDomainFlags
    unsigned long	maxMem	: the maximum memory in KBytes allowed
    unsigned long	memory	: the memory in KBytes used by the domain
    unsigned short	nrVirtCpu	: the number of virtual CPUs for the domain
    unsigned long long	cpuTime	: the CPU time used in nanoseconds
} virDomainInfo;


Typedef virDomainInfoPtr

virDomainInfo * virDomainInfoPtr;

a virDomainInfoPtr is a pointer to a virDomainInfo structure.


Structure virDomainKernel

struct _virDomainKernel {
    const char *	kernel	: filename pointing to the kernel image
    const char *	ramdisk	: an optional init ramdisk
    const char *	root	: an optional root block device
    const char *	extra	: optional kernel command line parameters
} virDomainKernel;


Typedef virDomainKernelPtr

virDomainKernel * virDomainKernelPtr;

a virDomainKernelPtr is a pointer to a virDomainKernel structure.


Typedef virDomainPtr

virDomain * virDomainPtr;

a virDomainPtr is pointer to a virDomain private structure, this is the type used to reference a Xen domain in the API.


Enum virDomainRestart

enum virDomainRestart {
    VIR_DOMAIN_DESTROY = 1 /* destroy the domain */
    VIR_DOMAIN_RESTART = 2 /* restart the domain */
    VIR_DOMAIN_PRESERVE = 3 /* keep as is, need manual destroy, for debug */
    VIR_DOMAIN_RENAME_RESTART = 4 /*  restart under an new unique name */
};


Enum virDomainState

enum virDomainState {
    VIR_DOMAIN_NOSTATE = 0 /* no state */
    VIR_DOMAIN_RUNNING = 1 /* the domain is running */
    VIR_DOMAIN_BLOCKED = 2 /* the domain is blocked on resource */
    VIR_DOMAIN_PAUSED = 3 /* the domain is paused by user */
    VIR_DOMAIN_SHUTDOWN = 4 /* the domain is being shut down */
    VIR_DOMAIN_SHUTOFF = 5 /* the domain is shut off */
    VIR_DOMAIN_CRASHED = 6 /*  the domain is crashed */
};


Structure virNodeInfo

struct _virNodeInfo {
    charmodel[32]	model	: string indicating the CPU model
    unsigned long	memory	: memory size in kilobytes
    unsigned int	cpus	: the number of active CPUs
    unsigned int	mhz	: expected CPU frequency
    unsigned int	nodes	: the number of NUMA cell, 1 for uniform mem access
    unsigned int	sockets	: number of CPU socket per node
    unsigned int	cores	: number of core per socket
    unsigned int	threads	: number of threads per core
} virNodeInfo;


Typedef virNodeInfoPtr

virNodeInfo * virNodeInfoPtr;

a virNodeInfoPtr is a pointer to a virNodeInfo structure.


virConnectClose ()

int	virConnectClose			(virConnectPtr conn)

This function closes the connection to the Hypervisor. This should not be called if further interaction with the Hypervisor are needed especially if there is running domain which need further monitoring by the application.

conn:pointer to the hypervisor connection
Returns:0 in case of success or -1 in case of error.

virConnectGetType ()

const char *	virConnectGetType	(virConnectPtr conn)

Get the name of the Hypervisor software used.

conn:pointer to the hypervisor connection
Returns:NULL in case of error, a static zero terminated string otherwise.

virConnectGetVersion ()

int	virConnectGetVersion		(virConnectPtr conn, 
unsigned long * hvVer)

Get the version level of the Hypervisor running. This may work only with hypervisor call, i.e. with priviledged access to the hypervisor, not with a Read-Only connection.

conn:pointer to the hypervisor connection
hvVer:return value for the version of the running hypervisor (OUT)
Returns:-1 in case of error, 0 otherwise. if the version can't be extracted by lack of capacities returns 0 and @hvVer is 0, otherwise @hvVer value is major * 1,000,000 + minor * 1,000 + release

virConnectListDomains ()

int	virConnectListDomains		(virConnectPtr conn, 
int * ids,
int maxids)

Collect the list of active domains, and store their ID in @maxids

conn:pointer to the hypervisor connection
ids:array to collect the list of IDs of active domains
maxids:size of @ids
Returns:the number of domain found or -1 in case of error

virConnectNumOfDomains ()

int	virConnectNumOfDomains		(virConnectPtr conn)

Provides the number of active domains.

conn:pointer to the hypervisor connection
Returns:the number of domain found or -1 in case of error

virConnectOpen ()

virConnectPtr	virConnectOpen		(const char * name)

This function should be called first to get a connection to the Hypervisor and xen store

name:optional argument currently unused, pass NULL
Returns:a pointer to the hypervisor connection or NULL in case of error

virConnectOpenReadOnly ()

virConnectPtr	virConnectOpenReadOnly	(const char * name)

This function should be called first to get a restricted connection to the libbrary functionalities. The set of APIs usable are then restricted on the available methods to control the domains.

name:optional argument currently unused, pass NULL
Returns:a pointer to the hypervisor connection or NULL in case of error

virDomainCreateLinux ()

virDomainPtr	virDomainCreateLinux	(virConnectPtr conn, 
const char * xmlDesc,
unsigned int flags)

Launch a new Linux guest domain, based on an XML description similar to the one returned by virDomainGetXMLDesc() This function may requires priviledged access to the hypervisor.

conn:pointer to the hypervisor connection
xmlDesc:an XML description of the domain
flags:an optional set of virDomainFlags
Returns:a new domain object or NULL in case of failure

virDomainDestroy ()

int	virDomainDestroy		(virDomainPtr domain)

Destroy the domain object. The running instance is shutdown if not down already and all resources used by it are given back to the hypervisor. The data structure is freed and should not be used thereafter if the call does not return an error. This function may requires priviledged access

domain:a domain object
Returns:0 in case of success and -1 in case of failure.

virDomainFree ()

int	virDomainFree			(virDomainPtr domain)

Free the domain object. The running instance is kept alive. The data structure is freed and should not be used thereafter.

domain:a domain object
Returns:0 in case of success and -1 in case of failure.

virDomainGetID ()

unsigned int	virDomainGetID		(virDomainPtr domain)

Get the hypervisor ID number for the domain

domain:a domain object
Returns:the domain ID number or (unsigned int) -1 in case of error

virDomainGetInfo ()

int	virDomainGetInfo		(virDomainPtr domain, 
virDomainInfoPtr info)

Extract information about a domain. Note that if the connection used to get the domain is limited only a partial set of the informations can be extracted.

domain:a domain object
info:pointer to a virDomainInfo structure allocated by the user
Returns:0 in case of success and -1 in case of failure.

virDomainGetMaxMemory ()

unsigned long	virDomainGetMaxMemory	(virDomainPtr domain)

Retrieve the maximum amount of physical memory allocated to a domain. If domain is NULL, then this get the amount of memory reserved to Domain0 i.e. the domain where the application runs.

domain:a domain object or NULL
Returns:the memory size in kilobytes or 0 in case of error.

virDomainGetName ()

const char *	virDomainGetName	(virDomainPtr domain)

Get the public name for that domain

domain:a domain object
Returns:a pointer to the name or NULL, the string need not be deallocated its lifetime will be the same as the domain object.

virDomainGetOSType ()

char *	virDomainGetOSType		(virDomainPtr domain)

Get the type of domain operation system.

domain:a domain object
Returns:the new string or NULL in case of error, the string must be freed by the caller.

virDomainGetUUID ()

int	virDomainGetUUID		(virDomainPtr domain, 
unsigned char * uuid)

Get the UUID for a domain

domain:a domain object
uuid:pointer to a 16 bytes array
Returns:-1 in case of error, 0 in case of success

virDomainGetXMLDesc ()

char *	virDomainGetXMLDesc		(virDomainPtr domain, 
int flags)

Provide an XML description of the domain. The description may be reused later to relaunch the domain with virDomainCreateLinux().

domain:a domain object
flags:and OR'ed set of extraction flags, not used yet
Returns:a 0 terminated UTF-8 encoded XML instance, or NULL in case of error. the caller must free() the returned value.

virDomainLookupByID ()

virDomainPtr	virDomainLookupByID	(virConnectPtr conn, 
int id)

Try to find a domain based on the hypervisor ID number

conn:pointer to the hypervisor connection
id:the domain ID number
Returns:a new domain object or NULL in case of failure

virDomainLookupByName ()

virDomainPtr	virDomainLookupByName	(virConnectPtr conn, 
const char * name)

Try to lookup a domain on the given hypervisor based on its name.

conn:pointer to the hypervisor connection
name:name for the domain
Returns:a new domain object or NULL in case of failure

virDomainLookupByUUID ()

virDomainPtr	virDomainLookupByUUID	(virConnectPtr conn, 
const unsigned char * uuid)

Try to lookup a domain on the given hypervisor based on its UUID.

conn:pointer to the hypervisor connection
uuid:the UUID string for the domain
Returns:a new domain object or NULL in case of failure

virDomainReboot ()

int	virDomainReboot			(virDomainPtr domain, 
unsigned int flags)

Reboot a domain, the domain object is still usable there after but the domain OS is being stopped for a restart. Note that the guest OS may ignore the request.

domain:a domain object
flags:extra flags for the reboot operation, not used yet
Returns:0 in case of success and -1 in case of failure.

virDomainRestore ()

int	virDomainRestore		(virConnectPtr conn, 
const char * from)

This method will restore a domain saved to disk by virDomainSave().

conn:pointer to the hypervisor connection
from:path to the
Returns:0 in case of success and -1 in case of failure.

virDomainResume ()

int	virDomainResume			(virDomainPtr domain)

Resume an suspended domain, the process is restarted from the state where it was frozen by calling virSuspendDomain(). This function may requires priviledged access

domain:a domain object
Returns:0 in case of success and -1 in case of failure.

virDomainSave ()

int	virDomainSave			(virDomainPtr domain, 
const char * to)

This method will suspend a domain and save its memory contents to a file on disk. After the call, if successful, the domain is not listed as running anymore (this may be a problem). Use virDomainRestore() to restore a domain after saving.

domain:a domain object
to:path for the output file
Returns:0 in case of success and -1 in case of failure.

virDomainSetMaxMemory ()

int	virDomainSetMaxMemory		(virDomainPtr domain, 
unsigned long memory)

Dynamically change the maximum amount of physical memory allocated to a domain. If domain is NULL, then this change the amount of memory reserved to Domain0 i.e. the domain where the application runs. This function requires priviledged access to the hypervisor.

domain:a domain object or NULL
memory:the memory size in kilobytes
Returns:0 in case of success and -1 in case of failure.

virDomainSetMemory ()

int	virDomainSetMemory		(virDomainPtr domain, 
unsigned long memory)

Dynamically change the target amount of physical memory allocated to a domain. If domain is NULL, then this change the amount of memory reserved to Domain0 i.e. the domain where the application runs. This function may requires priviledged access to the hypervisor.

domain:a domain object or NULL
memory:the memory size in kilobytes
Returns:0 in case of success and -1 in case of failure.

virDomainShutdown ()

int	virDomainShutdown		(virDomainPtr domain)

Shutdown a domain, the domain object is still usable there after but the domain OS is being stopped. Note that the guest OS may ignore the request. TODO: should we add an option for reboot, knowing it may not be doable in the general case ?

domain:a domain object
Returns:0 in case of success and -1 in case of failure.

virDomainSuspend ()

int	virDomainSuspend		(virDomainPtr domain)

Suspends an active domain, the process is frozen without further access to CPU resources and I/O but the memory used by the domain at the hypervisor level will stay allocated. Use virDomainResume() to reactivate the domain. This function may requires priviledged access.

domain:a domain object
Returns:0 in case of success and -1 in case of failure.



virNodeGetInfo ()

int	virNodeGetInfo			(virConnectPtr conn, 
virNodeInfoPtr info)

Extract hardware information about the node.

conn:pointer to the hypervisor connection
info:pointer to a virNodeInfo structure allocated by the user
Returns:0 in case of success and -1 in case of failure.