[node-patches] Change in ovirt-node[master]: Allow plugins to define the application

fabiand at fedoraproject.org fabiand at fedoraproject.org
Tue Dec 11 20:09:39 UTC 2012


Fabian Deutsch has uploaded a new change for review.

Change subject: Allow plugins to define the application
......................................................................

Allow plugins to define the application

Previosuly the plugins were loaded frmo a predefined location, now it's
possible to define this location when instanciating the application.

This allows an easy creation of an e.g. setup and installer application.

Change-Id: Ibfab8322c1c7a1ef59956f2eaf2b1d113c55497a
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/app.py
M scripts/tui/src/ovirt/node/config/defaults.py
M scripts/tui/src/ovirt/node/main.py
M scripts/tui/src/ovirt/node/plugins/__init__.py
A scripts/tui/src/ovirt/node/plugins/installer/__init__.py
A scripts/tui/src/ovirt/node/plugins/setup/__init__.py
R scripts/tui/src/ovirt/node/plugins/setup/engine_page.py
R scripts/tui/src/ovirt/node/plugins/setup/example.py
R scripts/tui/src/ovirt/node/plugins/setup/features.py
R scripts/tui/src/ovirt/node/plugins/setup/kdump_page.py
R scripts/tui/src/ovirt/node/plugins/setup/keyboard_page.py
R scripts/tui/src/ovirt/node/plugins/setup/logging_page.py
R scripts/tui/src/ovirt/node/plugins/setup/monitoring_page.py
R scripts/tui/src/ovirt/node/plugins/setup/network_page.py
R scripts/tui/src/ovirt/node/plugins/setup/ping.py
R scripts/tui/src/ovirt/node/plugins/setup/remote_storage_page.py
R scripts/tui/src/ovirt/node/plugins/setup/security_page.py
R scripts/tui/src/ovirt/node/plugins/setup/snmp_page.py
R scripts/tui/src/ovirt/node/plugins/setup/status_page.py
R scripts/tui/src/ovirt/node/plugins/setup/support_page.py
R scripts/tui/src/ovirt/node/plugins/setup/usage.py
M scripts/tui/src/ovirt/node/utils/fs.py
M scripts/tui/src/ovirt/node/utils/network.py
23 files changed, 70 insertions(+), 47 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/30/9930/1

diff --git a/scripts/tui/src/ovirt/node/app.py b/scripts/tui/src/ovirt/node/app.py
index 4aaa4ab..0373706 100644
--- a/scripts/tui/src/ovirt/node/app.py
+++ b/scripts/tui/src/ovirt/node/app.py
@@ -42,14 +42,15 @@
 
     ui = None
 
-    def __init__(self, ui_backend="urwid"):
+    def __init__(self, plugin_base, ui_backend="urwid"):
         ui_backend_class = {
             "urwid": ovirt.node.ui.tui.UrwidTUI
         }[ui_backend]
         self.ui = ui_backend_class(self)
+        self.plugin_base = plugin_base
 
     def __load_plugins(self):
-        self.plugins = [m.Plugin(self) for m in ovirt.node.plugins.load_all()]
+        self.plugins = [m.Plugin(self) for m in ovirt.node.plugins.load(self.plugin_base)]
 
         for plugin in self.plugins:
             LOGGER.debug("Loading plugin %s" % plugin)
diff --git a/scripts/tui/src/ovirt/node/config/defaults.py b/scripts/tui/src/ovirt/node/config/defaults.py
index be2c180..1931d8e 100644
--- a/scripts/tui/src/ovirt/node/config/defaults.py
+++ b/scripts/tui/src/ovirt/node/config/defaults.py
@@ -29,6 +29,9 @@
 central configuration file.
 Each class (for a component) can have a configure and apply_config method. Look
 at the CentralNodeConfiguration for more informations. 
+
+Each class should implement a configure method, mainly to define all the
+required arguments (or keys).
 """
 
 import logging
@@ -138,12 +141,12 @@
     - OVIRT_VLAN
     - OVIRT_IPV6
     """
-    keys = ("BOOTIF",
-            "BOOTPROTO",
-            "IP_ADDRESS",
-            "IP_NETMASK",
-            "IP_GATEWAY",
-            "VLAN")
+    keys = ("OVIRT_BOOTIF",
+            "OVIRT_BOOTPROTO",
+            "OVIRT_IP_ADDRESS",
+            "OVIRT_IP_NETMASK",
+            "OVIRT_IP_GATEWAY",
+            "OVIRT_VLAN")
 
     @map_and_update_defaults
     def configure(self, iface, bootproto, ipaddr=None, netmask=None, gw=None,
@@ -152,7 +155,7 @@
 
 
 class Nameservers(CentralNodeConfiguration):
-    keys = ("DNS")
+    keys = ("OVIRT_DNS")
 
     @map_and_update_defaults
     def configure(self, servers):
@@ -205,7 +208,7 @@
 
 
 class Timeservers(CentralNodeConfiguration):
-    keys = ("NTP")
+    keys = ("OVIRT_NTP")
 
     @map_and_update_defaults
     def configure(self, servers):
@@ -213,8 +216,8 @@
 
 
 class Syslog(CentralNodeConfiguration):
-    keys = ("SYSLOG_SERVER",
-            "SYSLOG_PORT")
+    keys = ("OVIRT_SYSLOG_SERVER",
+            "OVIRT_SYSLOG_PORT")
 
     @map_and_update_defaults
     def configure(self, server, port):
@@ -222,8 +225,8 @@
 
 
 class Collectd(CentralNodeConfiguration):
-    keys = ("COLLECTD_SERVER",
-            "COLLECTD_PORT")
+    keys = ("OVIRT_COLLECTD_SERVER",
+            "OVIRT_COLLECTD_PORT")
 
     @map_and_update_defaults
     def configure(self, server, port):
@@ -231,17 +234,17 @@
 
 
 class RHN(CentralNodeConfiguration):
-    keys = ("RHN_TYPE",
-            "RHN_URL",
-            "RHN_CA_CERT",
-            "RHN_USERNAME",
-            "RHN_PASSWORD",
-            "RHN_PROFILE",
-            "RHN_ACTIVATIONKEY",
-            "RHN_ORG",
-            "RHN_PROXY",
-            "RHN_PROXYUSER",
-            "RHN_PROXYPASSWORD")
+    keys = ("OVIRT_RHN_TYPE",
+            "OVIRT_RHN_URL",
+            "OVIRT_RHN_CA_CERT",
+            "OVIRT_RHN_USERNAME",
+            "OVIRT_RHN_PASSWORD",
+            "OVIRT_RHN_PROFILE",
+            "OVIRT_RHN_ACTIVATIONKEY",
+            "OVIRT_RHN_ORG",
+            "OVIRT_RHN_PROXY",
+            "OVIRT_RHN_PROXYUSER",
+            "OVIRT_RHN_PROXYPASSWORD")
 
     @map_and_update_defaults
     def configure(self, rhntype, url, ca_cert, username, password, profile,
@@ -250,8 +253,8 @@
 
 
 class KDump(CentralNodeConfiguration):
-    keys = ("KDUMP_NFS",
-            "KDUMP_SSH")
+    keys = ("OVIRT_KDUMP_NFS",
+            "OVIRT_KDUMP_SSH")
 
     @map_and_update_defaults
     def configure(self, nfs, ssh):
@@ -259,10 +262,10 @@
 
 
 class iSCSI(CentralNodeConfiguration):
-    keys = ("ISCSI_NODE_NAME",
-            "ISCSI_TARGET_NAME",
-            "ISCSI_TARGET_IP",
-            "ISCSI_TARGET_PORT")
+    keys = ("OVIRT_ISCSI_NODE_NAME",
+            "OVIRT_ISCSI_TARGET_NAME",
+            "OVIRT_ISCSI_TARGET_IP",
+            "OVIRT_ISCSI_TARGET_PORT")
 
     @map_and_update_defaults
     def configure(self, name, target_name, target_host, target_port):
@@ -270,7 +273,7 @@
 
 
 class SNMP(CentralNodeConfiguration):
-    keys = ("SNMP_PASSWORD")
+    keys = ("OVIRT_SNMP_PASSWORD")
 
     @map_and_update_defaults
     def configure(self, password):
@@ -278,8 +281,8 @@
 
 
 class Netconsole(CentralNodeConfiguration):
-    keys = ("NETCONSOLE_SERVER",
-            "NETCONSOLE_PORT")
+    keys = ("OVIRT_NETCONSOLE_SERVER",
+            "OVIRT_NETCONSOLE_PORT")
 
     @map_and_update_defaults
     def configure(self, server, port):
@@ -287,7 +290,7 @@
 
 
 class CIM(CentralNodeConfiguration):
-    keys = ("CIM_ENABLED")
+    keys = ("OVIRT_CIM_ENABLED")
 
     @map_and_update_defaults
     def configure(self, enabled):
diff --git a/scripts/tui/src/ovirt/node/main.py b/scripts/tui/src/ovirt/node/main.py
index e88cb8b..2e5c3f5 100644
--- a/scripts/tui/src/ovirt/node/main.py
+++ b/scripts/tui/src/ovirt/node/main.py
@@ -19,12 +19,13 @@
 # also available at http://www.gnu.org/copyleft/gpl.html.
 
 """
-Create an application instance an start it.
+Create an setup application instance an start it.
 """
 
 import ovirt.node.app
+import ovirt.node.plugins.setup
 
 
 if __name__ == '__main__':
-    app = ovirt.node.app.Application()
+    app = ovirt.node.app.Application(ovirt.node.plugins.setup)
     app.run()
diff --git a/scripts/tui/src/ovirt/node/plugins/__init__.py b/scripts/tui/src/ovirt/node/plugins/__init__.py
index 271f752..fb457c1 100644
--- a/scripts/tui/src/ovirt/node/plugins/__init__.py
+++ b/scripts/tui/src/ovirt/node/plugins/__init__.py
@@ -24,27 +24,25 @@
 import pkgutil
 import logging
 
-import ovirt.node.plugins
 import ovirt.node.exceptions
 
 LOGGER = logging.getLogger(__name__)
 
 
-def __walk_plugins():
+def __walk_plugins(module):
     """Used to find all plugins
     """
-    package = ovirt.node.plugins
-    for importer, modname, ispkg in pkgutil.iter_modules(package.__path__):
+    for importer, modname, ispkg in pkgutil.iter_modules(module.__path__):
         yield (importer, modname, ispkg)
 
 
-def load_all():
+def load(basemodule):
     """Load all plugins
     """
     modules = []
-    for importer, modname, ispkg in __walk_plugins():
+    for importer, modname, ispkg in __walk_plugins(basemodule):
         #print("Found submodule %s (is a package: %s)" % (modname, ispkg))
-        module = __import__("ovirt.node.plugins." + modname, fromlist="dummy")
+        module = __import__(basemodule.__name__ + "." + modname, fromlist="dummy")
         #print("Imported", module)
         modules += [module]
     return modules
diff --git a/scripts/tui/src/ovirt/node/plugins/installer/__init__.py b/scripts/tui/src/ovirt/node/plugins/installer/__init__.py
new file mode 100644
index 0000000..a38f201
--- /dev/null
+++ b/scripts/tui/src/ovirt/node/plugins/installer/__init__.py
@@ -0,0 +1,3 @@
+"""
+This package contains all UI plugins for the installer
+"""
\ No newline at end of file
diff --git a/scripts/tui/src/ovirt/node/plugins/setup/__init__.py b/scripts/tui/src/ovirt/node/plugins/setup/__init__.py
new file mode 100644
index 0000000..32f8845
--- /dev/null
+++ b/scripts/tui/src/ovirt/node/plugins/setup/__init__.py
@@ -0,0 +1,3 @@
+"""
+This package contains all UI plugins for the setup
+"""
\ No newline at end of file
diff --git a/scripts/tui/src/ovirt/node/plugins/engine_page.py b/scripts/tui/src/ovirt/node/plugins/setup/engine_page.py
similarity index 100%
rename from scripts/tui/src/ovirt/node/plugins/engine_page.py
rename to scripts/tui/src/ovirt/node/plugins/setup/engine_page.py
diff --git a/scripts/tui/src/ovirt/node/plugins/example.py b/scripts/tui/src/ovirt/node/plugins/setup/example.py
similarity index 100%
rename from scripts/tui/src/ovirt/node/plugins/example.py
rename to scripts/tui/src/ovirt/node/plugins/setup/example.py
diff --git a/scripts/tui/src/ovirt/node/plugins/features.py b/scripts/tui/src/ovirt/node/plugins/setup/features.py
similarity index 100%
rename from scripts/tui/src/ovirt/node/plugins/features.py
rename to scripts/tui/src/ovirt/node/plugins/setup/features.py
diff --git a/scripts/tui/src/ovirt/node/plugins/kdump_page.py b/scripts/tui/src/ovirt/node/plugins/setup/kdump_page.py
similarity index 100%
rename from scripts/tui/src/ovirt/node/plugins/kdump_page.py
rename to scripts/tui/src/ovirt/node/plugins/setup/kdump_page.py
diff --git a/scripts/tui/src/ovirt/node/plugins/keyboard_page.py b/scripts/tui/src/ovirt/node/plugins/setup/keyboard_page.py
similarity index 100%
rename from scripts/tui/src/ovirt/node/plugins/keyboard_page.py
rename to scripts/tui/src/ovirt/node/plugins/setup/keyboard_page.py
diff --git a/scripts/tui/src/ovirt/node/plugins/logging_page.py b/scripts/tui/src/ovirt/node/plugins/setup/logging_page.py
similarity index 100%
rename from scripts/tui/src/ovirt/node/plugins/logging_page.py
rename to scripts/tui/src/ovirt/node/plugins/setup/logging_page.py
diff --git a/scripts/tui/src/ovirt/node/plugins/monitoring_page.py b/scripts/tui/src/ovirt/node/plugins/setup/monitoring_page.py
similarity index 100%
rename from scripts/tui/src/ovirt/node/plugins/monitoring_page.py
rename to scripts/tui/src/ovirt/node/plugins/setup/monitoring_page.py
diff --git a/scripts/tui/src/ovirt/node/plugins/network_page.py b/scripts/tui/src/ovirt/node/plugins/setup/network_page.py
similarity index 98%
rename from scripts/tui/src/ovirt/node/plugins/network_page.py
rename to scripts/tui/src/ovirt/node/plugins/setup/network_page.py
index 8302917..23048c8 100644
--- a/scripts/tui/src/ovirt/node/plugins/network_page.py
+++ b/scripts/tui/src/ovirt/node/plugins/setup/network_page.py
@@ -52,6 +52,7 @@
         return 10
 
     def model(self):
+        # Pull name-/timeservers from config files (not defaults)
         nameservers = ovirt.node.config.network.nameservers()
         for idx, nameserver in enumerate(nameservers):
             self._model["dns[%d]" % idx] = nameserver
diff --git a/scripts/tui/src/ovirt/node/plugins/ping.py b/scripts/tui/src/ovirt/node/plugins/setup/ping.py
similarity index 100%
rename from scripts/tui/src/ovirt/node/plugins/ping.py
rename to scripts/tui/src/ovirt/node/plugins/setup/ping.py
diff --git a/scripts/tui/src/ovirt/node/plugins/remote_storage_page.py b/scripts/tui/src/ovirt/node/plugins/setup/remote_storage_page.py
similarity index 100%
rename from scripts/tui/src/ovirt/node/plugins/remote_storage_page.py
rename to scripts/tui/src/ovirt/node/plugins/setup/remote_storage_page.py
diff --git a/scripts/tui/src/ovirt/node/plugins/security_page.py b/scripts/tui/src/ovirt/node/plugins/setup/security_page.py
similarity index 100%
rename from scripts/tui/src/ovirt/node/plugins/security_page.py
rename to scripts/tui/src/ovirt/node/plugins/setup/security_page.py
diff --git a/scripts/tui/src/ovirt/node/plugins/snmp_page.py b/scripts/tui/src/ovirt/node/plugins/setup/snmp_page.py
similarity index 100%
rename from scripts/tui/src/ovirt/node/plugins/snmp_page.py
rename to scripts/tui/src/ovirt/node/plugins/setup/snmp_page.py
diff --git a/scripts/tui/src/ovirt/node/plugins/status_page.py b/scripts/tui/src/ovirt/node/plugins/setup/status_page.py
similarity index 100%
rename from scripts/tui/src/ovirt/node/plugins/status_page.py
rename to scripts/tui/src/ovirt/node/plugins/setup/status_page.py
diff --git a/scripts/tui/src/ovirt/node/plugins/support_page.py b/scripts/tui/src/ovirt/node/plugins/setup/support_page.py
similarity index 100%
rename from scripts/tui/src/ovirt/node/plugins/support_page.py
rename to scripts/tui/src/ovirt/node/plugins/setup/support_page.py
diff --git a/scripts/tui/src/ovirt/node/plugins/usage.py b/scripts/tui/src/ovirt/node/plugins/setup/usage.py
similarity index 100%
rename from scripts/tui/src/ovirt/node/plugins/usage.py
rename to scripts/tui/src/ovirt/node/plugins/setup/usage.py
diff --git a/scripts/tui/src/ovirt/node/utils/fs.py b/scripts/tui/src/ovirt/node/utils/fs.py
index 7c8977b..fd72aed 100644
--- a/scripts/tui/src/ovirt/node/utils/fs.py
+++ b/scripts/tui/src/ovirt/node/utils/fs.py
@@ -31,6 +31,18 @@
 LOGGER = logging.getLogger(__name__)
 
 
+def get_contents(src):
+    """Read the contents of a file
+
+    Args:
+        src: The file to be read
+    Returns:
+        The contents of src
+    """
+    with open(src, "r") as f:
+        contents = f.read()
+    return contents
+
 def copy_contents(src, dst):
     assert all([os.path.isfile(f) for f in [src, dst]]), \
            "Source and destination need to exist"
diff --git a/scripts/tui/src/ovirt/node/utils/network.py b/scripts/tui/src/ovirt/node/utils/network.py
index 7614774..0130f6b 100644
--- a/scripts/tui/src/ovirt/node/utils/network.py
+++ b/scripts/tui/src/ovirt/node/utils/network.py
@@ -29,6 +29,7 @@
 import glob
 
 import ovirt.node.utils.process as process
+import ovirt.node.utils.fs
 import ovirt.node.config.network
 
 LOGGER = logging.getLogger(__name__)
@@ -39,7 +40,7 @@
 #
 _nm_client = None
 try:
-    from gi.repository import NetworkManager, NMClient
+    from gi.repository import NetworkManager, NMClient      # @UnresolvedImport
     import socket
     import struct
     NetworkManager
@@ -116,8 +117,8 @@
 
     # Hwaddr
     hwaddr = "unkown"
-    with open("/sys/class/net/%s/address" % iface) as macfile:
-        hwaddr = macfile.read().strip()
+    hwfilename = "/sys/class/net/%s/address" % iface
+    hwaddr = ovirt.node.utils.fs.get_contents(hwfilename).strip()
     info["hwaddr"] = hwaddr
 
     # Check bridge


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

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