diff options
author | Karel Zak <kzak@redhat.com> | 2005-12-16 00:51:27 +0000 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2005-12-16 00:51:27 +0000 |
commit | d2dc6bf826bb107bdc5174237ffd0fdd33f59fba (patch) | |
tree | 680b19d1c1f0c074ee1a6f112663f5df76d08e54 | |
parent | remove --id/name from virsh (diff) | |
download | libvirt-d2dc6bf826bb107bdc5174237ffd0fdd33f59fba.tar.gz libvirt-d2dc6bf826bb107bdc5174237ffd0fdd33f59fba.tar.bz2 libvirt-d2dc6bf826bb107bdc5174237ffd0fdd33f59fba.zip |
add virDomainGetOSType() + small code refactoring
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | include/libvir.h.in | 5 | ||||
-rw-r--r-- | src/internal.h | 8 | ||||
-rw-r--r-- | src/libvir.c | 100 | ||||
-rw-r--r-- | src/libvir_sym.version | 3 | ||||
-rw-r--r-- | src/virsh.c | 16 | ||||
-rw-r--r-- | src/xml.c | 59 |
8 files changed, 141 insertions, 61 deletions
@@ -1 +1,2 @@ Daniel Veillard <veillard@redhat.com> or <daniel@veillard.com> +Karel Zak <kzak@redhat.com> @@ -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> diff --git a/include/libvir.h.in b/include/libvir.h.in index ce1347bc7..f560e9db3 100644 --- a/include/libvir.h.in +++ b/include/libvir.h.in @@ -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 } diff --git a/src/internal.h b/src/internal.h index af3963805..a4c1d1488 100644 --- a/src/internal.h +++ b/src/internal.h @@ -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 */ diff --git a/src/libvir.c b/src/libvir.c index 4e50e7e46..937468b0d 100644 --- a/src/libvir.c +++ b/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 @@ -696,6 +773,29 @@ virDomainGetID(virDomainPtr domain) { } /** + * 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 * diff --git a/src/libvir_sym.version b/src/libvir_sym.version index e62bdee77..c28e4e65a 100644 --- a/src/libvir_sym.version +++ b/src/libvir_sym.version @@ -14,12 +14,13 @@ virDomainGetInfo; virDomainGetMaxMemory; virDomainGetName; + virDomainGetOSType; + virDomainGetXMLDesc; virDomainLookupByID; virDomainLookupByName; virDomainResume; virDomainSetMaxMemory; virDomainSuspend; - virDomainGetXMLDesc; virGetVersion; local: *; }; diff --git a/src/virsh.c b/src/virsh.c index 3fa66b9ec..bc0e038e6 100644 --- a/src/virsh.c +++ b/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); @@ -168,39 +168,6 @@ done: } /** - * 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 * @buf: the output buffer 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) { |