New APIs for checking some object properties

Introduce a number of new APIs to  expose some boolean properties
of objects, which cannot otherwise reliably determined, nor are
aspects of the XML configuration.

 * virDomainIsActive: Checking virDomainGetID is not reliable
   since it is not possible to distinguish between error condition
   and inactive domain for ID of -1.
 * virDomainIsPersistent: Check whether a persistent config exists
   for the domain

 * virNetworkIsActive: Check whether the network is active
 * virNetworkIsPersistent: Check whether a persistent config exists
   for the network

 * virStoragePoolIsActive: Check whether the storage pool is active
 * virStoragePoolIsPersistent: Check whether a persistent config exists
   for the storage pool

 * virInterfaceIsActive: Check whether the host interface is active

 * virConnectIsSecure: whether the communication channel to the
   hypervisor is secure
 * virConnectIsEncrypted: whether any network based commnunication
   channels are encrypted

NB, a channel can be secure, even if not encrypted, eg if it does
not involve the network, like a UNIX socket, or pipe.

 * include/libvirt/libvirt.h.in: Define public API
 * src/driver.h: Define internal driver API
 * src/libvirt.c: Implement public API entry point
 * src/libvirt_public.syms: Export API symbols
 * src/esx/esx_driver.c, src/lxc/lxc_driver.c,
   src/interface/netcf_driver.c, src/network/bridge_driver.c,
   src/opennebula/one_driver.c, src/openvz/openvz_driver.c,
   src/phyp/phyp_driver.c, src/qemu/qemu_driver.c,
   src/remote/remote_driver.c, src/test/test_driver.c,
   src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
   src/xen/xen_driver.c: Stub out driver tables
This commit is contained in:
Daniel P. Berrange 2009-10-21 11:49:05 +01:00
parent 117aa0d874
commit c04498b305
17 changed files with 432 additions and 0 deletions

View File

@ -1653,6 +1653,22 @@ int virStreamAbort(virStreamPtr st);
int virStreamFree(virStreamPtr st);
int virDomainIsActive(virDomainPtr dom);
int virDomainIsPersistent(virDomainPtr dom);
int virNetworkIsActive(virNetworkPtr net);
int virNetworkIsPersistent(virNetworkPtr net);
int virStoragePoolIsActive(virStoragePoolPtr pool);
int virStoragePoolIsPersistent(virStoragePoolPtr pool);
int virInterfaceIsActive(virInterfacePtr iface);
int virConnectIsEncrypted(virConnectPtr conn);
int virConnectIsSecure(virConnectPtr conn);
#ifdef __cplusplus
}
#endif

View File

@ -337,6 +337,15 @@ typedef int
unsigned long resource,
const char *dom_xml);
typedef int
(*virDrvConnectIsEncrypted)(virConnectPtr conn);
typedef int
(*virDrvConnectIsSecure)(virConnectPtr conn);
typedef int
(*virDrvDomainIsActive)(virDomainPtr dom);
typedef int
(*virDrvDomainIsPersistent)(virDomainPtr dom);
/**
* _virDriver:
*
@ -418,6 +427,10 @@ struct _virDriver {
virDrvNodeDeviceReAttach nodeDeviceReAttach;
virDrvNodeDeviceReset nodeDeviceReset;
virDrvDomainMigratePrepareTunnel domainMigratePrepareTunnel;
virDrvConnectIsEncrypted isEncrypted;
virDrvConnectIsSecure isSecure;
virDrvDomainIsActive domainIsActive;
virDrvDomainIsPersistent domainIsPersistent;
};
typedef int
@ -462,6 +475,12 @@ typedef int
(*virDrvNetworkSetAutostart) (virNetworkPtr network,
int autostart);
typedef int
(*virDrvNetworkIsActive)(virNetworkPtr net);
typedef int
(*virDrvNetworkIsPersistent)(virNetworkPtr net);
typedef struct _virNetworkDriver virNetworkDriver;
typedef virNetworkDriver *virNetworkDriverPtr;
@ -495,6 +514,8 @@ struct _virNetworkDriver {
virDrvNetworkGetBridgeName networkGetBridgeName;
virDrvNetworkGetAutostart networkGetAutostart;
virDrvNetworkSetAutostart networkSetAutostart;
virDrvNetworkIsActive networkIsActive;
virDrvNetworkIsPersistent networkIsPersistent;
};
/*-------*/
@ -534,6 +555,10 @@ typedef int
(*virDrvInterfaceDestroy) (virInterfacePtr iface,
unsigned int flags);
typedef int
(*virDrvInterfaceIsActive)(virInterfacePtr iface);
typedef struct _virInterfaceDriver virInterfaceDriver;
typedef virInterfaceDriver *virInterfaceDriverPtr;
@ -562,6 +587,7 @@ struct _virInterfaceDriver {
virDrvInterfaceUndefine interfaceUndefine;
virDrvInterfaceCreate interfaceCreate;
virDrvInterfaceDestroy interfaceDestroy;
virDrvInterfaceIsActive interfaceIsActive;
};
@ -668,6 +694,12 @@ typedef virStorageVolPtr
virStorageVolPtr clone,
unsigned int flags);
typedef int
(*virDrvStoragePoolIsActive)(virStoragePoolPtr pool);
typedef int
(*virDrvStoragePoolIsPersistent)(virStoragePoolPtr pool);
typedef struct _virStorageDriver virStorageDriver;
typedef virStorageDriver *virStorageDriverPtr;
@ -719,6 +751,8 @@ struct _virStorageDriver {
virDrvStorageVolGetInfo volGetInfo;
virDrvStorageVolGetXMLDesc volGetXMLDesc;
virDrvStorageVolGetPath volGetPath;
virDrvStoragePoolIsActive poolIsActive;
virDrvStoragePoolIsPersistent poolIsPersistent;
};
#ifdef WITH_LIBVIRTD

View File

@ -3313,6 +3313,10 @@ static virDriver esxDriver = {
NULL, /* nodeDeviceReAttach */
NULL, /* nodeDeviceReset */
NULL, /* domainMigratePrepareTunnel */
NULL, /* isEncrypted */
NULL, /* isSecure */
NULL, /* domainIsActive */
NULL, /* domainIsPersistent */
};

View File

@ -526,6 +526,7 @@ static virInterfaceDriver interfaceDriver = {
interfaceUndefine, /* interfaceUndefine */
interfaceCreate, /* interfaceCreate */
interfaceDestroy, /* interfaceDestroy */
NULL, /* interfaceIsActive */
};
int interfaceRegister(void) {

View File

@ -10334,3 +10334,313 @@ int virStreamFree(virStreamPtr stream)
return (-1);
return (0);
}
/**
* virDomainIsActive:
* @dom: pointer to the domain object
*
* Determine if the domain is currently running
*
* Returns 1 if running, 0 if inactive, -1 on error
*/
int virDomainIsActive(virDomainPtr dom)
{
DEBUG("dom=%p", dom);
virResetLastError();
if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (-1);
}
if (dom->conn->driver->domainIsActive) {
int ret;
ret = dom->conn->driver->domainIsActive(dom);
if (ret < 0)
goto error;
return ret;
}
virLibConnError(dom->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
error:
/* Copy to connection error object for back compatability */
virSetConnError(dom->conn);
return -1;
}
/**
* virDomainIsPersistent:
* @dom: pointer to the domain object
*
* Determine if the domain has a persistent configuration
* which means it will still exist after shutting down
*
* Returns 1 if persistent, 0 if transient, -1 on error
*/
int virDomainIsPersistent(virDomainPtr dom)
{
DEBUG("dom=%p", dom);
virResetLastError();
if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (-1);
}
if (dom->conn->driver->domainIsPersistent) {
int ret;
ret = dom->conn->driver->domainIsPersistent(dom);
if (ret < 0)
goto error;
return ret;
}
virLibConnError(dom->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
error:
/* Copy to connection error object for back compatability */
virSetConnError(dom->conn);
return -1;
}
/**
* virNetworkIsActive:
* @net: pointer to the network object
*
* Determine if the network is currently running
*
* Returns 1 if running, 0 if inactive, -1 on error
*/
int virNetworkIsActive(virNetworkPtr net)
{
DEBUG("net=%p", net);
virResetLastError();
if (!VIR_IS_CONNECTED_NETWORK(net)) {
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (-1);
}
if (net->conn->networkDriver->networkIsActive) {
int ret;
ret = net->conn->networkDriver->networkIsActive(net);
if (ret < 0)
goto error;
return ret;
}
virLibConnError(net->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
error:
/* Copy to connection error object for back compatability */
virSetConnError(net->conn);
return -1;
}
/**
* virNetworkIsPersistent:
* @net: pointer to the network object
*
* Determine if the network has a persistent configuration
* which means it will still exist after shutting down
*
* Returns 1 if persistent, 0 if transient, -1 on error
*/
int virNetworkIsPersistent(virNetworkPtr net)
{
DEBUG("net=%p", net);
virResetLastError();
if (!VIR_IS_CONNECTED_NETWORK(net)) {
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (-1);
}
if (net->conn->networkDriver->networkIsPersistent) {
int ret;
ret = net->conn->networkDriver->networkIsPersistent(net);
if (ret < 0)
goto error;
return ret;
}
virLibConnError(net->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
error:
/* Copy to connection error object for back compatability */
virSetConnError(net->conn);
return -1;
}
/**
* virStoragePoolIsActive:
* @pool: pointer to the storage pool object
*
* Determine if the storage pool is currently running
*
* Returns 1 if running, 0 if inactive, -1 on error
*/
int virStoragePoolIsActive(virStoragePoolPtr pool)
{
DEBUG("pool=%p", pool);
virResetLastError();
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) {
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (-1);
}
if (pool->conn->storageDriver->poolIsActive) {
int ret;
ret = pool->conn->storageDriver->poolIsActive(pool);
if (ret < 0)
goto error;
return ret;
}
virLibConnError(pool->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
error:
/* Copy to connection error object for back compatability */
virSetConnError(pool->conn);
return -1;
}
/**
* virStoragePoolIsPersistent:
* @pool: pointer to the storage pool object
*
* Determine if the storage pool has a persistent configuration
* which means it will still exist after shutting down
*
* Returns 1 if persistent, 0 if transient, -1 on error
*/
int virStoragePoolIsPersistent(virStoragePoolPtr pool)
{
DEBUG("pool=%p", pool);
virResetLastError();
if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) {
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (-1);
}
if (pool->conn->storageDriver->poolIsPersistent) {
int ret;
ret = pool->conn->storageDriver->poolIsPersistent(pool);
if (ret < 0)
goto error;
return ret;
}
virLibConnError(pool->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
error:
/* Copy to connection error object for back compatability */
virSetConnError(pool->conn);
return -1;
}
/**
* virInterfaceIsActive:
* @iface: pointer to the interface object
*
* Determine if the interface is currently running
*
* Returns 1 if running, 0 if inactive, -1 on error
*/
int virInterfaceIsActive(virInterfacePtr iface)
{
DEBUG("iface=%p", iface);
virResetLastError();
if (!VIR_IS_CONNECTED_INTERFACE(iface)) {
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (-1);
}
if (iface->conn->interfaceDriver->interfaceIsActive) {
int ret;
ret = iface->conn->interfaceDriver->interfaceIsActive(iface);
if (ret < 0)
goto error;
return ret;
}
virLibConnError(iface->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
error:
/* Copy to connection error object for back compatability */
virSetConnError(iface->conn);
return -1;
}
/**
* virConnectIsEncrypted:
* @conn: pointer to the connection object
*
* Determine if the connection to the hypervisor is encrypted
*
* Returns 1 if encrypted, 0 if not encrypted, -1 on error
*/
int virConnectIsEncrypted(virConnectPtr conn)
{
DEBUG("conn=%p", conn);
virResetLastError();
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (-1);
}
if (conn->driver->isEncrypted) {
int ret;
ret = conn->driver->isEncrypted(conn);
if (ret < 0)
goto error;
return ret;
}
virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
error:
/* Copy to connection error object for back compatability */
virSetConnError(conn);
return -1;
}
/**
* virConnectIsSecure:
* @conn: pointer to the connection object
*
* 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)
*
* Returns 1 if secure, 0 if secure, -1 on error
*/
int virConnectIsSecure(virConnectPtr conn)
{
DEBUG("conn=%p", conn);
virResetLastError();
if (!VIR_IS_CONNECT(conn)) {
virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (-1);
}
if (conn->driver->isSecure) {
int ret;
ret = conn->driver->isSecure(conn);
if (ret < 0)
goto error;
return ret;
}
virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
error:
/* Copy to connection error object for back compatability */
virSetConnError(conn);
return -1;
}

View File

@ -329,4 +329,17 @@ LIBVIRT_0.7.2 {
virDomainMigrateToURI;
} LIBVIRT_0.7.1;
LIBVIRT_0.7.3 {
global:
virConnectIsEncrypted;
virConnectIsSecure;
virDomainIsActive;
virDomainIsPersistent;
virNetworkIsActive;
virNetworkIsPersistent;
virStoragePoolIsActive;
virStoragePoolIsPersistent;
virInterfaceIsActive;
} LIBVIRT_0.7.2;
# .... define new API here using predicted next version number ....

View File

@ -2278,6 +2278,10 @@ static virDriver lxcDriver = {
NULL, /* nodeDeviceReAttach */
NULL, /* nodeDeviceReset */
NULL, /* domainMigratePrepareTunnel */
NULL, /* isEncrypted */
NULL, /* isSecure */
NULL, /* domainIsActive */
NULL, /* domainIsPersistent */
};
static virStateDriver lxcStateDriver = {

View File

@ -1515,6 +1515,8 @@ static virNetworkDriver networkDriver = {
networkGetBridgeName, /* networkGetBridgeName */
networkGetAutostart, /* networkGetAutostart */
networkSetAutostart, /* networkSetAutostart */
NULL, /* networkIsActive */
NULL, /* networkIsPersistent */
};
static virStateDriver networkStateDriver = {

View File

@ -761,6 +761,10 @@ static virDriver oneDriver = {
NULL, /* nodeDeviceReAttach; */
NULL, /* nodeDeviceReset; */
NULL, /* domainMigratePrepareTunnel */
NULL, /* isEncrypted */
NULL, /* isSecure */
NULL, /* domainIsActive */
NULL, /* domainIsPersistent */
};
static virStateDriver oneStateDriver = {

View File

@ -1471,6 +1471,10 @@ static virDriver openvzDriver = {
NULL, /* nodeDeviceReAttach */
NULL, /* nodeDeviceReset */
NULL, /* domainMigratePrepareTunnel */
NULL, /* isEncrypted */
NULL, /* isSecure */
NULL, /* domainIsActive */
NULL, /* domainIsPersistent */
};
int openvzRegister(void) {

View File

@ -1625,6 +1625,10 @@ virDriver phypDriver = {
NULL, /* nodeDeviceReAttach */
NULL, /* nodeDeviceReset */
NULL, /* domainMigratePrepareTunnel */
NULL, /* isEncrypted */
NULL, /* isSecure */
NULL, /* domainIsActive */
NULL, /* domainIsPersistent */
};
int

View File

@ -7465,6 +7465,10 @@ static virDriver qemuDriver = {
qemudNodeDeviceReAttach, /* nodeDeviceReAttach */
qemudNodeDeviceReset, /* nodeDeviceReset */
qemudDomainMigratePrepareTunnel, /* domainMigratePrepareTunnel */
NULL, /* isEncrypted */
NULL, /* isSecure */
NULL, /* domainIsActive */
NULL, /* domainIsPersistent */
};

View File

@ -8554,6 +8554,10 @@ static virDriver remote_driver = {
remoteNodeDeviceReAttach, /* nodeDeviceReAttach */
remoteNodeDeviceReset, /* nodeDeviceReset */
remoteDomainMigratePrepareTunnel, /* domainMigratePrepareTunnel */
NULL, /* isEncrypted */
NULL, /* isSecure */
NULL, /* domainIsActive */
NULL, /* domainIsPersistent */
};
static virNetworkDriver network_driver = {
@ -8575,6 +8579,8 @@ static virNetworkDriver network_driver = {
.networkGetBridgeName = remoteNetworkGetBridgeName,
.networkGetAutostart = remoteNetworkGetAutostart,
.networkSetAutostart = remoteNetworkSetAutostart,
.networkIsActive = NULL,
.networkIsPersistent = NULL,
};
static virInterfaceDriver interface_driver = {
@ -8592,6 +8598,7 @@ static virInterfaceDriver interface_driver = {
.interfaceUndefine = remoteInterfaceUndefine,
.interfaceCreate = remoteInterfaceCreate,
.interfaceDestroy = remoteInterfaceDestroy,
.interfaceIsActive = NULL, /* interfaceIsActive */
};
static virStorageDriver storage_driver = {
@ -8630,6 +8637,9 @@ static virStorageDriver storage_driver = {
.volGetInfo = remoteStorageVolGetInfo,
.volGetXMLDesc = remoteStorageVolDumpXML,
.volGetPath = remoteStorageVolGetPath,
.poolIsActive = NULL, /* poolIsActive */
.poolIsPersistent = NULL, /* poolIsEncrypted */
};
static virSecretDriver secret_driver = {

View File

@ -5064,6 +5064,10 @@ static virDriver testDriver = {
NULL, /* nodeDeviceReAttach */
NULL, /* nodeDeviceReset */
NULL, /* domainMigratePrepareTunnel */
NULL, /* isEncrypted */
NULL, /* isSecure */
NULL, /* domainIsActive */
NULL, /* domainIsPersistent */
};
static virNetworkDriver testNetworkDriver = {
@ -5085,6 +5089,8 @@ static virNetworkDriver testNetworkDriver = {
testNetworkGetBridgeName, /* networkGetBridgeName */
testNetworkGetAutostart, /* networkGetAutostart */
testNetworkSetAutostart, /* networkSetAutostart */
NULL, /* networkIsActive */
NULL, /* networkIsPersistent */
};
static virInterfaceDriver testInterfaceDriver = {
@ -5102,6 +5108,7 @@ static virInterfaceDriver testInterfaceDriver = {
testInterfaceUndefine, /* interfaceUndefine */
testInterfaceCreate, /* interfaceCreate */
testInterfaceDestroy, /* interfaceDestroy */
NULL, /* interfaceIsActive */
};
@ -5142,6 +5149,9 @@ static virStorageDriver testStorageDriver = {
.volGetInfo = testStorageVolumeGetInfo,
.volGetXMLDesc = testStorageVolumeGetXMLDesc,
.volGetPath = testStorageVolumeGetPath,
.poolIsActive = NULL, /* poolIsActive */
.poolIsPersistent = NULL, /* poolIsPersistent */
};
static virDeviceMonitor testDevMonitor = {

View File

@ -1824,6 +1824,10 @@ static virDriver umlDriver = {
NULL, /* nodeDeviceReAttach */
NULL, /* nodeDeviceReset */
NULL, /* domainMigratePrepareTunnel */
NULL, /* isEncrypted */
NULL, /* isSecure */
NULL, /* domainIsActive */
NULL, /* domainIsPersistent */
};

View File

@ -6469,6 +6469,10 @@ virDriver NAME(Driver) = {
NULL, /* nodeDeviceReAttach */
NULL, /* nodeDeviceReset */
NULL, /* domainMigratePrepareTunnel */
NULL, /* isEncrypted */
NULL, /* isSecure */
NULL, /* domainIsActive */
NULL, /* domainIsPerrsistent */
};
virNetworkDriver NAME(NetworkDriver) = {

View File

@ -1709,6 +1709,10 @@ static virDriver xenUnifiedDriver = {
xenUnifiedNodeDeviceReAttach, /* nodeDeviceReAttach */
xenUnifiedNodeDeviceReset, /* nodeDeviceReset */
NULL, /* domainMigratePrepareTunnel */
NULL, /* isEncrypted */
NULL, /* isSecure */
NULL, /* domainIsActive */
NULL, /* domainIsPersistent */
};
/**