[node-patches] Change in ovirt-node[master]: ui: Several smaller fixes

fabiand at fedoraproject.org fabiand at fedoraproject.org
Wed Jan 16 11:57:13 UTC 2013


Fabian Deutsch has uploaded a new change for review.

Change subject: ui: Several smaller fixes
......................................................................

ui: Several smaller fixes

- Correct closing of dialogs
- Handle the case where a bridge is configured but not available
- ...

Change-Id: I70f66b84cadd6a1dcea8a19389cd4f4595f1d06d
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/app.py
M scripts/tui/src/ovirt/node/config/network.py
M scripts/tui/src/ovirt/node/plugins.py
M scripts/tui/src/ovirt/node/setup/network_page.py
M scripts/tui/src/ovirt/node/setup/status_page.py
M scripts/tui/src/ovirt/node/ui/__init__.py
M scripts/tui/src/ovirt/node/ui/urwid_builder.py
M scripts/tui/src/ovirt/node/ui/widgets.py
M scripts/tui/src/ovirt/node/utils/network.py
M scripts/tui/src/ovirt/node/utils/virt.py
10 files changed, 96 insertions(+), 40 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/86/11086/1

diff --git a/scripts/tui/src/ovirt/node/app.py b/scripts/tui/src/ovirt/node/app.py
index a3cf88e..879c809 100644
--- a/scripts/tui/src/ovirt/node/app.py
+++ b/scripts/tui/src/ovirt/node/app.py
@@ -178,11 +178,17 @@
         window = self.ui
         elements = ui_container.elements()
 
+        def cond_close_dialog(userdata):
+            self.logger.debug("Closing dialog: %s" % userdata)
+            if ui.Dialog in type(userdata).mro():
+                window.close_dialog(userdata.title)
+            else:
+                window.close_topmost_dialog()
+
         # All known handlers
         handlers = {ui.SaveAction:
                     lambda d: self.current_plugin()._on_ui_save(),
-                    ui.CloseAction:
-                    lambda d: window.close_topmost_dialog(),
+                    ui.CloseAction: cond_close_dialog,
                     ui.ResetAction:
                     lambda d: self.current_plugin()._on_ui_reset(),
                     ui.ChangeAction:
@@ -236,8 +242,8 @@
         self.__current_plugin = plugin
         with Timer() as t:
             content = plugin.ui_content()
-            self.populate_with_values(content)
-            self.assign_actions(content)
+            #self.populate_with_values(content)
+            #self.assign_actions(content)
             self.show(content)
         self.logger.debug("Build and displayed plugin_page in %s seconds" % t)
 
@@ -247,8 +253,10 @@
         and displays it.
         """
         assert ui.Page in type(ui_container).mro()
+        plugin = self.current_plugin()
         self.populate_with_values(ui_container)
         self.assign_actions(ui_container)
+        plugin.check_semantics()
         if ui.Dialog in type(ui_container).mro():
             self.ui._show_on_dialog(ui_container)
         elif ui.Page in type(ui_container).mro():
diff --git a/scripts/tui/src/ovirt/node/config/network.py b/scripts/tui/src/ovirt/node/config/network.py
index 83a897f..03a35d7 100644
--- a/scripts/tui/src/ovirt/node/config/network.py
+++ b/scripts/tui/src/ovirt/node/config/network.py
@@ -47,11 +47,11 @@
     info = {}
 
     aug = Augeas()
-    filepath = "/files/etc/sysconfig/network-scripts/ifcfg-%s" % iface
+    filepath = "/etc/sysconfig/network-scripts/ifcfg-%s" % iface
     augdevicepath = "/files%s" % filepath
 
     if not os.path.exists(filepath):
-        LOGGER.debug("No config file")
+        LOGGER.debug("No config file %s" % filepath)
 
     # Type
     info["type"] = aug.get(augdevicepath + "/TYPE", True)
diff --git a/scripts/tui/src/ovirt/node/plugins.py b/scripts/tui/src/ovirt/node/plugins.py
index de56a74..9444ce5 100644
--- a/scripts/tui/src/ovirt/node/plugins.py
+++ b/scripts/tui/src/ovirt/node/plugins.py
@@ -253,7 +253,7 @@
         Raises:
             An exception on a problem
         """
-        self.logger.debug("Triggering revalidation of model")
+        self.logger.debug("Triggering on_change of model")
         is_valid = True
         try:
             model = Changeset(model or self.model())
diff --git a/scripts/tui/src/ovirt/node/setup/network_page.py b/scripts/tui/src/ovirt/node/setup/network_page.py
index 2a8e485..2985cd3 100644
--- a/scripts/tui/src/ovirt/node/setup/network_page.py
+++ b/scripts/tui/src/ovirt/node/setup/network_page.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 plugins, ui, valid, utils
+from ovirt.node import plugins, ui, valid, utils, config
 from ovirt.node.config import defaults
 from ovirt.node.plugins import Changeset
 from ovirt.node.utils import network
@@ -64,12 +64,12 @@
             network.hostname()
 
         # Pull name-/timeservers from config files (not defaults)
-        nameservers = defaults.Nameservers().retrieve()["servers"]
+        nameservers = config.network.nameservers()
         if nameservers:
             for idx, nameserver in enumerate(nameservers):
                 model["dns[%d]" % idx] = nameserver
 
-        timeservers = defaults.Timeservers().retrieve()["servers"]
+        timeservers = config.network.timeservers()
         if timeservers:
             for idx, timeserver in enumerate(timeservers):
                 model["ntp[%d]" % idx] = timeserver
@@ -172,10 +172,6 @@
             self._nic_dialog.close()
             return
 
-        if "dialog.nic.save" in changes:
-            self.logger.debug("Save and close NIC")
-            self._nic_dialog.close()
-
         if "button.ping" in changes:
             self.logger.debug("Opening ping page")
             plugin_type = ovirt.node.setup.ping.Plugin
@@ -225,8 +221,12 @@
         progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self)
         progress_dialog.run()
 
+        if "dialog.nic.save" in changes:
+            # Close the remaing details dialog
+            self._nic_dialog.close()
+
         # Behaves like a page reload
-        #return self.ui_content()
+        return self.ui_content()
 
     def _configure_nic(self, bootproto, ipaddr, netmask, gateway, vlanid):
         vlanid = vlanid or None
@@ -272,12 +272,16 @@
         ipaddr, netmask, gateway, vlanid = (cfg["ipaddr"], cfg["netmask"],
                                             cfg["gateway"], cfg["vlanid"])
 
+        bridge_nic = utils.network.NIC(live["bridge"])
         if cfg["bootproto"] == "dhcp":
-            nic = utils.network.NIC(live["bridge"])
-            routes = utils.network.Routes()
-            ipaddr, netmask, gateway, vlanid = (nic.ipv4_address().items() +
-                                               (routes.default(),) +
-                                               (nic.vlanid(),))
+            if bridge_nic.exists():
+                routes = utils.network.Routes()
+                ipaddr, netmask = bridge_nic.ipv4_address().items()
+                gateway = routes.default()
+                vlanid = bridge_nic.vlanid()
+            else:
+                self.logger.warning("Bridge assigned but couldn't gather " +
+                                    "live info: %s" % bridge_nic)
 
         self.plugin._model_extra.update({
             "dialog.nic.iface": live["name"],
@@ -296,9 +300,6 @@
         })
 
         self.logger.debug("model: %s" % self.plugin.model())
-
-        save_n_close = ui.SaveButton("dialog.nic.save", "Save & Close")
-        save_n_close.on_activate.connect(ui.CloseAction())
 
         padd = lambda l: l.ljust(14)
         ws = [ui.Row("dialog.nic._row[0]",
@@ -336,7 +337,7 @@
               ]
         self.plugin.widgets.add(ws)
         self.children = ws
-        self.buttons = [save_n_close,
+        self.buttons = [ui.SaveButton("dialog.nic.save", "Save"),
                         ui.CloseButton("dialog.nic.close", "Close"),
                         ]
         self.plugin._nic_details_group.enabled(False)
diff --git a/scripts/tui/src/ovirt/node/setup/status_page.py b/scripts/tui/src/ovirt/node/setup/status_page.py
index 3341263..f1dec6c 100644
--- a/scripts/tui/src/ovirt/node/setup/status_page.py
+++ b/scripts/tui/src/ovirt/node/setup/status_page.py
@@ -49,9 +49,7 @@
         if net_addrs:
             net_addrs_str = "\nIPv4: {inet}\nIPv6: {inet6}".format(**net_addrs)
 
-        num_domains = "N/A"
-        with virt.LibvirtConnection() as con:
-            num_domains = str(con.numOfDomains())
+        num_domains = virt.number_of_domains()
 
         return {
             "status": virt.hardware_status(),
diff --git a/scripts/tui/src/ovirt/node/ui/__init__.py b/scripts/tui/src/ovirt/node/ui/__init__.py
index 599d430..7d6c6fc 100644
--- a/scripts/tui/src/ovirt/node/ui/__init__.py
+++ b/scripts/tui/src/ovirt/node/ui/__init__.py
@@ -138,6 +138,9 @@
     def __call__(self, target, userdata=None):
         r = None
         if self.callback:
+            self.logger.debug("Calling action %s %s with %s" % (self,
+                                                                self.callback,
+                                                                userdata))
             r = self.callback(userdata)
             self.logger.debug("Action %s called and returned: %s" % (self, r))
         else:
@@ -161,9 +164,15 @@
 
 
 class CloseAction(Action):
-    """Action to close the current page/dialog
+    """Action to close the current/given dialog
+
+    Args:
+        dialog: The dialog to close
     """
-    pass
+    dialog = None
+    def __init__(self, callback=None, dialog=None):
+        super(CloseAction, self).__init__(callback)
+        self.dialog = dialog
 
 
 class ResetAction(Action):
@@ -590,7 +599,7 @@
         super(Dialog, self).__init__(path, children, title)
         self.on_close = self.new_signal()
         self.close(False)
-        self.on_close.connect(CloseAction())
+        self.on_close.connect(CloseAction(dialog=self))
 
     def close(self, v=True):
         if v:
@@ -610,8 +619,9 @@
         self.buttons = [self._close_button]
         self._progress_label = Label("dialog.progress", initial_text)
         widgets = [self._progress_label]
+        title = "Transaction: %s" % self.transaction.title
         super(TransactionProgressDialog, self).__init__(path,
-                                                        self.transaction.title,
+                                                        title,
                                                         widgets)
 
     def add_update(self, txt):
diff --git a/scripts/tui/src/ovirt/node/ui/urwid_builder.py b/scripts/tui/src/ovirt/node/ui/urwid_builder.py
index 4fb388e..9c0bd7e 100644
--- a/scripts/tui/src/ovirt/node/ui/urwid_builder.py
+++ b/scripts/tui/src/ovirt/node/ui/urwid_builder.py
@@ -472,6 +472,11 @@
         return dialog
 
     def close_dialog(self, dialog):
+        if type(dialog) in [str, unicode]:
+            # Hack to alow to close a dialog by name
+            for d in self.__widget_stack:
+                if d.title == dialog:
+                    dialog = d 
         self.logger.debug("Widget stack: %s" % self.__widget_stack)
         new_stack = [w for w in self.__widget_stack if w != dialog]
         self.__widget_stack = new_stack
@@ -481,7 +486,6 @@
         else:
             self.__loop.widget = self.__main_frame
         assert dialog not in new_stack
-        assert type(dialog) is not dict
         self.logger.debug("Dialog %s closed" % dialog)
 
     def __filter_hotkeys(self, keys, raw):
diff --git a/scripts/tui/src/ovirt/node/ui/widgets.py b/scripts/tui/src/ovirt/node/ui/widgets.py
index 271cf04..c8f71b6 100644
--- a/scripts/tui/src/ovirt/node/ui/widgets.py
+++ b/scripts/tui/src/ovirt/node/ui/widgets.py
@@ -192,6 +192,8 @@
 class ModalDialog(urwid.WidgetWrap):
     signals = ['close']
 
+    title = None
+
     def __init__(self, title, body, escape_key, previous_widget):
         self.escape_key = escape_key
         self.previous_widget = previous_widget
diff --git a/scripts/tui/src/ovirt/node/utils/network.py b/scripts/tui/src/ovirt/node/utils/network.py
index 32fcbaf..89a4692 100644
--- a/scripts/tui/src/ovirt/node/utils/network.py
+++ b/scripts/tui/src/ovirt/node/utils/network.py
@@ -41,7 +41,9 @@
 #
 _nm_client = None
 try:
-    from gi.repository import NetworkManager, NMClient      # @UnresolvedImport
+    # pylint: disable-msg=E0611
+    from gi.repository import NetworkManager, NMClient  # @UnresolvedImport
+    # pylint: enable-msg=E0611
     import socket
     import struct
     NetworkManager
@@ -132,8 +134,10 @@
         info["type"] = "vlan"
 
     if "type" not in info:
-        LOGGER.warning("Type of %s still unknown, using devtype" % iface)
-        info["type"] = info["devtype"]
+        devtype = info["devtype"]
+        LOGGER.warning(("Type of %s still unknown, using devtype " +
+                        "%s") % (iface, devtype))
+        info["type"] = devtype
 
     if with_slow:
         info.update(_slow_iface_information(iface))
@@ -297,6 +301,12 @@
         self.iface = iface
         super(NIC, self).__init__()
 
+    def exists(self):
+        """If this NIC currently exists in the system
+        """
+        
+        return self.iface in all_ifaces()
+
     def has_link(self):
         """Determin if L1 is up on a given interface
 
@@ -316,7 +326,7 @@
             True if L1 (the-link-is-up) is detected (depends on driver support)
         """
 
-        if self.iface not in all_ifaces():
+        if not self.exists():
             raise UnknownNicError("Unknown network interface: '%s'" %
                                   self.iface)
 
@@ -349,7 +359,7 @@
 
         FIXME NM client.get_device_by_iface(iface).get_ip?_config()
         """
-        if self.iface not in all_ifaces():
+        if not self.exists():
             raise UnknownNicError("Unknown network interface: '%s'" %
                                   self.iface)
 
@@ -377,7 +387,8 @@
 
         # Fallback
         cmd = "ip -o addr show {iface}".format(iface=self.iface)
-        for line in process.pipe(cmd, without_retval=True).split("\n"):
+        stdout = str(process.pipe(cmd, without_retval=True))
+        for line in stdout.split("\n"):
             token = re.split("\s+", line)
             if re.search("\sinet[6]?\s", line):
                 addr, mask = token[3].split("/")
@@ -407,6 +418,9 @@
                              vlanids)
         return vlanids[0] if vlanids else None
 
+    def __str__(self):
+        return "<NIC iface='%s' at %s" % (self.iface, hex(id(self)))
+
 
 class Routes(base.Base):
     def default(self):
@@ -415,7 +429,8 @@
         # Fallback
         gw = None
         cmd = "ip route list"
-        for line in process.pipe(cmd, without_retval=True).split("\n"):
+        stdout = str(process.pipe(cmd, without_retval=True))
+        for line in stdout.split("\n"):
             token = re.split("\s+", line)
             if line.startswith("default via"):
                 gw = token[2]
@@ -483,4 +498,5 @@
     """
     if new_hostname:
         utils.process.system("hostname %s" % new_hostname)
-    return utils.process.pipe("hostname", without_retval=True)
+    stdout = unicode(utils.process.pipe("hostname", without_retval=True))
+    return stdout.strip()
diff --git a/scripts/tui/src/ovirt/node/utils/virt.py b/scripts/tui/src/ovirt/node/utils/virt.py
index 7e90620..7414720 100644
--- a/scripts/tui/src/ovirt/node/utils/virt.py
+++ b/scripts/tui/src/ovirt/node/utils/virt.py
@@ -81,9 +81,26 @@
     return "No virtualization hardware was detected on this system"
 
 
+def number_of_domains():
+    # FIXME solve this more general
+    num_domains = None
+    try:
+        with LibvirtConnection() as con:
+            num_domains = str(con.numOfDomains())
+    except libvirt.libvirtError as e:
+        pass
+        # warning("Error while working with libvirt: %s" % e.message)
+    return num_domains
+
+
 class LibvirtConnection(base.Base):
+    con = None
+
     def __init__(self, readonly=True):
         super(LibvirtConnection, self).__init__()
+        self.connect(readonly)
+
+    def connect(self, readonly):
         if readonly:
             self.con = libvirt.openReadOnly(None)
         else:


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I70f66b84cadd6a1dcea8a19389cd4f4595f1d06d
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