[libvirt] [PATCH 2/2] Make some vlan, bond, and bridge properties optional in the interface XML.

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

 



This is necessary because netcf does not yet know how to get this
information from the kernel, so the live config XML doesn't contain
it, leading to errors when passing it through the current libvirt parsers.
---
 src/conf/interface_conf.c |   86 ++++++++++++++++++--------------------------
 1 files changed, 35 insertions(+), 51 deletions(-)

diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c
index fc18eba..8926804 100644
--- a/src/conf/interface_conf.c
+++ b/src/conf/interface_conf.c
@@ -782,30 +782,27 @@ virInterfaceDefParseXML(virConnectPtr conn, xmlXPathContextPtr ctxt) {
             if (virInterfaceDefParseIfAdressing(conn, def, ctxt) < 0)
                 goto error;
 
-            bridge = virXPathNode(conn, "./bridge[1]", ctxt);
-            if (bridge == NULL) {
-                virInterfaceReportError(conn, VIR_ERR_XML_ERROR,
-                                        "%s", _("bridge interface misses the bridge element"));
-                goto error;
-            }
-            tmp = virXMLPropString(bridge, "stp");
             def->data.bridge.stp = -1;
-            if (tmp != NULL) {
-                if (STREQ(tmp, "on")) {
-                    def->data.bridge.stp = 1;
-                } else if (STREQ(tmp, "off")) {
-                    def->data.bridge.stp = 0;
-                } else {
-                    virInterfaceReportError(conn, VIR_ERR_XML_ERROR,
-                          _("bridge interface stp should be on or off got %s"),
-                                            tmp);
+            bridge = virXPathNode(conn, "./bridge[1]", ctxt);
+            if (bridge != NULL) {
+                tmp = virXMLPropString(bridge, "stp");
+                if (tmp != NULL) {
+                    if (STREQ(tmp, "on")) {
+                        def->data.bridge.stp = 1;
+                    } else if (STREQ(tmp, "off")) {
+                        def->data.bridge.stp = 0;
+                    } else {
+                        virInterfaceReportError(conn, VIR_ERR_XML_ERROR,
+                                                _("bridge interface stp should be on or off got %s"),
+                                                tmp);
+                        VIR_FREE(tmp);
+                        goto error;
+                    }
                     VIR_FREE(tmp);
-                    goto error;
                 }
-                VIR_FREE(tmp);
+                ctxt->node = bridge;
+                virInterfaceDefParseBridge(conn, def, ctxt);
             }
-            ctxt->node = bridge;
-            virInterfaceDefParseBridge(conn, def, ctxt);
             break;
         }
         case VIR_INTERFACE_TYPE_BOND: {
@@ -818,14 +815,11 @@ virInterfaceDefParseXML(virConnectPtr conn, xmlXPathContextPtr ctxt) {
             if (virInterfaceDefParseIfAdressing(conn, def, ctxt) < 0)
                 goto error;
             bond = virXPathNode(conn, "./bond[1]", ctxt);
-            if (bond == NULL) {
-                virInterfaceReportError(conn, VIR_ERR_XML_ERROR,
-                            "%s", _("bond interface misses the bond element"));
-                goto error;
+            if (bond != NULL) {
+                ctxt->node = bond;
+                if (virInterfaceDefParseBond(conn, def, ctxt)  < 0)
+                    goto error;
             }
-            ctxt->node = bond;
-            if (virInterfaceDefParseBond(conn, def, ctxt)  < 0)
-                goto error;
             break;
         }
         case VIR_INTERFACE_TYPE_VLAN: {
@@ -839,14 +833,11 @@ virInterfaceDefParseXML(virConnectPtr conn, xmlXPathContextPtr ctxt) {
             if (virInterfaceDefParseIfAdressing(conn, def, ctxt) < 0)
                 goto error;
             vlan = virXPathNode(conn, "./vlan[1]", ctxt);
-            if (vlan == NULL) {
-                virInterfaceReportError(conn, VIR_ERR_XML_ERROR,
-                            "%s", _("vlan interface misses the vlan element"));
-                goto error;
+            if (vlan != NULL) {
+                ctxt->node = vlan;
+                if (virInterfaceDefParseVlan(conn, def, ctxt)  < 0)
+                    goto error;
             }
-            ctxt->node = vlan;
-            if (virInterfaceDefParseVlan(conn, def, ctxt)  < 0)
-                goto error;
             break;
         }
 
@@ -1108,12 +1099,8 @@ virInterfaceBondDefFormat(virConnectPtr conn, virBufferPtr buf,
         else if (def->data.bond.validate == VIR_INTERFACE_BOND_ARP_ALL)
             virBufferAddLit(buf, " validate='all'");
         virBufferAddLit(buf, "/>\n");
-    } else {
-        virInterfaceReportError(conn, VIR_ERR_INTERNAL_ERROR,
-                                _("bond monitoring type %d unknown"),
-                                def->data.bond.monit);
-        return(-1);
     }
+
     for (i = 0;i < def->data.bond.nbItf;i++) {
         if (virInterfaceBareDevDefFormat(conn, buf, def->data.bond.itf[i]) < 0)
             ret = -1;
@@ -1126,20 +1113,17 @@ virInterfaceBondDefFormat(virConnectPtr conn, virBufferPtr buf,
 static int
 virInterfaceVlanDefFormat(virConnectPtr conn, virBufferPtr buf,
                             const virInterfaceDefPtr def) {
-    if (def->data.vlan.tag == NULL) {
-        virInterfaceReportError(conn, VIR_ERR_INTERNAL_ERROR,
-                                "%s", _("vlan misses the tag name"));
-        return(-1);
+    if (def->data.vlan.tag != NULL) {
+        virBufferVSprintf(buf, "  <vlan tag='%s'", def->data.vlan.tag);
+        if (def->data.vlan.devname != NULL) {
+            virBufferAddLit(buf, ">\n");
+            virBufferVSprintf(buf, "    <interface name='%s'/>\n",
+                              def->data.vlan.devname);
+            virBufferAddLit(buf, "  </vlan>\n");
+        } else
+            virBufferAddLit(buf, "/>\n");
     }
 
-    virBufferVSprintf(buf, "  <vlan tag='%s'", def->data.vlan.tag);
-    if (def->data.vlan.devname != NULL) {
-        virBufferAddLit(buf, ">\n");
-        virBufferVSprintf(buf, "    <interface name='%s'/>\n",
-                          def->data.vlan.devname);
-        virBufferAddLit(buf, "  </vlan>\n");
-    } else
-        virBufferAddLit(buf, "/>\n");
     return(0);
 }
 
-- 
1.6.5.15.gc274d

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]