[node-patches] Change in ovirt-node[master]: [DRAFT] Add ovirt-node-config

fabiand at fedoraproject.org fabiand at fedoraproject.org
Mon Feb 24 18:54:35 UTC 2014


Fabian Deutsch has uploaded a new change for review.

Change subject: [DRAFT] Add ovirt-node-config
......................................................................

[DRAFT] Add ovirt-node-config

ovirt-node-config is a commandline tool to configure Node.
Basically the tool exposes the classes of ovirt-node.config.defaults.
That way the system can basically configured using the commandline. The
same codepaths are shared between the CLI and TUI.

This is mainly intended for quality issue to check all codepaths.

Change-Id: I0d06244e1380b4880381757074ad19c5d96a7771
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M ovirt-node.spec.in
M scripts/Makefile.am
A scripts/ovirt-node-config
3 files changed, 70 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/68/24968/1

diff --git a/ovirt-node.spec.in b/ovirt-node.spec.in
index 943e5f9..3727c45 100644
--- a/ovirt-node.spec.in
+++ b/ovirt-node.spec.in
@@ -670,6 +670,7 @@
 %{_bindir}/ovirt-node-installer
 %{_bindir}/ovirt-node-doc
 %{_bindir}/ovirt-node-features
+%{_bindir}/ovirt-node-config
 
 
 
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 22b8ef5..0cb226d 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -27,7 +27,8 @@
   ovirt-node-setup \
   ovirt-node-installer \
   ovirt-node-doc \
-  ovirt-node-features
+  ovirt-node-features \
+  ovirt-node-config
 
 dist_libexec_SCRIPTS = \
   ovirt-config-password \
diff --git a/scripts/ovirt-node-config b/scripts/ovirt-node-config
new file mode 100755
index 0000000..faa12c2
--- /dev/null
+++ b/scripts/ovirt-node-config
@@ -0,0 +1,67 @@
+#!/usr/bin/python
+
+import sys
+from ovirt.node.config.defaults import NodeConfigFileSection
+from ovirt.node.utils.console import TransactionProgress
+import inspect
+
+from optparse import OptionParser
+usage = "%prog [options] help|run [<CLASS>[.<FUNC> [<ARG> [<ARG>] ...]]]]"
+parser = OptionParser(usage=usage)
+parser.add_option("-m", "--module", dest="module",
+                  help="Module to use",
+                  default="ovirt.node.config.defaults")
+
+(options, args) = parser.parse_args()
+
+
+def list_funcs(cfg):
+    def valid_member(x):
+        return inspect.ismethod(x) and x.__name__.startswith("configure_")
+    funcs = dict(inspect.getmembers(cfg, valid_member))
+    return funcs
+
+def print_func_usage(func, with_doc=True):
+    args = inspect.getargspec(func).args[1:]
+    txtargs = " ".join("<%s>" % s.upper() for s in args)
+    return txtargs
+#    print inspect.getdoc(func)
+#    print ""
+
+def list_classes(module):
+    def valid_member(x):
+        return inspect.isclass(x) and NodeConfigFileSection in x.mro()
+    core = __import__(module, fromlist=[''])
+    return dict(inspect.getmembers(core, valid_member))
+
+def get_class(module, cls):
+    mbs = list_classes(module)
+    if cls not in mbs:
+        raise RuntimeError("Unknown config obj: %s" % classfunc)
+    return mbs[cls]
+
+def wtf(module, classfunc, args=None):
+    cls, func = classfunc.split(".")
+    cfg = get_class(module, cls)()
+    funcs = list_funcs(cfg)
+    func = funcs[func]
+    print func
+    tx = cfg.transaction()
+    TransactionProgress(tx, is_dry=True).run()
+
+if __name__ == "__main__":
+    if len(args) >= 1:
+        cmd = args[1]
+        if cmd[0] == "h":
+            cls = args[0]
+            print("Functions in class '%s':" % cls)
+            cfg = get_class(options.module, cls)
+            for name, func in sorted(list_funcs(cfg).items()):
+                print("- %s %s" % (name, print_func_usage(func)))
+        elif cmd[0] == "r":
+            wtf(options.module, args[0], args[1:])
+    else:
+        print("Classes in module '%s':" % options.module)
+        for name in sorted(list_classes(options.module).keys()):
+            print("- %s" % name)
+


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

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