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 | 16 +++ src/libvirt.c | 298 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 314 insertions(+), 0 deletions(-) diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 6186d4e..05a164b 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -1649,6 +1649,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 diff --git a/src/libvirt.c b/src/libvirt.c index 9e87900..58ea514 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -10321,3 +10321,301 @@ int virStreamFree(virStreamPtr stream) return (-1); return (0); } + + +/** + * virDomainIsActive: + * + * Determine if the domain is currently running + * + * Returns > 0 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: + * + * Determine if the domain has a persistent configuration + * + * Returns > 0 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: + * + * Determine if the network is currently running + * + * Returns > 0 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: + * + * Determine if the network has a persistent configuration + * + * Returns > 0 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: + * + * Determine if the storagepool is currently running + * + * Returns > 0 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: + * + * Determine if the storagepool has a persistent configuration + * + * Returns > 0 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: + * + * Determine if the interface is currently running + * + * Returns > 0 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: + * + * Determine if the connection to the hypervisor is encrypted + * + * Returns > 0 if running, 0 if inactive, -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: + * + * 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 > 0 if running, 0 if inactive, -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; +} -- 1.6.2.5 -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list