[node-patches] Change in ovirt-node[master]: ui: Fetch bridge from config

fabiand at fedoraproject.org fabiand at fedoraproject.org
Tue Feb 5 14:23:29 UTC 2013


Fabian Deutsch has uploaded a new change for review.

Change subject: ui: Fetch bridge from config
......................................................................

ui: Fetch bridge from config

Previously the logic tried to determin the bridge using the current live
informations, but now the reliable config files are used.

Change-Id: I66ffb97c1477283452429c5d393e094b51948280
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/config/network.py
M scripts/tui/src/ovirt/node/utils/network.py
2 files changed, 57 insertions(+), 22 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/51/11751/1

diff --git a/scripts/tui/src/ovirt/node/config/network.py b/scripts/tui/src/ovirt/node/config/network.py
index 03a35d7..1aa22c3 100644
--- a/scripts/tui/src/ovirt/node/config/network.py
+++ b/scripts/tui/src/ovirt/node/config/network.py
@@ -18,7 +18,8 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.  A copy of the GNU General Public License is
 # also available at http://www.gnu.org/copyleft/gpl.html.
-from ovirt.node import utils
+from ovirt.node import utils, base
+from ovirt.node.config import defaults
 from ovirt.node.utils import AugeasWrapper as Augeas
 import logging
 import os
@@ -149,3 +150,56 @@
                            (cfg_hostname, sys_hostname))
 
     return cfg_hostname
+
+
+class Ifcfg(base.Base):
+    """Object to access ifcfg-%ifname
+    """
+    bridge = None
+    type = None
+    bootproto = None
+    ipaddr = None
+    netmask = None
+    gateway = None
+    vlan = None
+    device = None
+    hwaddr = None
+    onboot = None
+
+    def __init__(self, iface):
+        self.iface = iface
+        self.aug = Augeas()
+        self.load_properties()
+
+    def load_properties(self):
+        Augeas.force_reload()
+        for p in ["bridge", "type", "bootproto", "ipaddr", "netmask",
+                  "gateway", "vlan", "device", "onboot", "hwaddr"]:
+            self.__dict__[p] = self.ifcfg_property(p.upper())
+
+    def ifcfg_property(self, name):
+        filepath = "/etc/sysconfig/network-scripts/ifcfg-%s" % self.iface
+        augdevicepath = "/files%s" % filepath
+
+        value = None
+        if os.path.exists(filepath):
+            value = self.aug.get("%s/%s" % (augdevicepath, name), True)
+        else:
+            LOGGER.debug("No config file %s" % filepath)
+
+        return value
+
+
+def node_bridge():
+    """Return the configured bridge
+
+    Returns:
+        Ifname of a configured bridge or None if none is configured
+    """
+    bridge = None
+    model = defaults.Network()
+    bootif = model.retrieve()["iface"]
+    if bootif:
+        nic = Ifcfg(bootif)
+        bridge = nic.bridge
+    return bridge
\ No newline at end of file
diff --git a/scripts/tui/src/ovirt/node/utils/network.py b/scripts/tui/src/ovirt/node/utils/network.py
index 89a4692..9f7fb44 100644
--- a/scripts/tui/src/ovirt/node/utils/network.py
+++ b/scripts/tui/src/ovirt/node/utils/network.py
@@ -18,7 +18,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.  A copy of the GNU General Public License is
 # also available at http://www.gnu.org/copyleft/gpl.html.
-from ovirt.node import base, utils
+from ovirt.node import base, utils, config
 from socket import inet_ntoa
 from struct import pack
 import glob
@@ -277,25 +277,6 @@
     return node_infos
 
 
-def node_bridge():
-    """Returns the main bridge of this node
-
-    Returns:
-        Bridge of this node
-    """
-
-    all_ifaces = relevant_ifaces(filter_bridges=False, filter_vlans=False)
-    all_infos = [iface_information(i) for i in all_ifaces]
-
-    bridges = [info["name"] for info in all_infos
-               if info["devtype"] == "bridge"]
-
-    if len(bridges) != 1:
-        LOGGER.warning("Expected exactly one bridge: %s" % bridges)
-
-    return bridges[0] if len(bridges) else None
-
-
 class NIC(base.Base):
     def __init__(self, iface):
         self.iface = iface
@@ -448,7 +429,7 @@
 def networking_status(iface=None):
     status = "Not connected"
 
-    iface = iface or node_bridge()
+    iface = iface or config.network.node_bridge()
     addresses = []
     if iface:
         nic = NIC(iface)


--
To view, visit http://gerrit.ovirt.org/11751
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I66ffb97c1477283452429c5d393e094b51948280
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>



More information about the node-patches mailing list