virt-manager command line options

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 We need a way how call virt-manager methods without D-BUS. This patch
 adds new --show-* command line options.

 The --show-* options need to be used together with the --connect
 option.

 Daniel, I also added an OptionValueError exception. It's not perfect
 solution, but I'm not sure what's your favourite way for error messages
 in virt-manager when GTK is not initialized yet. 

        # virt-manager --help 
        usage: virt-manager.py [options]

        options:
          -h, --help            show this help message and exit
          -c URI, --connect=URI
                                Connect to hypervisor at URI
          --no-dbus             Disable DBus service for controlling UI
          --show-domain-creator
                                Create a new virtual machine
          --show-domain-editor=UUID
                                Edit a domain configuration
          --show-domain-performance=UUID
                                Show a domain performance
          --show-domain-console=UUID
                                Show a domain console
          --show-host-summary   Show a host summary


    Karel


# HG changeset patch
# User Karel Zak <kzak@xxxxxxxxxx>
# Node ID 3aab017160416137fe3033e13a206303287e5dd9
# Parent  127d61c9062e0ed5662f412f5edbb6c7dbd5582f
add command line option

diff -r 127d61c9062e -r 3aab01716041 src/virt-manager.py.in
--- a/src/virt-manager.py.in	Thu Oct 19 13:48:03 2006 -0400
+++ b/src/virt-manager.py.in	Wed Oct 25 23:24:24 2006 +0200
@@ -70,7 +70,7 @@ dbus.glib.threads_init()
 dbus.glib.threads_init()
 import dbus.service
 
-from optparse import OptionParser
+from optparse import OptionParser, OptionValueError
 
 appname = "::PACKAGE::"
 appversion = "::VERSION::"
@@ -102,21 +102,74 @@ from virtManager.remote import vmmRemote
 
 gtk.window_set_default_icon_from_file(icon_dir + "/" + appname + "-icon.svg")
 
+# maps --show-* to engine methods
+def show_engine(engine, show, uri, uuid):
+    if show=='creator':
+        engine.show_create(uri)
+    elif show=='editor':
+        engine.show_details_config(uri, uuid)
+    elif show=='performance':
+        engine.show_details_performance(uri, uuid)
+    elif show=='console':
+        engine.show_console(uri, uuid)
+    elif show=='summary' or uri:
+        engine.show_manager(uri)
+    else:
+        engine.show_connect()
+
+# maps --show-* to remote manager methods
+def show_remote(managerObj, show, uri, uuid):
+    if show=='creator':
+        managerObj.show_domain_creator(uri)
+    elif show=='editor':
+        managerObj.show_domain_editor(uri, uuid)
+    elif show=='performance':
+        managerObj.show_domain_performance(uri, uuid)
+    elif show=='console':
+        managerObj.show_domain_console(uri, uuid)
+    elif show=='summary' or uri:
+        managerObj.show_host_summary(uri)
+    else:
+        managerObj.show_connect()
+
+# Generic OptionParser callback for all --show-* options
+# This routine stores UUID to options.uuid for all --show-* options 
+# where is metavar="UUID" and also sets options.show
+def opt_show_cb(option, opt_str, value, parser):
+    if option.metavar=="UUID":
+        setattr(parser.values, "uuid", value)        
+    s = str(option)
+    show = s[s.rindex('-')+1:]
+    setattr(parser.values, "show", show)
+
 # Run me!
 def main():
     optParser = OptionParser()
-    optParser.add_option("-c", "--connect", dest="uri", help="Connect to hypervisor at URI", metavar="URI")
-    optParser.add_option("--no-dbus", action="store_true", dest="nodbus", help="Disable DBus service for controlling UI")
+    optParser.set_defaults(uuid=None)
+    optParser.add_option("-c", "--connect", dest="uri", 
+        help="Connect to hypervisor at URI", metavar="URI")
+    optParser.add_option("--no-dbus", action="store_true", dest="nodbus", 
+        help="Disable DBus service for controlling UI")
+    optParser.add_option("--show-domain-creator", action="callback", 
+        callback=opt_show_cb, dest="show", help="Create a new virtual machine")
+    optParser.add_option("--show-domain-editor",  type="string", metavar="UUID",
+        action="callback", callback=opt_show_cb, help="Edit a domain configuration")
+    optParser.add_option("--show-domain-performance", type="string", metavar="UUID", 
+        action="callback", callback=opt_show_cb, help="Show a domain performance")
+    optParser.add_option("--show-domain-console", type="string", metavar="UUID",
+        action="callback", callback=opt_show_cb, help="Show a domain console")
+    optParser.add_option("--show-host-summary", action="callback", 
+       callback=opt_show_cb, help="Show a host summary")
 
     (options, args) = optParser.parse_args()
+
+    if options.show and options.uri==None:
+        raise OptionValueError("can't use --show-* options without --connect")
 
     config = vmmConfig(appname, appversion, gconf_dir, glade_dir, icon_dir)
     engine = vmmEngine(config)
     if options.nodbus:
-        if options.uri != None:
-            engine.show_manager(options.uri)
-        else:
-            engine.show_connect()
+        show_engine(engine, options.show, options.uri, options.uuid)
     else:
         bus = None
         try:
@@ -135,19 +188,14 @@ def main():
                 managerProxy = bus.get_object("com.redhat.virt.manager", "/com/redhat/virt/manager")
                 managerObj = dbus.Interface(managerProxy, "com.redhat.virt.manager")
 
-                if options.uri != None:
-                    managerObj.show_host_summary(options.uri)
-                else:
-                    managerObj.show_connect()
+                show_remote(managerObj, options.show, options.uri, options.uuid)
+
                 # yes, we exit completely now - remote service is in charge
                 return
         except:
             logging.warning("Could not connection to session bus, disabling DBus service " + \
                             str(sys.exc_info()[0]) + " " + str(sys.exc_info()[1]))
-            if options.uri != None:
-                engine.show_manager(options.uri)
-            else:
-                engine.show_connect()
+            show_engine(engine, options.show, options.uri, options.uuid)
     gtk.main()
 
 if __name__ == "__main__":


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]