add virConnectNumOfDomains()

This commit is contained in:
Karel Zak 2005-12-07 11:03:24 +00:00
parent cf65cf953f
commit db4caab690
2 changed files with 34 additions and 0 deletions

View File

@ -124,6 +124,12 @@ int virConnectListDomains (virConnectPtr conn,
int *ids,
int maxids);
/*
* Number of domains
*/
int virConnectNumOfDomains (virConnectPtr conn);
/*
* Domain creation and destruction
*/

View File

@ -257,6 +257,34 @@ done:
return(ret);
}
/**
* virConnectNumOfDomains:
* @conn: pointer to the hypervisor connection
*
* Returns the number of domain found or -1 in case of error
*/
int
virConnectNumOfDomains(virConnectPtr conn) {
struct xs_transaction_handle* t;
int ret = -1;
unsigned int num;
char **idlist = NULL;
if ((conn == NULL) || (conn->magic != VIR_CONNECT_MAGIC))
return(-1);
t = xs_transaction_start(conn->xshandle);
if (t) {
idlist = xs_directory(conn->xshandle, t, "/local/domain", &num);
if (idlist) {
free(idlist);
ret = num;
}
xs_transaction_end(conn->xshandle, t, 0);
}
return(ret);
}
/**
* virDomainCreateLinux:
* @conn: pointer to the hypervisor connection