[libvirt] [PATCH 8/8] virsh: Add support for virDomainGetDescription api

Peter Krempa pkrempa at redhat.com
Wed Jan 18 14:24:05 UTC 2012


This patch modifies the description parser to use the new API if
available with option to fall back to XML parsing.
---
 tools/virsh.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 976c2d9..08bfb27 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -17851,9 +17851,29 @@ vshGetDomainDescription(vshControl *ctl, virDomainPtr dom, bool title,
 {
     char *desc = NULL;
     char *domxml = NULL;
+    virErrorPtr err = NULL;
     xmlDocPtr doc = NULL;
     xmlXPathContextPtr ctxt = NULL;
+    int apiflags = flags;

+    if (title)
+        apiflags |= VIR_DOMAIN_DESCRIPTION_TITLE;
+
+    if ((desc = virDomainGetDescription(dom, apiflags))) {
+        return desc;
+    } else {
+        err = virGetLastError();
+
+        if (err && err->code == VIR_ERR_OPERATION_FAILED) {
+            desc = vshStrdup(ctl, "");
+            return desc;
+        }
+
+        if (err &&  err->code != VIR_ERR_NO_SUPPORT)
+            return desc;
+    }
+
+    /* fall back to xml */
     /* get domains xml description and extract the title/description */
     if (!(domxml = virDomainGetXMLDesc(dom, flags))) {
         vshError(ctl, "%s", _("Failed to retrieve domain XML"));
-- 
1.7.3.4




More information about the libvir-list mailing list