add 'status all --full' options, update README
authorJens Kasten <jens@kasten-edv.de>
Sun, 08 Apr 2012 00:24:35 +0200
changeset 113 d180b27d13a9
parent 112 0ca5084026ff
child 114 d146fb6e68ae
add 'status all --full' options, update README
README.txt
bin/kvm-admin
kvmtools/kvm/action.py
--- a/README.txt	Sat Apr 07 16:38:10 2012 +0200
+++ b/README.txt	Sun Apr 08 00:24:35 2012 +0200
@@ -17,6 +17,7 @@
   {boot,create,kill,modify,monitor,reboot,show,shutdown,status}
                         additional help
 
+
 =========
 Depencies
 =========
@@ -27,6 +28,7 @@
 
 All others are standard python library.
 
+
 ======
 Update
 ======
@@ -37,11 +39,15 @@
 This is used to check if the given key in the configuration file 
 is a valid qemu-kvm option.
 
+
 ====
 Info
 ====
 The qemu-kvm option for monitor, and pidfile has default values.
 But this options can be overriden in each domain configuration file.
+The qemu-kvm domain name should not be "all".
+See status description below.
+
 
 ========
 Downlaod
@@ -54,12 +60,14 @@
     hg clone http://hg.kasten-edv.de/kvm-tools  
     hg clone https://hg.kasten-edv.de/kvm-tools --insecure
 
+
 ============
 Installation
 ============
 Look at INSTALL.txt.
 # Fix: debian package and new setup.py 
 
+
 ==================
 System preparation
 ==================
@@ -82,6 +90,7 @@
 	chown kvm:kvm /var/run/kvm  (or /usr/local/var/run/kvm)
     chmod 750 /var/run/kvm  (or /usr/local/var/run/kvm)
 
+
 =============
 Kernel module
 =============
@@ -93,9 +102,10 @@
 For using tap device:
 	modprobe -v tun
 
-===================
-Guest configuration
-===================
+
+=============================
+QEMU-KVM domain configuration
+=============================
 An example for a domain configuration file.
 The syntax values are 1:1 on commandline usage the only differ is instead using
 	-option_name value
@@ -155,6 +165,7 @@
     # optinal, run as kvm user
     runas = kvm
 
+
 ================
 Sound for guests
 ================
@@ -177,6 +188,21 @@
     # add a harddrive to guest
     kvm-admin my_guest monitor pci_add auto storage file=/path/to/partion_or_file,if=virtio
 
+
+============================
+Query qemu-kvm doamin status
+============================
+For a single qemu-kvm domain use:
+    kvm-admin status domain_name
+
+For all running domains use:
+    # argument --full is optional and print more information
+    kvm-admin status all --full
+
+Info: The qemu-kvm domain name should not be "all" because of using in status
+      report.
+
+
 =============
 Monitor using
 =============
--- a/bin/kvm-admin	Sat Apr 07 16:38:10 2012 +0200
+++ b/bin/kvm-admin	Sun Apr 08 00:24:35 2012 +0200
@@ -104,10 +104,15 @@
     for i in actions:
         my_help = getattr(kvm_admin, "kvm_%s_action" % i).__doc__
         action = subparser.add_parser(i)
-        action.add_argument(i, action="store", metavar=("domain_name"), help=my_help)
+        action.add_argument(i, action="store", metavar=("domain"), 
+            help=my_help)
+        if i == "status":
+            action.add_argument("--full", default=False, action="store_true", 
+                #metavar=("full status information"),
+                help=_("Display full status information for each running qemu-kvm domain."))
         if i == "monitor":               
             action.add_argument("args_monitor", nargs="*", default=[],
-                metavar=("monitor argument"),
+                #metavar=("monitor argument"),
                 help=_("One ore more arguments to pass to the qemu-kvm monitor."))
     
     args = parser.parse_args()
@@ -130,7 +135,9 @@
 
     # assign all as domain name its used for status
     if kvm_admin.kvm_domain_name == "all" and kvm_admin.action == "status":
+        # append "all" as pseudo domain name
         domains.append("all")
+        kvm_admin.kvm_status_full = args.full
 
     # check if the domain name has a config file and is not create
     if not kvm_admin.kvm_domain_name in domains and not "create" == kvm_admin.action:  
--- a/kvmtools/kvm/action.py	Sat Apr 07 16:38:10 2012 +0200
+++ b/kvmtools/kvm/action.py	Sun Apr 08 00:24:35 2012 +0200
@@ -18,7 +18,7 @@
 
     def __init__(self):
         Domain.__init__(self)
-        #self.doc = False
+        self.kvm_status_full = False
 
     def kvm_error(self, error_message):
         """Append a error message to error list."""
@@ -146,20 +146,66 @@
             self.is_running()
             sys.exit(1)
 
+    def _status_all(self):
+        """Show status information form all running qemu-kvm domains."""
+        domains = {}
+        # list all files in run dir and get pidfile socketfile and domain name
+        for i in os.listdir(self.kvm_run_dir):
+            domain_name = i.rsplit(".", 1)[0]
+            if not domain_name in domains:
+                domains[domain_name] = {}
+            if i.endswith(".pid"):
+                domains[domain_name]["pidfile"] = os.path.join(self.kvm_run_dir, i)
+            if i.endswith(".socket"):
+                domains[domain_name]["socketfile"] = os.path.join(self.kvm_run_dir, i)
+        # iter over the domains and set the necessary values on the fly
+        counter = len(domains)
+        for domain in domains.iterkeys():
+            self.kvm_pidfile = domains[domain]["pidfile"]
+            self.kvm_socketfile = domains[domain]["socketfile"]
+            self.kvm_domain_name = domain
+            self.monitor_open()
+            self._get_uuid()
+            self._get_status()
+            self._get_process_info()
+            print ("Domain name: %s :: Process name: %s" % \
+                (domain, self.kvm_process_name))
+            print ("Domain uuid: %s" % self.kvm_process_uuid)
+            print ("%s :: Process state: %s" % \
+                (self.kvm_process_status, self.kvm_process_state))
+            if self.kvm_status_full:
+                self._get_vnc()
+                print "UID: %s" % self.kvm_process_uid
+                print "GID: %s" % self.kvm_process_gid
+                print "Groups: %s" % self.kvm_process_groups
+                print "PID: %s :: PPID: %s" % \
+                    (self.kvm_process_pid, self.kvm_process_ppid)
+                print ("VNC information")
+                print self.kvm_process_vnc
+            self.monitor_close()
+            # show only line for seperation if more than one domains
+            if counter > 1:
+                print "-" * 80
+            counter -= 1
+
     def kvm_status_action(self):
         """Show information about qemu-kvm domain(s)."""
+        if self.kvm_domain_name == "all":
+            self._status_all()
+            return True
         if not self.is_running():
             print ("Guest is not running.")
             return False
         self.get_process_information()
-        print ("Process name: %s" % self.kvm_process_name)
-        print ("Domain uuid:  %s" % self.kvm_process_uuid)
-        print ("%s :: Process state: %s" % (self.kvm_process_status,
-            self.kvm_process_state))
+        print ("Domain name: %s :: Process name: %s" % \
+            (self.kvm_domain_name, self.kvm_process_name))
+        print ("Domain uuid: %s" % self.kvm_process_uuid)
+        print ("%s :: Process state: %s" % \
+            (self.kvm_process_status, self.kvm_process_state))
         print "UID: %s" % self.kvm_process_uid
         print "GID: %s" % self.kvm_process_gid
         print "Groups: %s" % self.kvm_process_groups
-        print "PID: %s :: PPID: %s" % (self.kvm_process_pid, 
-            self.kvm_process_ppid)
+        print "PID: %s :: PPID: %s" % \
+            (self.kvm_process_pid, self.kvm_process_ppid)
         print ("VNC information")
         print self.kvm_process_vnc