mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
add virDomainGetOSType() + small code refactoring
This commit is contained in:
parent
4dcc4c2d8b
commit
d2dc6bf826
1
AUTHORS
1
AUTHORS
@ -1 +1,2 @@
|
||||
Daniel Veillard <veillard@redhat.com> or <daniel@veillard.com>
|
||||
Karel Zak <kzak@redhat.com>
|
||||
|
10
ChangeLog
10
ChangeLog
@ -1,8 +1,14 @@
|
||||
Fri Dec 16 01:43:18 CET 2005 Karel Zak <kzak@redhat.com>
|
||||
|
||||
* include/libvir.h.in: add missing declaration of virDomainGetXMLDesc()
|
||||
* include/libvir.h.in src/libvir.c src/virsh src/libvir_sym.version: add
|
||||
virDomainGetOSType()
|
||||
* src/internal.h src/libvir.c src/xml.c: add internal function virDomainGetVM(),
|
||||
move virDomainGetVMInfo() from src/xml.c
|
||||
|
||||
Thu Dec 15 17:56:27 CET 2005 Karel Zak <kzak@redhat.com>
|
||||
|
||||
* src/virsh.c: remove --id / --name options
|
||||
* include/libvir.h: add missing declaration of virDomainGetXMLDesc()
|
||||
|
||||
|
||||
Wed Dec 14 16:28:24 CET 2005 Daniel Veillard <veillard@redhat.com>
|
||||
|
||||
|
@ -180,9 +180,14 @@ int virDomainGetInfo (virDomainPtr domain,
|
||||
*/
|
||||
const char * virDomainGetName (virDomainPtr domain);
|
||||
unsigned int virDomainGetID (virDomainPtr domain);
|
||||
char * virDomainGetOSType (virDomainPtr domain);
|
||||
unsigned long virDomainGetMaxMemory (virDomainPtr domain);
|
||||
int virDomainSetMaxMemory (virDomainPtr domain,
|
||||
unsigned long memory);
|
||||
/*
|
||||
* XML domain description
|
||||
*/
|
||||
char * virDomainGetXMLDesc (virDomainPtr domain, int flags);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user