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

[libvirt] [PATCH 3/2] Make type & startmode optional in toplevel interface definitions.



(Yes, you read the subject correctly - 3 of 2!)

The minimal XML returned from ncf_if_xml_state() doesn't contain these
attributes, and it was preventing it from passing through the
parse/format step (making my patches from earlier today unusable).

Because adding an "UNSPECIFIED" value to the enums for type and
startmode would have made it possible for someone to send xml with,
eg, type="unspecified" (which we don't want), I've followed the
convention already used for the dhcp "peerdns" attribute - if it isn't
specified, the value is -1.

If anyone dislikes this use of an absolute, non-self-documenting
value, I'll figure out a more elegant way. This at least makes the
previous set of patches usable, though ;-)
---
 src/conf/interface_conf.c |   38 ++++++++++++++------------------------
 1 files changed, 14 insertions(+), 24 deletions(-)

diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c
index b1926c1..a5aa395 100644
--- a/src/conf/interface_conf.c
+++ b/src/conf/interface_conf.c
@@ -152,11 +152,9 @@ virInterfaceDefParseStartMode(virConnectPtr conn, virInterfaceDefPtr def,
 
     tmp = virXPathString(conn, "string(./start/@mode)", ctxt);
     if (tmp == NULL) {
-        virInterfaceReportError(conn, VIR_ERR_XML_ERROR,
-                        "%s", _("interface misses the start mode attribute"));
-        return(-1);
+        def->startmode = -1; /* not specified */
     }
-    if (STREQ(tmp, "onboot"))
+    else if (STREQ(tmp, "onboot"))
         def->startmode = VIR_INTERFACE_START_ONBOOT;
     else if (STREQ(tmp, "hotplug"))
         def->startmode = VIR_INTERFACE_START_HOTPLUG;
@@ -741,18 +739,7 @@ virInterfaceDefParseXML(virConnectPtr conn, xmlXPathContextPtr ctxt) {
 
     /* check @type */
     tmp = virXPathString(conn, "string(./@type)", ctxt);
-    if (tmp == NULL) {
-        virInterfaceReportError(conn, VIR_ERR_XML_ERROR,
-                                "%s", _("interface misses the type attribute"));
-        return(NULL);
-    }
     type = virInterfaceTypeFromString(tmp);
-    if (type == -1) {
-        virInterfaceReportError(conn, VIR_ERR_XML_ERROR,
-                                _("unknown interface type %s"), tmp);
-        VIR_FREE(tmp);
-        return(NULL);
-    }
     VIR_FREE(tmp);
 
     if (VIR_ALLOC(def) < 0) {
@@ -761,6 +748,7 @@ virInterfaceDefParseXML(virConnectPtr conn, xmlXPathContextPtr ctxt) {
     }
     def->type = type;
     switch (type) {
+        case -1:
         case VIR_INTERFACE_TYPE_ETHERNET:
             if (virInterfaceDefParseBasicAttrs(conn, def, ctxt) < 0)
                 goto error;
@@ -1202,9 +1190,7 @@ virInterfaceStartmodeDefFormat(virConnectPtr conn, virBufferPtr buf,
             mode = "hotplug";
             break;
         default:
-            virInterfaceReportError(conn, VIR_ERR_INTERNAL_ERROR,
-                        "%s", _("virInterfaceDefFormat unknown startmode"));
-            return -1;
+            return 0;
     }
     virBufferVSprintf(buf, "  <start mode='%s'/>\n", mode);
     return(0);
@@ -1223,18 +1209,22 @@ char *virInterfaceDefFormat(virConnectPtr conn,
         goto cleanup;
     }
 
-    if (!(type = virInterfaceTypeToString(def->type))) {
-        virInterfaceReportError(conn, VIR_ERR_INTERNAL_ERROR,
-                        _("unexpected interface type %d"), def->type);
-        goto cleanup;
+    if (def->type == -1) {
+        virBufferAddLit(&buf, "<interface ");
+    } else {
+        if (!(type = virInterfaceTypeToString(def->type))) {
+            virInterfaceReportError(conn, VIR_ERR_INTERNAL_ERROR,
+                                    _("unexpected interface type %d"), def->type);
+            goto cleanup;
+        }
+        virBufferVSprintf(&buf, "<interface type='%s' ", type);
     }
-
-    virBufferVSprintf(&buf, "<interface type='%s' ", type);
     if (def->name != NULL)
         virBufferEscapeString(&buf, "name='%s'", def->name);
     virBufferAddLit(&buf, ">\n");
 
     switch (def->type) {
+        case -1:
         case VIR_INTERFACE_TYPE_ETHERNET:
             virInterfaceStartmodeDefFormat(conn, &buf, def->startmode);
             if (def->mac != NULL)
-- 
1.6.2.5


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