mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
add virDomainGetOSType() + small code refactoring
This commit is contained in:
@@ -84,6 +84,14 @@ struct _virDomain {
|
||||
int handle; /* internal handle for the dmonain ID */
|
||||
};
|
||||
|
||||
/*
|
||||
* Internal routines
|
||||
*/
|
||||
char * virDomainGetVM (virDomainPtr domain);
|
||||
char * virDomainGetVMInfo (virDomainPtr domain,
|
||||
const char *vm,
|
||||
const char *name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
100
src/libvir.c
100
src/libvir.c
@@ -466,6 +466,83 @@ done:
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virDomainGetVM:
|
||||
* @domain: a domain object
|
||||
*
|
||||
* Internal API extracting a xenstore vm path.
|
||||
*
|
||||
* Returns the new string or NULL in case of error
|
||||
*/
|
||||
char *
|
||||
virDomainGetVM(virDomainPtr domain)
|
||||
{
|
||||
struct xs_transaction_handle* t;
|
||||
char *vm;
|
||||
char query[200];
|
||||
unsigned int len;
|
||||
|
||||
if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC))
|
||||
return(NULL);
|
||||
if ((domain->conn == NULL) || (domain->conn->magic != VIR_CONNECT_MAGIC))
|
||||
return(NULL);
|
||||
|
||||
t = xs_transaction_start(domain->conn->xshandle);
|
||||
if (t == NULL)
|
||||
return(NULL);
|
||||
|
||||
snprintf(query, 199, "/local/domain/%d/vm",
|
||||
virDomainGetID(domain));
|
||||
query[199] = 0;
|
||||
|
||||
vm = xs_read(domain->conn->xshandle, t, &query[0], &len);
|
||||
|
||||
if (t != NULL)
|
||||
xs_transaction_end(domain->conn->xshandle, t, 0);
|
||||
|
||||
return(vm);
|
||||
}
|
||||
|
||||
/**
|
||||
* virDomainGetVMInfo:
|
||||
* @domain: a domain object
|
||||
* @vm: the xenstore vm path
|
||||
* @name: the value's path
|
||||
*
|
||||
* Internal API extracting one information the device used
|
||||
* by the domain from xensttore
|
||||
*
|
||||
* Returns the new string or NULL in case of error
|
||||
*/
|
||||
char *
|
||||
virDomainGetVMInfo(virDomainPtr domain, const char *vm,
|
||||
const char *name) {
|
||||
struct xs_transaction_handle* t;
|
||||
char s[256];
|
||||
char *ret = NULL;
|
||||
unsigned int len = 0;
|
||||
|
||||
if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC))
|
||||
return(NULL);
|
||||
if ((domain->conn == NULL) || (domain->conn->magic != VIR_CONNECT_MAGIC))
|
||||
return(NULL);
|
||||
|
||||
snprintf(s, 255, "%s/%s", vm, name);
|
||||
s[255] = 0;
|
||||
|
||||
t = xs_transaction_start(domain->conn->xshandle);
|
||||
if (t == NULL)
|
||||
goto done;
|
||||
|
||||
ret = xs_read(domain->conn->xshandle, t, &s[0], &len);
|
||||
|
||||
done:
|
||||
if (t != NULL)
|
||||
xs_transaction_end(domain->conn->xshandle, t, 0);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* virDomainLookupByID:
|
||||
* @conn: pointer to the hypervisor connection
|
||||
@@ -695,6 +772,29 @@ virDomainGetID(virDomainPtr domain) {
|
||||
return(domain->handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* virDomainGetOSType:
|
||||
* @domain: a domain object
|
||||
*
|
||||
* Get the type of domain operation system.
|
||||
*
|
||||
* Returns the new string or NULL in case of error
|
||||
*/
|
||||
char *
|
||||
virDomainGetOSType(virDomainPtr domain) {
|
||||
char *vm, *str = NULL;
|
||||
|
||||
if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC))
|
||||
return(NULL);
|
||||
|
||||
vm = virDomainGetVM(domain);
|
||||
if (vm) {
|
||||
str = virDomainGetVMInfo(domain, vm, "image/ostype");
|
||||
free(vm);
|
||||
}
|
||||
return(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* virDomainGetMaxMemory:
|
||||
* @domain: a domain object or NULL
|
||||
|
||||
@@ -14,12 +14,13 @@
|
||||
virDomainGetInfo;
|
||||
virDomainGetMaxMemory;
|
||||
virDomainGetName;
|
||||
virDomainGetOSType;
|
||||
virDomainGetXMLDesc;
|
||||
virDomainLookupByID;
|
||||
virDomainLookupByName;
|
||||
virDomainResume;
|
||||
virDomainSetMaxMemory;
|
||||
virDomainSuspend;
|
||||
virDomainGetXMLDesc;
|
||||
virGetVersion;
|
||||
local: *;
|
||||
};
|
||||
|
||||
16
src/virsh.c
16
src/virsh.c
@@ -482,6 +482,7 @@ cmdDinfo(vshControl *ctl, vshCmd *cmd) {
|
||||
virDomainInfo info;
|
||||
virDomainPtr dom;
|
||||
int ret = TRUE;
|
||||
char *str;
|
||||
|
||||
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
|
||||
return FALSE;
|
||||
@@ -489,13 +490,20 @@ cmdDinfo(vshControl *ctl, vshCmd *cmd) {
|
||||
if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
|
||||
return FALSE;
|
||||
|
||||
vshPrint(ctl, VSH_MESG, "%-15s %d\n", "Id:",
|
||||
virDomainGetID(dom));
|
||||
vshPrint(ctl, VSH_MESG, "%-15s %s\n", "Name:",
|
||||
virDomainGetName(dom));
|
||||
|
||||
if ((str=virDomainGetOSType(dom))) {
|
||||
vshPrint(ctl, VSH_MESG, "%-15s %s\n", "OS Type:", str);
|
||||
free(str);
|
||||
}
|
||||
|
||||
if (virDomainGetInfo(dom, &info)==0) {
|
||||
vshPrint(ctl, VSH_MESG, "%-15s %d\n", "Id:",
|
||||
virDomainGetID(dom));
|
||||
vshPrint(ctl, VSH_MESG, "%-15s %s\n", "Name:",
|
||||
virDomainGetName(dom));
|
||||
vshPrint(ctl, VSH_MESG, "%-15s %s\n", "State:",
|
||||
vshDomainStateToString(info.state));
|
||||
|
||||
vshPrint(ctl, VSH_MESG, "%-15s %d\n", "CPU(s):",
|
||||
info.nrVirtCpu);
|
||||
|
||||
|
||||
59
src/xml.c
59
src/xml.c
@@ -167,39 +167,6 @@ done:
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* virDomainGetVMInfo:
|
||||
* @domain: a domain object
|
||||
* @vm: the xenstore vm path
|
||||
* @name: the value's path
|
||||
*
|
||||
* Extract one information the device used by the domain from xensttore
|
||||
*
|
||||
* Returns the new string or NULL in case of error
|
||||
*/
|
||||
static char *
|
||||
virDomainGetVMInfo(virDomainPtr domain, const char *vm,
|
||||
const char *name) {
|
||||
struct xs_transaction_handle* t;
|
||||
char s[256];
|
||||
char *ret = NULL;
|
||||
unsigned int len = 0;
|
||||
|
||||
snprintf(s, 255, "%s/%s", vm, name);
|
||||
s[255] = 0;
|
||||
|
||||
t = xs_transaction_start(domain->conn->xshandle);
|
||||
if (t == NULL)
|
||||
goto done;
|
||||
|
||||
ret = xs_read(domain->conn->xshandle, t, &s[0], &len);
|
||||
|
||||
done:
|
||||
if (t != NULL)
|
||||
xs_transaction_end(domain->conn->xshandle, t, 0);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* virDomainGetXMLDevice:
|
||||
* @domain: a domain object
|
||||
@@ -419,6 +386,9 @@ done:
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* virDomainGetXMLBoot:
|
||||
* @domain: a domain object
|
||||
@@ -430,34 +400,15 @@ done:
|
||||
*/
|
||||
static int
|
||||
virDomainGetXMLBoot(virDomainPtr domain, virBufferPtr buf) {
|
||||
struct xs_transaction_handle* t;
|
||||
char *vm, *str;
|
||||
char query[200];
|
||||
virConnectPtr conn;
|
||||
int len;
|
||||
|
||||
conn = domain->conn;
|
||||
|
||||
if ((conn == NULL) || (conn->magic != VIR_CONNECT_MAGIC))
|
||||
if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC))
|
||||
return(-1);
|
||||
|
||||
t = xs_transaction_start(conn->xshandle);
|
||||
if (t == NULL)
|
||||
return(-1);
|
||||
|
||||
snprintf(query, 199, "/local/domain/%d/vm",
|
||||
virDomainGetID(domain));
|
||||
query[199] = 0;
|
||||
|
||||
vm = xs_read(domain->conn->xshandle, t, &query[0], &len);
|
||||
|
||||
if (t != NULL)
|
||||
xs_transaction_end(domain->conn->xshandle, t, 0);
|
||||
|
||||
vm = virDomainGetVM(domain);
|
||||
if (vm == NULL)
|
||||
return(-1);
|
||||
|
||||
|
||||
virBufferAdd(buf, " <os>\n", 7);
|
||||
str = virDomainGetVMInfo(domain, vm, "image/ostype");
|
||||
if (str != NULL) {
|
||||
|
||||
Reference in New Issue
Block a user