[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] Allows for a <description> tag for domains



  https://bugzilla.redhat.com/show_bug.cgi?id=523639

feature request which makes sense to me, the simple patch attached
seems to be sufficient, one can define and have the description back
in the dump. Doesn't try to keep the location of the tag, it always
get serialized after <uuid>.
The only drawbacks I can think of are:
  - others XML formats may require the same, but honnestly it's trivial
  - machine generated description (for example if the history log of
    a domain gets stored there) could grow a lot and I wonder if we
    have a hard limit on the size when transmitting xml descriptions

Oh and I didn't found a good place to test the feature, i.e. no test
seems to parse and reserialize XML it's always about conversions.

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/
diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng
index 70e98a7..b1987e1 100644
--- a/docs/schemas/domain.rng
+++ b/docs/schemas/domain.rng
@@ -6,6 +6,16 @@
   </start>
 
   <include href='storageencryption.rng'/>
+
+  <!--
+    description element, maybe placed anywhere under the root
+    -->
+  <define name="description">
+    <element name="description">
+      <text/>
+    </element>
+  </define>
+
   <!--
       We handle only document defining a domain
     -->
@@ -14,6 +24,9 @@
       <ref name="hvs"/>
       <ref name="ids"/>
       <interleave>
+        <optional>
+          <ref name="description"/>
+        </optional>
         <ref name="os"/>
         <ref name="clock"/>
         <ref name="resources"/>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 5e37d96..868e865 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -506,6 +506,7 @@ void virDomainDefFree(virDomainDefPtr def)
     VIR_FREE(def->name);
     VIR_FREE(def->cpumask);
     VIR_FREE(def->emulator);
+    VIR_FREE(def->description);
 
     virSecurityLabelDefFree(def);
 
@@ -2534,6 +2535,9 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
         VIR_FREE(tmp);
     }
 
+    /* Extract documentation if present */
+    def->description = virXPathString(conn, "string(./description[1])", ctxt);
+
     /* Extract domain memory */
     if (virXPathULong(conn, "string(./memory[1])", ctxt, &def->maxmem) < 0) {
         virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
@@ -4197,6 +4201,10 @@ char *virDomainDefFormat(virConnectPtr conn,
     virUUIDFormat(uuid, uuidstr);
     virBufferVSprintf(&buf, "  <uuid>%s</uuid>\n", uuidstr);
 
+    if (def->description)
+        virBufferEscapeString(&buf, "  <description>%s</description>\n",
+                              def->description);
+
     virBufferVSprintf(&buf, "  <memory>%lu</memory>\n", def->maxmem);
     virBufferVSprintf(&buf, "  <currentMemory>%lu</currentMemory>\n",
                       def->memory);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 7c918a7..4b3646e 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -533,6 +533,7 @@ struct _virDomainDef {
     int id;
     unsigned char uuid[VIR_UUID_BUFLEN];
     char *name;
+    char *description;
 
     unsigned long memory;
     unsigned long maxmem;

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]