]> xenbits.xensource.com Git - libvirt.git/commitdiff
Add <title> and <description> for Network Objects
authorK Shiva Kiran <shiva_kr@riseup.net>
Wed, 16 Aug 2023 18:47:09 +0000 (00:17 +0530)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 25 Aug 2023 10:36:37 +0000 (12:36 +0200)
This patch adds new elements <title> and <description> to the Network XML.
- The <title> attribute holds a short title defined by the user and
  cannot contain newlines.
- The <description> attribute holds any documentation that the user
  wants to store.
- Schema definitions of <title> and <description> have been moved from
  domaincommon.rng to basictypes.rng for use by network and future objects.
- Added Network XML parser logic for the above.

Signed-off-by: K Shiva Kiran <shiva_kr@riseup.net>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
docs/formatnetwork.rst
src/conf/network_conf.c
src/conf/network_conf.h
src/conf/schemas/basictypes.rng
src/conf/schemas/domaincommon.rng
src/conf/schemas/network.rng

index b5dc29db07affa61206a5e94366a5787cf46838c..c54d53070ae790769d85d2b407fa05f755584a13 100644 (file)
@@ -30,6 +30,8 @@ The first elements provide basic metadata about the virtual network.
    <network ipv6='yes' trustGuestRxFilters='no'>
      <name>default</name>
      <uuid>3e3fce45-4f53-4fa7-bb32-11f34168b82b</uuid>
+     <title>A short description - title - of the network</title>
+     <description>Some human readable description</description>
      <metadata>
        <app1:foo xmlns:app1="http://app1.org/app1/">..</app1:foo>
        <app2:bar xmlns:app2="http://app1.org/app2/">..</app2:bar>
@@ -47,6 +49,7 @@ The first elements provide basic metadata about the virtual network.
    the virtual network. The format must be RFC 4122 compliant, eg
    ``3e3fce45-4f53-4fa7-bb32-11f34168b82b``. If omitted when defining/creating a
    new network, a random UUID is generated. :since:`Since 0.3.0`
+``metadata``
    The ``metadata`` node can be used by applications to store custom metadata in
    the form of XML nodes/trees. Applications must use custom namespaces on their
    XML nodes/trees, with only one top-level element per namespace (if the
@@ -65,6 +68,14 @@ The first elements provide basic metadata about the virtual network.
    documentation for more details. Note that an explicit setting of this
    attribute in a portgroup or the individual domain interface will override the
    setting in the network.
+``title``
+   The optional element ``title`` provides space for a short description of the
+   network. The title should not contain any newlines. :since:`Since 9.7.0` .
+``description``
+   The content of the ``description`` element provides a human readable
+   description of the network. This data is not used by libvirt in any
+   way, it can contain any information the user wants. :since:`Since 9.7.0`
+
 
 Connectivity
 ~~~~~~~~~~~~
index 3e137cb562b3bbe3cc0173420768d4c3f38e5560..262e9a9fc794f92a1e50ab063fc70a04d102272e 100644 (file)
@@ -281,6 +281,8 @@ virNetworkDefFree(virNetworkDef *def)
     virNetDevBandwidthFree(def->bandwidth);
     virNetDevVlanClear(&def->vlan);
 
+    g_free(def->title);
+    g_free(def->description);
     xmlFreeNode(def->metadata);
 
     if (def->namespaceData && def->ns.free)
@@ -1599,6 +1601,17 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
         def->uuid_specified = true;
     }
 
+    /* Extract short description of network (title) */
+    def->title = virXPathString("string(./title[1])", ctxt);
+    if (def->title && strchr(def->title, '\n')) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("Network title can't contain newlines"));
+        return NULL;
+    }
+
+    /* Extract documentation if present */
+    def->description = virXPathString("string(./description[1])", ctxt);
+
     /* check if definitions with no IPv6 gateway addresses is to
      * allow guest-to-guest communications.
      */
@@ -2311,6 +2324,11 @@ virNetworkDefFormatBuf(virBuffer *buf,
     virUUIDFormat(uuid, uuidstr);
     virBufferAsprintf(buf, "<uuid>%s</uuid>\n", uuidstr);
 
+    virBufferEscapeString(buf, "<title>%s</title>\n", def->title);
+
+    virBufferEscapeString(buf, "<description>%s</description>\n",
+                          def->description);
+
     if (virXMLFormatMetadata(buf, def->metadata) < 0)
         return -1;
 
index 2b2e9d15f03be1d1acf33b22bdf859cedc61ff29..5a1bdb12845755e8bd9f54129f153454972fc9dc 100644 (file)
@@ -249,6 +249,8 @@ struct _virNetworkDef {
     unsigned char uuid[VIR_UUID_BUFLEN];
     bool uuid_specified;
     char *name;
+    char *title;
+    char *description;
     int   connections; /* # of guest interfaces connected to this network */
 
     char *bridge;       /* Name of bridge device */
index 2d6f1a2c84b72a28ab64c3a1b734b3da294de409..26eb538077c3eb17e3170b4f5c152780a7f093fd 100644 (file)
     </choice>
   </define>
 
+  <!--
+    title and description element, may be placed anywhere under the root
+    -->
+  <define name="title">
+    <element name="title">
+      <ref name="objectNameWithSlash"/>
+    </element>
+  </define>
+
+  <define name="description">
+    <element name="description">
+      <text/>
+    </element>
+  </define>
+
   <define name="metadata">
     <element name="metadata">
       <zeroOrMore>
index c2f56b04901c0b45e2c1cacbd087cc20f2e42bed..2556ac01edc99b9971a7dc133bcd7b86de747068 100644 (file)
@@ -8,21 +8,6 @@
   <include href="nwfilter_params.rng"/>
   <include href="privatedata.rng"/>
 
-  <!--
-    description and title element, may be placed anywhere under the root
-    -->
-  <define name="description">
-    <element name="description">
-      <text/>
-    </element>
-  </define>
-
-  <define name="title">
-    <element name="title">
-      <ref name="objectNameWithSlash"/>
-    </element>
-  </define>
-
   <define name="createMode">
     <data type="unsignedInt">
       <param name="pattern">0[0-7]{3}|[0-7]{1,3}</param>
index 4317572208258edd58b86c8080377f004c04bc47..cda174ab4be224c2a82e1ef109005343cfc3d819 100644 (file)
           <text/>
         </element>
 
+        <!-- <title> element -->
+        <optional>
+          <ref name="title"/>
+        </optional>
+
+        <!-- <description> element -->
+        <optional>
+          <ref name="description"/>
+        </optional>
+
         <!-- <metadata> element -->
         <optional>
           <ref name="metadata"/>