[PATCH] XML: Changing the 'interface' tag

Jiri Pirko jpirko at redhat.com
Fri May 3 12:42:24 UTC 2013


applied.

Would be great to fix the recipes as well. Please send followup patch
for it.

Thanks.


Fri, May 03, 2013 at 02:14:02PM CEST, rpazdera at redhat.com wrote:
>This commit removes the <interface> tag from both the recipe and the
>slavemachine config files. Now the interface tag's names are based
>on their type.
>
>For example an interface with type="bond" will now be represented by
>a tag <bond ...>.
>
>A slight cleanup of the slavemachine parser was done along with this
>patch.
>---
> lnst/Controller/RecipeParse.py       |   18 ++++++++--
> lnst/Controller/SlaveMachineParse.py |   62 ++++++++-------------------------
> 2 files changed, 29 insertions(+), 51 deletions(-)
>
>diff --git a/lnst/Controller/RecipeParse.py b/lnst/Controller/RecipeParse.py
>index fe155cb..8445a0e 100644
>--- a/lnst/Controller/RecipeParse.py
>+++ b/lnst/Controller/RecipeParse.py
>@@ -97,7 +97,12 @@ class FirstPass(LnstParser):
> 
>     def _interfaces(self, node, params):
>         params = {"id": params["id"]}
>-        scheme = {"interface": self._interface}
>+        scheme = {"eth": self._interface,
>+                  "bond": self._interface,
>+                  "team": self._interface,
>+                  "vlan": self._interface,
>+                  "macvlan": self._interface,
>+                  "bridge": self._interface}
>         self._process_child_nodes(node, scheme, params)
> 
>     def _interface(self, node, params):
>@@ -105,7 +110,7 @@ class FirstPass(LnstParser):
>         machine = self._data["machines"][m_id]
> 
>         if_id = self._get_attribute(node, "id")
>-        if_type = self._get_attribute(node, "type")
>+        if_type = node.tagName
> 
>         if if_id in machine["interfaces"]:
>             msg = "Two interfaces with the same id '%s', " % if_id
>@@ -205,7 +210,12 @@ class MachineParse(LnstParser):
>         self._process_child_nodes(node, scheme)
> 
>     def _interfaces(self, node, params):
>-        scheme = {"interface": self._interface}
>+        scheme = {"eth": self._interface,
>+                  "bond": self._interface,
>+                  "team": self._interface,
>+                  "vlan": self._interface,
>+                  "macvlan": self._interface,
>+                  "bridge": self._interface}
>         self._process_child_nodes(node, scheme)
> 
>     def _interface(self, node, params):
>@@ -232,7 +242,7 @@ class InterfaceParse(LnstParser):
>             self._machine["interfaces"][if_id] = {}
>         self._iface = iface = self._machine["interfaces"][if_id]
> 
>-        iface["type"] = self._get_attribute(node, "type")
>+        iface["type"] = node.tagName
> 
>         scheme = {"addresses": self._addresses}
>         if iface["type"] in ["bond", "bridge", "vlan", "macvlan", "team"]:
>diff --git a/lnst/Controller/SlaveMachineParse.py b/lnst/Controller/SlaveMachineParse.py
>index 20915c4..4be2dc5 100644
>--- a/lnst/Controller/SlaveMachineParse.py
>+++ b/lnst/Controller/SlaveMachineParse.py
>@@ -47,67 +47,35 @@ class SlaveMachineParse(LnstParser):
>         subparser.parse(node)
> 
>     def _interfaces(self, node, params):
>-        scheme = {"interface": self._interface,
>-                  "libvirt_create": self._libvirt_create}
>+        scheme = {"eth": self._eth}
> 
>-        new_params = {"create": None}
>-        self._process_child_nodes(node, scheme, new_params)
>+        try:
>+            self._process_child_nodes(node, scheme)
>+        except XmlProcessingError as err:
>+            msg = "Interface type other than 'eth' is not allowed here. " \
>+                  "Other types must be configured in LNST recipes directly."
>+            logging.error(msg)
>+            raise
> 
>-    def _libvirt_create(self, node, params):
>-        scheme = {"interface": self._interface}
>-
>-        new_params = {"create": "libvirt"}
>-        self._process_child_nodes(node, scheme, new_params)
>-
>-    def _interface(self, node, params):
>+    def _eth(self, node, params):
>         machine = self._machine
>         iface_id = self._get_attribute(node, "id")
> 
>         iface = machine["interfaces"][iface_id] = {}
>-        iface["create"] = params["create"]
>         iface["network"] = self._get_attribute(node, "network")
>         iface["params"] = {}
>+        iface["type"] = "eth"
> 
>         # parse interface parameters
>         scheme = {"params": self._params}
>         params = {"target": iface["params"]}
>         self._process_child_nodes(node, scheme, params)
> 
>-        if "type" not in iface["params"]:
>-            msg = "Missing required parameter 'type'"
>-            raise XmlProcessingError(msg, node)
>-
>-        iface["type"] = iface["params"]["type"]
>-        if iface["type"] not in ["eth"]:
>-            msg = "Interface type '%s' is not allowed here. " \
>-                  "Interface types other than 'eth' mus be configured " \
>-                  "in LNST recipes directly." % iface["type"]
>-            raise XmlProcessingError(msg, node)
>-
>-        # hwaddr parameter is optional for dynamic interface,
>-        # but it is required by non-dynamic interfaces
>-        if iface["create"] and "hwaddr" in iface["params"]:
>-                iface["hwaddr"] = normalize_hwaddr(iface["params"]["hwaddr"])
>+        if "hwaddr" in iface["params"]:
>+            iface["hwaddr"] = normalize_hwaddr(iface["params"]["hwaddr"])
>         else:
>-            if "hwaddr" in iface["params"]:
>-                iface["hwaddr"] = normalize_hwaddr(iface["params"]["hwaddr"])
>-            else:
>-                msg = "Missing required parameter 'hwaddr'"
>-                raise XmlProcessingError(msg, node)
>+            msg = "Missing required parameter 'hwaddr'"
>+            raise XmlProcessingError(msg, node)
> 
>-        # name parameter is only valid when the interface is not dynamic
>         if "name" in iface["params"]:
>-            if iface["create"]:
>-                msg = "'name' parameter is not valid with dynamic interfaces"
>-                raise XmlProcessingError(msg, node)
>-            else:
>-                iface["name"] = iface["params"]["name"]
>-
>-        # bridge parameter is valid only when the interface is dynamic
>-        if "libvirt_bridge" in iface["params"]:
>-            if iface["create"] == "libvirt":
>-                iface["libvirt_bridge"] = iface["params"]["libvirt_bridge"]
>-            else:
>-                msg = "'libvirt_bridge' parameter is not valid with" \
>-                      "dynamic ifaceices"
>-                raise XmlProcessingError(msg, node)
>+            iface["name"] = iface["params"]["name"]
>-- 
>1.7.7.6
>
>_______________________________________________
>LNST-developers mailing list
>LNST-developers at lists.fedorahosted.org
>https://lists.fedorahosted.org/mailman/listinfo/lnst-developers


More information about the LNST-developers mailing list