# Module libvirt-host from libvirt

Provides APIs for the management of hosts

## Table of Contents

### Macros

    #define VIR_NODEINFO_MAXCPUS
    #define VIR_NODE_CPU_STATS_FIELD_LENGTH
    #define VIR_NODE_CPU_STATS_IDLE
    #define VIR_NODE_CPU_STATS_INTR
    #define VIR_NODE_CPU_STATS_IOWAIT
    #define VIR_NODE_CPU_STATS_KERNEL
    #define VIR_NODE_CPU_STATS_USER
    #define VIR_NODE_CPU_STATS_UTILIZATION
    #define VIR_NODE_MEMORY_SHARED_FULL_SCANS
    #define VIR_NODE_MEMORY_SHARED_MERGE_ACROSS_NODES
    #define VIR_NODE_MEMORY_SHARED_PAGES_SHARED
    #define VIR_NODE_MEMORY_SHARED_PAGES_SHARING
    #define VIR_NODE_MEMORY_SHARED_PAGES_TO_SCAN
    #define VIR_NODE_MEMORY_SHARED_PAGES_UNSHARED
    #define VIR_NODE_MEMORY_SHARED_PAGES_VOLATILE
    #define VIR_NODE_MEMORY_SHARED_SLEEP_MILLISECS
    #define VIR_NODE_MEMORY_STATS_BUFFERS
    #define VIR_NODE_MEMORY_STATS_CACHED
    #define VIR_NODE_MEMORY_STATS_FIELD_LENGTH
    #define VIR_NODE_MEMORY_STATS_FREE
    #define VIR_NODE_MEMORY_STATS_TOTAL
    #define VIR_SECURITY_DOI_BUFLEN
    #define VIR_SECURITY_LABEL_BUFLEN
    #define VIR_SECURITY_MODEL_BUFLEN
    #define VIR_UUID_BUFLEN
    #define VIR_UUID_STRING_BUFLEN

### Types

    typedef enum virCPUCompareResult
    typedef struct _virConnect virConnect
    typedef struct _virConnectAuth virConnectAuth
    typedef virConnectAuth * virConnectAuthPtr
    typedef enum virConnectBaselineCPUFlags
    typedef enum virConnectCompareCPUFlags
    typedef struct _virConnectCredential virConnectCredential
    typedef virConnectCredential * virConnectCredentialPtr
    typedef enum virConnectCredentialType
    typedef enum virConnectFlags
    typedef virConnect * virConnectPtr
    typedef enum virNodeAllocPagesFlags
    typedef struct _virNodeCPUStats virNodeCPUStats
    typedef virNodeCPUStats * virNodeCPUStatsPtr
    typedef enum virNodeGetCPUStatsAllCPUs
    typedef enum virNodeGetMemoryStatsAllCells
    typedef struct _virNodeInfo virNodeInfo
    typedef virNodeInfo * virNodeInfoPtr
    typedef struct _virNodeMemoryStats virNodeMemoryStats
    typedef virNodeMemoryStats * virNodeMemoryStatsPtr
    typedef enum virNodeSuspendTarget
    typedef struct _virSecurityLabel virSecurityLabel
    typedef virSecurityLabel * virSecurityLabelPtr
    typedef struct _virSecurityModel virSecurityModel
    typedef virSecurityModel * virSecurityModelPtr
    typedef struct _virStream virStream
    typedef virStream * virStreamPtr

### Functions

    typedef virConnectAuthCallbackPtr
    int	virConnectAuthCallbackPtr	(virConnectCredentialPtr cred,
    					 unsigned int ncred,
    					 void * cbdata)

    char *	virConnectBaselineCPU		(virConnectPtr conn,
    					 const char ** xmlCPUs,
    					 unsigned int ncpus,
    					 unsigned int flags)
    int	virConnectClose			(virConnectPtr conn)
    typedef virConnectCloseFunc
    void	virConnectCloseFunc		(virConnectPtr conn,
    					 int reason,
    					 void * opaque)

    int	virConnectCompareCPU		(virConnectPtr conn,
    					 const char * xmlDesc,
    					 unsigned int flags)
    int	virConnectGetCPUModelNames	(virConnectPtr conn,
    					 const char * arch,
    					 char ** * models,
    					 unsigned int flags)
    char *	virConnectGetCapabilities	(virConnectPtr conn)
    char *	virConnectGetHostname		(virConnectPtr conn)
    int	virConnectGetLibVersion		(virConnectPtr conn,
    					 unsigned long * libVer)
    int	virConnectGetMaxVcpus		(virConnectPtr conn,
    					 const char * type)
    char *	virConnectGetSysinfo		(virConnectPtr conn,
    					 unsigned int flags)
    const char *	virConnectGetType	(virConnectPtr conn)
    char *	virConnectGetURI		(virConnectPtr conn)
    int	virConnectGetVersion		(virConnectPtr conn,
    					 unsigned long * hvVer)
    int	virConnectIsAlive		(virConnectPtr conn)
    int	virConnectIsEncrypted		(virConnectPtr conn)
    int	virConnectIsSecure		(virConnectPtr conn)
    virConnectPtr	virConnectOpen		(const char * name)
    virConnectPtr	virConnectOpenAuth	(const char * name,
    					 virConnectAuthPtr auth,
    					 unsigned int flags)
    virConnectPtr	virConnectOpenReadOnly	(const char * name)
    int	virConnectRef			(virConnectPtr conn)
    int	virConnectRegisterCloseCallback	(virConnectPtr conn,
    					 virConnectCloseFunc cb,
    					 void * opaque,
    					 virFreeCallback freecb)
    int	virConnectSetKeepAlive		(virConnectPtr conn,
    					 int interval,
    					 unsigned int count)
    int	virConnectUnregisterCloseCallback	(virConnectPtr conn,
    						 virConnectCloseFunc cb)
    int	virGetVersion			(unsigned long * libVer,
    					 const char * type,
    					 unsigned long * typeVer)
    int	virInitialize			(void)
    int	virNodeAllocPages		(virConnectPtr conn,
    					 unsigned int npages,
    					 unsigned int * pageSizes,
    					 unsigned long long * pageCounts,
    					 int startCell,
    					 unsigned int cellCount,
    					 unsigned int flags)
    int	virNodeGetCPUMap		(virConnectPtr conn,
    					 unsigned char ** cpumap,
    					 unsigned int * online,
    					 unsigned int flags)
    int	virNodeGetCPUStats		(virConnectPtr conn,
    					 int cpuNum,
    					 virNodeCPUStatsPtr params,
    					 int * nparams,
    					 unsigned int flags)
    int	virNodeGetCellsFreeMemory	(virConnectPtr conn,
    					 unsigned long long * freeMems,
    					 int startCell,
    					 int maxCells)
    unsigned long long	virNodeGetFreeMemory	(virConnectPtr conn)
    int	virNodeGetFreePages		(virConnectPtr conn,
    					 unsigned int npages,
    					 unsigned int * pages,
    					 int startCell,
    					 unsigned int cellCount,
    					 unsigned long long * counts,
    					 unsigned int flags)
    int	virNodeGetInfo			(virConnectPtr conn,
    					 virNodeInfoPtr info)
    int	virNodeGetMemoryParameters	(virConnectPtr conn,
    					 virTypedParameterPtr params,
    					 int * nparams,
    					 unsigned int flags)
    int	virNodeGetMemoryStats		(virConnectPtr conn,
    					 int cellNum,
    					 virNodeMemoryStatsPtr params,
    					 int * nparams,
    					 unsigned int flags)
    int	virNodeGetSecurityModel		(virConnectPtr conn,
    					 virSecurityModelPtr secmodel)
    int	virNodeSetMemoryParameters	(virConnectPtr conn,
    					 virTypedParameterPtr params,
    					 int nparams,
    					 unsigned int flags)
    int	virNodeSuspendForDuration	(virConnectPtr conn,
    					 unsigned int target,
    					 unsigned long long duration,
    					 unsigned int flags)

## Description

### Macros

### `VIR_NODEINFO_MAXCPUS`

    #define VIR_NODEINFO_MAXCPUS

This macro is to calculate the total number of CPUs supported but not necessary active in the host.

### `VIR_NODE_CPU_STATS_FIELD_LENGTH`

    #define VIR_NODE_CPU_STATS_FIELD_LENGTH

Macro providing the field length of virNodeCPUStats

### `VIR_NODE_CPU_STATS_IDLE`

    #define VIR_NODE_CPU_STATS_IDLE

The cumulative idle CPU time, since the node booting up (in nanoseconds).

### `VIR_NODE_CPU_STATS_INTR`

    #define VIR_NODE_CPU_STATS_INTR

The cumulative interrupt CPU time, since the node booting up (in nanoseconds).

### `VIR_NODE_CPU_STATS_IOWAIT`

    #define VIR_NODE_CPU_STATS_IOWAIT

The cumulative I/O wait CPU time, since the node booting up (in nanoseconds).

### `VIR_NODE_CPU_STATS_KERNEL`

    #define VIR_NODE_CPU_STATS_KERNEL

Macro for the cumulative CPU time which was spent by the kernel, since the node booting up (in nanoseconds).

### `VIR_NODE_CPU_STATS_USER`

    #define VIR_NODE_CPU_STATS_USER

The cumulative CPU time which was spent by user processes, since the node booting up (in nanoseconds).

### `VIR_NODE_CPU_STATS_UTILIZATION`

    #define VIR_NODE_CPU_STATS_UTILIZATION

The CPU utilization of a node. The usage value is in percent and 100% represents all CPUs of the node.

### `VIR_NODE_MEMORY_SHARED_FULL_SCANS`

    #define VIR_NODE_MEMORY_SHARED_FULL_SCANS

Macro for typed parameter that represents how many times all mergeable areas have been scanned.

### `VIR_NODE_MEMORY_SHARED_MERGE_ACROSS_NODES`

    #define VIR_NODE_MEMORY_SHARED_MERGE_ACROSS_NODES

Macro for typed parameter that represents whether pages from different NUMA nodes can be merged. The parameter has type int, when its value is 0, only pages which physically reside in the memory area of same NUMA node are merged; When its value is 1, pages from all nodes can be merged. Other values are reserved for future use.

### `VIR_NODE_MEMORY_SHARED_PAGES_SHARED`

    #define VIR_NODE_MEMORY_SHARED_PAGES_SHARED

Macro for typed parameter that represents how many the shared memory pages are being used.

### `VIR_NODE_MEMORY_SHARED_PAGES_SHARING`

    #define VIR_NODE_MEMORY_SHARED_PAGES_SHARING

Macro for typed parameter that represents how many sites are sharing the pages i.e. how much saved.

### `VIR_NODE_MEMORY_SHARED_PAGES_TO_SCAN`

    #define VIR_NODE_MEMORY_SHARED_PAGES_TO_SCAN

Macro for typed parameter that represents how many present pages to scan before the shared memory service goes to sleep.

### `VIR_NODE_MEMORY_SHARED_PAGES_UNSHARED`

    #define VIR_NODE_MEMORY_SHARED_PAGES_UNSHARED

Macro for typed parameter that represents how many pages unique but repeatedly checked for merging.

### `VIR_NODE_MEMORY_SHARED_PAGES_VOLATILE`

    #define VIR_NODE_MEMORY_SHARED_PAGES_VOLATILE

Macro for typed parameter that represents how many pages changing too fast to be placed in a tree.

### `VIR_NODE_MEMORY_SHARED_SLEEP_MILLISECS`

    #define VIR_NODE_MEMORY_SHARED_SLEEP_MILLISECS

Macro for typed parameter that represents how many milliseconds the shared memory service should sleep before next scan.

### `VIR_NODE_MEMORY_STATS_BUFFERS`

    #define VIR_NODE_MEMORY_STATS_BUFFERS

Macro for the buffer memory: On Linux, it is only returned in case of VIR_NODE_MEMORY_STATS_ALL_CELLS.

### `VIR_NODE_MEMORY_STATS_CACHED`

    #define VIR_NODE_MEMORY_STATS_CACHED

Macro for the cached memory: On Linux, it is only returned in case of VIR_NODE_MEMORY_STATS_ALL_CELLS.

### `VIR_NODE_MEMORY_STATS_FIELD_LENGTH`

    #define VIR_NODE_MEMORY_STATS_FIELD_LENGTH

Macro providing the field length of virNodeMemoryStats

### `VIR_NODE_MEMORY_STATS_FREE`

    #define VIR_NODE_MEMORY_STATS_FREE

Macro for the free memory of specified cell: On Linux, it includes buffer and cached memory, in case of VIR_NODE_MEMORY_STATS_ALL_CELLS.

### `VIR_NODE_MEMORY_STATS_TOTAL`

    #define VIR_NODE_MEMORY_STATS_TOTAL

Macro for the total memory of specified cell: it represents the maximum memory.

### `VIR_SECURITY_DOI_BUFLEN`

    #define VIR_SECURITY_DOI_BUFLEN

Macro providing the maximum length of the virSecurityModel doi string.

### `VIR_SECURITY_LABEL_BUFLEN`

    #define VIR_SECURITY_LABEL_BUFLEN

Macro providing the maximum length of the virSecurityLabel label string. Note that this value is based on that used by Labeled NFS.

### `VIR_SECURITY_MODEL_BUFLEN`

    #define VIR_SECURITY_MODEL_BUFLEN

Macro providing the maximum length of the virSecurityModel model string.

### `VIR_UUID_BUFLEN`

    #define VIR_UUID_BUFLEN

This macro provides the length of the buffer required for virDomainGetUUID()

### `VIR_UUID_STRING_BUFLEN`

    #define VIR_UUID_STRING_BUFLEN

This macro provides the length of the buffer required for virDomainGetUUIDString()

### Types

### `virCPUCompareResult`

    enum virCPUCompareResult {

VIR_CPU_COMPARE_ERROR | = | -1
VIR_CPU_COMPARE_INCOMPATIBLE | = | 0
VIR_CPU_COMPARE_IDENTICAL | = | 1
VIR_CPU_COMPARE_SUPERSET | = | 2
VIR_CPU_COMPARE_LAST | = | 3

    }

### `virConnect`

    struct virConnect {

The content of this structure is not made public by the API

    }

### `virConnectAuth`

    struct virConnectAuth {

int * | credtype | List of supported virConnectCredentialType values
unsigned int | ncredtype
virConnectAuthCallbackPtr | cb | Callback used to collect credentials
void * | cbdata

    }

### `virConnectBaselineCPUFlags`

    enum virConnectBaselineCPUFlags {

VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES | = | 1 | show all features
VIR_CONNECT_BASELINE_CPU_MIGRATABLE | = | 2 | filter out non-migratable features

    }

### `virConnectCompareCPUFlags`

    enum virConnectCompareCPUFlags {

VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE | = | 1 | treat incompatible CPUs as failure

    }

### `virConnectCredential`

    struct virConnectCredential {

int | type | One of virConnectCredentialType constants
const char * | prompt | Prompt to show to user
const char * | challenge | Additional challenge to show
const char * | defresult | Optional default result
char * | result | Result to be filled with user response (or defresult)
unsigned int | resultlen | Length of the result

    }

### `virConnectCredentialType`

    enum virConnectCredentialType {

VIR_CRED_USERNAME | = | 1 | Identity to act as
VIR_CRED_AUTHNAME | = | 2 | Identify to authorize as
VIR_CRED_LANGUAGE | = | 3 | RFC 1766 languages, comma separated
VIR_CRED_CNONCE | = | 4 | client supplies a nonce
VIR_CRED_PASSPHRASE | = | 5 | Passphrase secret
VIR_CRED_ECHOPROMPT | = | 6 | Challenge response
VIR_CRED_NOECHOPROMPT | = | 7 | Challenge response
VIR_CRED_REALM | = | 8 | Authentication realm
VIR_CRED_EXTERNAL | = | 9 | Externally managed credential
VIR_CRED_LAST | = | 10 | More may be added - expect the unexpected

    }

### `virConnectFlags`

    enum virConnectFlags {

VIR_CONNECT_RO | = | 1 | A readonly connection
VIR_CONNECT_NO_ALIASES | = | 2 | Don't try to resolve URI aliases

    }

### `virNodeAllocPagesFlags`

    enum virNodeAllocPagesFlags {

VIR_NODE_ALLOC_PAGES_ADD | = | 0 | Add @pageCounts to the pages pool. This can be used only to size up the pool.
VIR_NODE_ALLOC_PAGES_SET | = | 1 | Don't add @pageCounts, instead set passed number of pages. This can be used to free allocated pages.

    }

### `virNodeCPUStats`

    struct virNodeCPUStats {

char field[VIR_NODE_CPU_STATS_FIELD_LENGTH] | field
unsigned long long | value

    }

### `virNodeGetCPUStatsAllCPUs`

    enum virNodeGetCPUStatsAllCPUs {

VIR_NODE_CPU_STATS_ALL_CPUS | = | -1

    }

### `virNodeGetMemoryStatsAllCells`

    enum virNodeGetMemoryStatsAllCells {

VIR_NODE_MEMORY_STATS_ALL_CELLS | = | -1

    }

### `virNodeInfo`

    struct virNodeInfo {

char model[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, 0 if not known or on unusual architectures
unsigned int | nodes | the number of NUMA cell, 1 for unusual NUMA topologies or uniform memory access; check capabilities XML for the actual NUMA topology
unsigned int | sockets | number of CPU sockets per node if nodes > 1, 1 in case of unusual NUMA topology
unsigned int | cores | number of cores per socket, total number of processors in case of unusual NUMA topolog
unsigned int | threads | number of threads per core, 1 in case of unusual numa topology

    }

### `virNodeMemoryStats`

    struct virNodeMemoryStats {

char field[VIR_NODE_MEMORY_STATS_FIELD_LENGTH] | field
unsigned long long | value

    }

### `virNodeSuspendTarget`

    enum virNodeSuspendTarget {

VIR_NODE_SUSPEND_TARGET_MEM | = | 0
VIR_NODE_SUSPEND_TARGET_DISK | = | 1
VIR_NODE_SUSPEND_TARGET_HYBRID | = | 2
VIR_NODE_SUSPEND_TARGET_LAST | = | 3 | This constant is subject to change

    }

### `virSecurityLabel`

    struct virSecurityLabel {

char label[VIR_SECURITY_LABEL_BUFLEN] | label | security label string
int | enforcing | 1 if security policy is being enforced for domain

    }

### `virSecurityModel`

    struct virSecurityModel {

char model[VIR_SECURITY_MODEL_BUFLEN] | model | security model string
char doi[VIR_SECURITY_DOI_BUFLEN] | doi | domain of interpretation

    }

### `virStream`

    struct virStream {

The content of this structure is not made public by the API

    }

### Functions

### `virConnectAuthCallbackPtr`

    typedef int	(*virConnectAuthCallbackPtr)	(virConnectCredentialPtr cred,
    					 unsigned int ncred,
    					 void * cbdata)

When authentication requires one or more interactions, this callback is invoked. For each interaction supplied, data must be gathered from the user and filled in to the 'result' and 'resultlen' fields. If an interaction cannot be filled, fill in NULL and 0.

cred
  list of virConnectCredential object to fetch from user
ncred
  size of cred list
cbdata
  opaque data passed to virConnectOpenAuth
Returns
  0 if all interactions were filled, or -1 upon error

### `virConnectBaselineCPU`

    char *	virConnectBaselineCPU		(virConnectPtr conn,
    					 const char ** xmlCPUs,
    					 unsigned int ncpus,
    					 unsigned int flags)

Computes the most feature-rich CPU which is compatible with all given host CPUs.

If @flags includes VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES then libvirt will explicitly list all CPU features that are part of the host CPU, without this flag features that are part of the CPU model will not be listed.

If @flags includes VIR_CONNECT_BASELINE_CPU_MIGRATABLE, the resulting CPU will not include features that block migration.

conn
  virConnect connection
xmlCPUs
  array of XML descriptions of host CPUs
ncpus
  number of CPUs in xmlCPUs
flags
  bitwise-OR of virConnectBaselineCPUFlags
Returns
  XML description of the computed CPU (caller frees) or NULL on error.

### `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.

Connections are reference counted; the count is explicitly increased by the initial open (virConnectOpen, virConnectOpenAuth, and the like) as well as virConnectRef; it is also temporarily increased by other API that depend on the connection remaining alive. The open and every virConnectRef call should have a matching virConnectClose, and all other references will be released after the corresponding operation completes.

conn
  pointer to the hypervisor connection
Returns
  a positive number if at least 1 reference remains on success. The returned value should not be assumed to be the total reference count. A return of 0 implies no references remain and the connection is closed and memory has been freed. A return of -1 implies a failure. It is possible for the last virConnectClose to return a positive value if some other object still has a temporary reference to the connection, but the application should not try to further use a connection after the virConnectClose that matches the initial open.

### `virConnectCloseFunc`

    typedef void	(*virConnectCloseFunc	)	(virConnectPtr conn,
    					 int reason,
    					 void * opaque)

A callback function to be registered, and called when the connection is closed.

conn
  virConnect connection
reason
  reason why the connection was closed (one of virConnectCloseReason)
opaque
  opaque user data

### `virConnectCompareCPU`

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

Compares the given CPU description with the host CPU

conn
  virConnect connection
xmlDesc
  XML describing the CPU to compare with host CPU
flags
  bitwise-OR of virConnectCompareCPUFlags
Returns
  comparison result according to enum virCPUCompareResult. If VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE is used and @xmlDesc CPU is incompatible with host CPU, this function will return VIR_CPU_COMPARE_ERROR (instead of VIR_CPU_COMPARE_INCOMPATIBLE) and the error will use the VIR_ERR_CPU_INCOMPATIBLE code with a message providing more details about the incompatibility.

### `virConnectGetCPUModelNames`

    int	virConnectGetCPUModelNames	(virConnectPtr conn,
    					 const char * arch,
    					 char ** * models,
    					 unsigned int flags)

Get the list of supported CPU models for a specific architecture.

conn
  virConnect connection
arch
  Architecture
models
  Pointer to a variable to store the NULL-terminated array of the CPU models supported for the specified architecture. Each element and the array itself must be freed by the caller with free. Pass NULL if only the list length is needed.
flags
  extra flags; not used yet, so callers should always pass 0.
Returns
  -1 on error, number of elements in @models on success.

### `virConnectGetCapabilities`

    char *	virConnectGetCapabilities	(virConnectPtr conn)

Provides capabilities of the hypervisor / driver.

conn
  pointer to the hypervisor connection
Returns
  NULL in case of error, or an XML string defining the capabilities. The client must free the returned string after use.

### `virConnectGetHostname`

    char *	virConnectGetHostname		(virConnectPtr conn)

This returns a system hostname on which the hypervisor is running (based on the result of the gethostname system call, but possibly expanded to a fully-qualified domain name via getaddrinfo). If we are connected to a remote system, then this returns the hostname of the remote system.

conn
  pointer to a hypervisor connection
Returns
  the hostname which must be freed by the caller, or NULL if there was an error.

### `virConnectGetLibVersion`

    int	virConnectGetLibVersion		(virConnectPtr conn,
    					 unsigned long * libVer)

Provides @libVer, which is the version of libvirt used by the daemon running on the @conn host

conn
  pointer to the hypervisor connection
libVer
  returns the libvirt library version used on the connection (OUT)
Returns
  -1 in case of failure, 0 otherwise, and values for @libVer have the format major * 1,000,000 + minor * 1,000 + release.

### `virConnectGetMaxVcpus`

    int	virConnectGetMaxVcpus		(virConnectPtr conn,
    					 const char * type)

Provides the maximum number of virtual CPUs supported for a guest VM of a specific type. The 'type' parameter here corresponds to the 'type' attribute in the <domain> element of the XML.

conn
  pointer to the hypervisor connection
type
  value of the 'type' attribute in the <domain> element
Returns
  the maximum of virtual CPU or -1 in case of error.

### `virConnectGetSysinfo`

    char *	virConnectGetSysinfo		(virConnectPtr conn,
    					 unsigned int flags)

This returns the XML description of the sysinfo details for the host on which the hypervisor is running, in the same format as the <sysinfo> element of a domain XML. This information is generally available only for hypervisors running with root privileges.

conn
  pointer to a hypervisor connection
flags
  extra flags; not used yet, so callers should always pass 0
Returns
  the XML string which must be freed by the caller, or NULL if there was an error.

### `virConnectGetType`

    const char *	virConnectGetType	(virConnectPtr conn)

Get the name of the Hypervisor driver used. This is merely the driver name; for example, both KVM and QEMU guests are serviced by the driver for the qemu:// URI, so a return of "QEMU" does not indicate whether KVM acceleration is present. For more details about the hypervisor, use virConnectGetCapabilities().

conn
  pointer to the hypervisor connection
Returns
  NULL in case of error, a static zero terminated string otherwise. See also: http://www.redhat.com/archives/libvir-list/2007-February/msg00096.html

### `virConnectGetURI`

    char *	virConnectGetURI		(virConnectPtr conn)

This returns the URI (name) of the hypervisor connection. Normally this is the same as or similar to the string passed to the virConnectOpen/virConnectOpenReadOnly call, but the driver may make the URI canonical. If name == NULL was passed to virConnectOpen, then the driver will return a non-NULL URI which can be used to connect to the same hypervisor later.

conn
  pointer to a hypervisor connection
Returns
  the URI string which must be freed by the caller, or NULL if there was an error.

### `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 privileged 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

### `virConnectIsAlive`

    int	virConnectIsAlive		(virConnectPtr conn)

Determine if the connection to the hypervisor is still alive

A connection will be classed as alive if it is either local, or running over a channel (TCP or UNIX socket) which is not closed.

conn
  pointer to the connection object
Returns
  1 if alive, 0 if dead, -1 on error

### `virConnectIsEncrypted`

    int	virConnectIsEncrypted		(virConnectPtr conn)

Determine if the connection to the hypervisor is encrypted

conn
  pointer to the connection object
Returns
  1 if encrypted, 0 if not encrypted, -1 on error

### `virConnectIsSecure`

    int	virConnectIsSecure		(virConnectPtr conn)

Determine if the connection to the hypervisor is secure

A connection will be classed as secure if it is either encrypted, or running over a channel which is not exposed to eavesdropping (eg a UNIX domain socket, or pipe)

conn
  pointer to the connection object
Returns
  1 if secure, 0 if not secure, -1 on error

### `virConnectOpen`

    virConnectPtr	virConnectOpen		(const char * name)

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

If @name is NULL, if the LIBVIRT_DEFAULT_URI environment variable is set, then it will be used. Otherwise if the client configuration file has the "uri_default" parameter set, then it will be used. Finally probing will be done to determine a suitable default driver to activate. This involves trying each hypervisor in turn until one successfully opens.

If connecting to an unprivileged hypervisor driver which requires the libvirtd daemon to be active, it will automatically be launched if not already running. This can be prevented by setting the environment variable LIBVIRT_AUTOSTART=0

URIs are documented at http://libvirt.org/uri.html

virConnectClose should be used to release the resources after the connection is no longer needed.

name
  (optional) URI of the hypervisor
Returns
  a pointer to the hypervisor connection or NULL in case of error

### `virConnectOpenAuth`

    virConnectPtr	virConnectOpenAuth	(const char * name,
    					 virConnectAuthPtr auth,
    					 unsigned int flags)

This function should be called first to get a connection to the Hypervisor. If necessary, authentication will be performed fetching credentials via the callback

See virConnectOpen for notes about environment variables which can have an effect on opening drivers and freeing the connection resources

URIs are documented at http://libvirt.org/uri.html

name
  (optional) URI of the hypervisor
auth
  Authenticate callback parameters
flags
  bitwise-OR of virConnectFlags
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 library functionalities. The set of APIs usable are then restricted on the available methods to control the domains.

See virConnectOpen for notes about environment variables which can have an effect on opening drivers and freeing the connection resources

URIs are documented at http://libvirt.org/uri.html

name
  (optional) URI of the hypervisor
Returns
  a pointer to the hypervisor connection or NULL in case of error

### `virConnectRef`

    int	virConnectRef			(virConnectPtr conn)

Increment the reference count on the connection. For each additional call to this method, there shall be a corresponding call to virConnectClose to release the reference count, once the caller no longer needs the reference to this object.

This method is typically useful for applications where multiple threads are using a connection, and it is required that the connection remain open until all threads have finished using it. ie, each new thread using a connection would increment the reference count.

conn
  the connection to hold a reference on
Returns
  0 in case of success, -1 in case of failure

### `virConnectRegisterCloseCallback`

    int	virConnectRegisterCloseCallback	(virConnectPtr conn,
    					 virConnectCloseFunc cb,
    					 void * opaque,
    					 virFreeCallback freecb)

Registers a callback to be invoked when the connection is closed. This callback is invoked when there is any condition that causes the socket connection to the hypervisor to be closed.

This function is only applicable to hypervisor drivers which maintain a persistent open connection. Drivers which open a new connection for every operation will not invoke this.

The @freecb must not invoke any other libvirt public APIs, since it is not called from a re-entrant safe context.

conn
  pointer to connection object
cb
  callback to invoke upon close
opaque
  user data to pass to @cb
freecb
  callback to free @opaque
Returns
  0 on success, -1 on error

### `virConnectSetKeepAlive`

    int	virConnectSetKeepAlive		(virConnectPtr conn,
    					 int interval,
    					 unsigned int count)

Start sending keepalive messages after @interval seconds of inactivity and consider the connection to be broken when no response is received after @count keepalive messages sent in a row. In other words, sending count + 1 keepalive message results in closing the connection. When @interval is <= 0, no keepalive messages will be sent. When @count is 0, the connection will be automatically closed after @interval seconds of inactivity without sending any keepalive messages.

Note: The client has to implement and run an event loop with virEventRegisterImpl() or virEventRegisterDefaultImpl() to be able to use keepalive messages. Failure to do so may result in connections being closed unexpectedly.

Note: This API function controls only keepalive messages sent by the client. If the server is configured to use keepalive you still need to run the event loop to respond to them, even if you disable keepalives by this function.

conn
  pointer to a hypervisor connection
interval
  number of seconds of inactivity before a keepalive message is sent
count
  number of messages that can be sent in a row
Returns
  -1 on error, 0 on success, 1 when remote party doesn't support keepalive messages.

### `virConnectUnregisterCloseCallback`

    int	virConnectUnregisterCloseCallback	(virConnectPtr conn,
    						 virConnectCloseFunc cb)

Unregisters the callback previously set with the virConnectRegisterCloseCallback method. The callback will no longer receive notifications when the connection closes. If a virFreeCallback was provided at time of registration, it will be invoked

conn
  pointer to connection object
cb
  pointer to the current registered callback
Returns
  0 on success, -1 on error

### `virGetVersion`

    int	virGetVersion			(unsigned long * libVer,
    					 const char * type,
    					 unsigned long * typeVer)

Provides version information. @libVer is the version of the library and will always be set unless an error occurs, in which case an error code will be returned. @typeVer exists for historical compatibility; if it is not NULL it will duplicate @libVer (it was originally intended to return hypervisor information based on @type, but due to the design of remote clients this is not reliable). To get the version of the running hypervisor use the virConnectGetVersion() function instead. To get the libvirt library version used by a connection use the virConnectGetLibVersion() instead.

This function includes a call to virInitialize() when necessary.

libVer
  return value for the library version (OUT)
type
  ignored; pass NULL
typeVer
  pass NULL; for historical purposes duplicates @libVer if non-NULL
Returns
  -1 in case of failure, 0 otherwise, and values for @libVer and @typeVer have the format major * 1,000,000 + minor * 1,000 + release.

### `virInitialize`

    int	virInitialize			(void)

Initialize the library.

This method is invoked automatically by any of the virConnectOpen() API calls, and by virGetVersion(). Since release 1.0.0, there is no need to call this method even in a multithreaded application, since initialization is performed in a thread safe manner; but applications using an older version of the library should manually call this before setting up competing threads that attempt virConnectOpen in parallel.

The only other time it would be necessary to call virInitialize is if the application did not invoke virConnectOpen as its first API call, such as when calling virEventRegisterImpl() before setting up connections, or when using virSetErrorFunc() to alter error reporting of the first connection attempt.

Returns
  0 in case of success, -1 in case of error

### `virNodeAllocPages`

    int	virNodeAllocPages		(virConnectPtr conn,
    					 unsigned int npages,
    					 unsigned int * pageSizes,
    					 unsigned long long * pageCounts,
    					 int startCell,
    					 unsigned int cellCount,
    					 unsigned int flags)

Sometimes, when trying to start a new domain, it may be necessary to reserve some huge pages in the system pool which can be then allocated by the domain. This API serves that purpose. On its input, @pageSizes and @pageCounts are arrays of the same cardinality of @npages. The @pageSizes contains page sizes which are to be allocated in the system (the size unit is kibibytes), and @pageCounts then contains the number of pages to reserve. If @flags is 0 (VIR_NODE_ALLOC_PAGES_ADD), each pool corresponding to @pageSizes grows by the number of pages specified in the corresponding @pageCounts. If @flags contains VIR_NODE_ALLOC_PAGES_SET, each pool mentioned is resized to the given number of pages. The pages pool can be allocated over several NUMA nodes at once, just point at @startCell and tell how many subsequent NUMA nodes should be taken in. As a special case, if @startCell is equal to negative one, then kernel is instructed to allocate the pages over all NUMA nodes proportionally.

conn
  pointer to the hypervisor connection
npages
  number of items in the @pageSizes and @pageCounts arrays
pageSizes
  which huge page sizes to allocate
pageCounts
  how many pages should be allocated
startCell
  index of first cell to allocate pages on
cellCount
  number of consecutive cells to allocate pages on
flags
  extra flags; binary-OR of virNodeAllocPagesFlags
Returns
  the number of nodes successfully adjusted or -1 in case of an error.

### `virNodeGetCPUMap`

    int	virNodeGetCPUMap		(virConnectPtr conn,
    					 unsigned char ** cpumap,
    					 unsigned int * online,
    					 unsigned int flags)

Get CPU map of host node CPUs.

conn
  pointer to the hypervisor connection
cpumap
  optional pointer to a bit map of real CPUs on the host node (in 8-bit bytes) (OUT) In case of success each bit set to 1 means that corresponding CPU is online. Bytes are stored in little-endian order: CPU0-7, 8-15... In each byte, lowest CPU number is least significant bit. The bit map is allocated by virNodeGetCPUMap and needs to be released using free() by the caller.
online
  optional number of online CPUs in cpumap (OUT) Contains the number of online CPUs if the call was successful.
flags
  extra flags; not used yet, so callers should always pass 0
Returns
  number of CPUs present on the host node, or -1 if there was an error.

### `virNodeGetCPUStats`

    int	virNodeGetCPUStats		(virConnectPtr conn,
    					 int cpuNum,
    					 virNodeCPUStatsPtr params,
    					 int * nparams,
    					 unsigned int flags)

This function provides individual cpu statistics of the node. If you want to get total cpu statistics of the node, you must specify VIR_NODE_CPU_STATS_ALL_CPUS to @cpuNum. The @params array will be filled with the values equal to the number of parameters suggested by @nparams

As the value of @nparams is dynamic, call the API setting @nparams to 0 and @params as NULL, the API returns the number of parameters supported by the HV by updating @nparams on SUCCESS. The caller should then allocate @params array, i.e. (sizeof(@virNodeCPUStats) * @nparams) bytes and call the API again.

Here is a sample code snippet:

    if (virNodeGetCPUStats(conn, cpuNum, NULL, &nparams, 0) == 0 &&
        nparams != 0) {
        if ((params = malloc(sizeof(virNodeCPUStats) * nparams)) == NULL)
            goto error;
        memset(params, 0, sizeof(virNodeCPUStats) * nparams);
        if (virNodeGetCPUStats(conn, cpuNum, params, &nparams, 0))
            goto error;
    }

This function doesn't require privileged access to the hypervisor. This function expects the caller to allocate the @params.

CPU time Statistics:

VIR_NODE_CPU_STATS_KERNEL: The cumulative CPU time which spends by kernel, when the node booting up.(nanoseconds) VIR_NODE_CPU_STATS_USER: The cumulative CPU time which spends by user processes, when the node booting up.(nanoseconds) VIR_NODE_CPU_STATS_IDLE: The cumulative idle CPU time, when the node booting up.(nanoseconds) VIR_NODE_CPU_STATS_IOWAIT: The cumulative I/O wait CPU time, when the node booting up.(nanoseconds) VIR_NODE_CPU_STATS_UTILIZATION: The CPU utilization. The usage value is in percent and 100% represents all CPUs on the server.

conn
  pointer to the hypervisor connection.
cpuNum
  number of node cpu. (VIR_NODE_CPU_STATS_ALL_CPUS means total cpu statistics)
params
  pointer to node cpu time parameter objects
nparams
  number of node cpu time parameter (this value should be same or less than the number of parameters supported)
flags
  extra flags; not used yet, so callers should always pass 0
Returns
  -1 in case of error, 0 in case of success.

### `virNodeGetCellsFreeMemory`

    int	virNodeGetCellsFreeMemory	(virConnectPtr conn,
    					 unsigned long long * freeMems,
    					 int startCell,
    					 int maxCells)

This call returns the amount of free memory in one or more NUMA cells. The @freeMems array must be allocated by the caller and will be filled with the amount of free memory in bytes for each cell requested, starting with startCell (in freeMems[0]), up to either (startCell + maxCells), or the number of additional cells in the node, whichever is smaller.

conn
  pointer to the hypervisor connection
freeMems
  pointer to the array of unsigned long long
startCell
  index of first cell to return freeMems info on.
maxCells
  Maximum number of cells for which freeMems information can be returned.
Returns
  the number of entries filled in freeMems, or -1 in case of error.

### `virNodeGetFreeMemory`

    unsigned long long	virNodeGetFreeMemory	(virConnectPtr conn)

provides the free memory available on the Node Note: most libvirt APIs provide memory sizes in kibibytes, but in this function the returned value is in bytes. Divide by 1024 as necessary.

conn
  pointer to the hypervisor connection
Returns
  the available free memory in bytes or 0 in case of error

### `virNodeGetFreePages`

    int	virNodeGetFreePages		(virConnectPtr conn,
    					 unsigned int npages,
    					 unsigned int * pages,
    					 int startCell,
    					 unsigned int cellCount,
    					 unsigned long long * counts,
    					 unsigned int flags)

This calls queries the host system on free pages of specified size. For the input, @pages is expected to be filled with pages that caller is interested in (the size unit is kibibytes, so e.g. pass 2048 for 2MB), then @startcell refers to the first NUMA node that info should be collected from, and @cellcount tells how many consecutive nodes should be queried. On the function output, @counts is filled with desired information, where items are grouped by NUMA node. So from @counts[0] till @counts[@npages - 1] you'll find count for the first node (@startcell), then from @counts[@npages] till @count[2 * @npages - 1] you'll find info for the (@startcell + 1) node, and so on. It's callers responsibility to allocate the @counts array.

Example how to use this API:

    unsigned int pages[] = { 4, 2048, 1048576}
    unsigned int npages = ARRAY_CARDINALITY(pages);
    int startcell = 0;
    unsigned int cellcount = 2;

    unsigned long long counts = malloc(sizeof(long long) * npages * cellcount);

    virNodeGetFreePages(conn, pages, npages,
                        startcell, cellcount, counts, 0);

    for (i = 0 ; i < cellcount ; i++) {
        fprintf(stdout, "Cell %d\n", startcell + i);
        for (j = 0 ; j < npages ; j++) {
           fprintf(stdout, "  Page size=%d count=%d bytes=%llu\n",
                   pages[j], counts[(i * npages) +  j],
                   pages[j] * counts[(i * npages) +  j]);
        }
    }

    This little code snippet will produce something like this:
    Cell 0
     Page size=4096 count=300 bytes=1228800
     Page size=2097152 count=0 bytes=0
     Page size=1073741824 count=1 bytes=1073741824
    Cell 1
     Page size=4096 count=0 bytes=0
     Page size=2097152 count=20 bytes=41943040
     Page size=1073741824 count=0 bytes=0

conn
  pointer to the hypervisor connection
npages
  number of items in the @pages array
pages
  page sizes to query
startCell
  index of first cell to return free pages info on.
cellCount
  maximum number of cells for which free pages information can be returned.
counts
  returned counts of free pages
flags
  extra flags; not used yet, so callers should always pass 0
Returns
  the number of entries filled in @counts or -1 in case of error.

### `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.

### `virNodeGetMemoryParameters`

    int	virNodeGetMemoryParameters	(virConnectPtr conn,
    					 virTypedParameterPtr params,
    					 int * nparams,
    					 unsigned int flags)

Get all node memory parameters (parameters unsupported by OS will be omitted). On input, @nparams gives the size of the @params array; on output, @nparams gives how many slots were filled with parameter information, which might be less but will not exceed the input value.

As a special case, calling with @params as NULL and @nparams as 0 on input will cause @nparams on output to contain the number of parameters supported by the hypervisor. The caller should then allocate @params array, i.e. (sizeof(@virTypedParameter) * @nparams) bytes and call the API again. See virDomainGetMemoryParameters() for an equivalent usage example.

conn
  pointer to the hypervisor connection
params
  pointer to memory parameter object (return value, allocated by the caller)
nparams
  pointer to number of memory parameters; input and output
flags
  extra flags; not used yet, so callers should always pass 0
Returns
  0 in case of success, and -1 in case of failure.

### `virNodeGetMemoryStats`

    int	virNodeGetMemoryStats		(virConnectPtr conn,
    					 int cellNum,
    					 virNodeMemoryStatsPtr params,
    					 int * nparams,
    					 unsigned int flags)

This function provides memory stats of the node. If you want to get total memory statistics of the node, you must specify VIR_NODE_MEMORY_STATS_ALL_CELLS to @cellNum. The @params array will be filled with the values equal to the number of stats suggested by @nparams

As the value of @nparams is dynamic, call the API setting @nparams to 0 and @params as NULL, the API returns the number of parameters supported by the HV by updating @nparams on SUCCESS. The caller should then allocate @params array, i.e. (sizeof(@virNodeMemoryStats) * @nparams) bytes and call the API again.

Here is the sample code snippet:

    if (virNodeGetMemoryStats(conn, cellNum, NULL, &nparams, 0) == 0 &&
        nparams != 0) {
        if ((params = malloc(sizeof(virNodeMemoryStats) * nparams)) == NULL)
            goto error;
        memset(params, cellNum, 0, sizeof(virNodeMemoryStats) * nparams);
        if (virNodeGetMemoryStats(conn, params, &nparams, 0))
            goto error;
    }

This function doesn't require privileged access to the hypervisor. This function expects the caller to allocate the @params.

Memory Stats:

VIR_NODE_MEMORY_STATS_TOTAL: The total memory usage.(KB) VIR_NODE_MEMORY_STATS_FREE: The free memory usage.(KB) On linux, this usage includes buffers and cached. VIR_NODE_MEMORY_STATS_BUFFERS: The buffers memory usage.(KB) VIR_NODE_MEMORY_STATS_CACHED: The cached memory usage.(KB)

conn
  pointer to the hypervisor connection.
cellNum
  number of node cell. (VIR_NODE_MEMORY_STATS_ALL_CELLS means total cell statistics)
params
  pointer to node memory stats objects
nparams
  number of node memory stats (this value should be same or less than the number of stats supported)
flags
  extra flags; not used yet, so callers should always pass 0
Returns
  -1 in case of error, 0 in case of success.

### `virNodeGetSecurityModel`

    int	virNodeGetSecurityModel		(virConnectPtr conn,
    					 virSecurityModelPtr secmodel)

Extract the security model of a hypervisor. The 'model' field in the @secmodel argument may be initialized to the empty string if the driver has not activated a security model.

conn
  a connection object
secmodel
  pointer to a virSecurityModel structure
Returns
  0 in case of success, -1 in case of failure

### `virNodeSetMemoryParameters`

    int	virNodeSetMemoryParameters	(virConnectPtr conn,
    					 virTypedParameterPtr params,
    					 int nparams,
    					 unsigned int flags)

Change all or a subset of the node memory tunables. The function fails if not all of the tunables are supported.

Note that it's not recommended to use this function while the outside tuning program is running (such as ksmtuned under Linux), as they could change the tunables in parallel, which could cause conflicts.

This function may require privileged access to the hypervisor.

conn
  pointer to the hypervisor connection
params
  pointer to scheduler parameter objects
nparams
  number of scheduler parameter objects (this value can be the same or less than the returned value nparams of virDomainGetSchedulerType)
flags
  extra flags; not used yet, so callers should always pass 0
Returns
  0 in case of success, -1 in case of failure.

### `virNodeSuspendForDuration`

    int	virNodeSuspendForDuration	(virConnectPtr conn,
    					 unsigned int target,
    					 unsigned long long duration,
    					 unsigned int flags)

Attempt to suspend the node (host machine) for the given duration of time in the specified state (Suspend-to-RAM, Suspend-to-Disk or Hybrid-Suspend). Schedule the node's Real-Time-Clock interrupt to resume the node after the duration is complete.

conn
  pointer to the hypervisor connection
target
  the state to which the host must be suspended to, such as: VIR_NODE_SUSPEND_TARGET_MEM (Suspend-to-RAM) VIR_NODE_SUSPEND_TARGET_DISK (Suspend-to-Disk) VIR_NODE_SUSPEND_TARGET_HYBRID (Hybrid-Suspend, which is a combination of the former modes).
duration
  the time duration in seconds for which the host has to be suspended
flags
  extra flags; not used yet, so callers should always pass 0
Returns
  0 on success (i.e., the node will be suspended after a short delay), -1 on failure (the operation is not supported, or an attempted suspend is already underway).