func virt module patch

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

 



The attached patch renames the virt module's info() method to state(),
then adds a new info() method that returns all of libvirt's info()
data.

There's a comment in there about converting some long int's to
strings.   That was the easy path - a better solution would be nice
but I didn't see one on google or the python docs.

-Al Tobey
From 691267b21a94d21dab54e446c47342b428452b7b Mon Sep 17 00:00:00 2001
From: Al Tobey <tobert@xxxxxxxxx>
Date: Fri, 21 Dec 2007 16:21:10 -0500
Subject: [PATCH] rename info() to state() and add a new info() that corellates better to libvirt's info() and returns more data

---
 func/minion/modules/virt.py |   36 ++++++++++++++++++++++++++++--------
 1 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/func/minion/modules/virt.py b/func/minion/modules/virt.py
index b92dd54..2735054 100755
--- a/func/minion/modules/virt.py
+++ b/func/minion/modules/virt.py
@@ -137,8 +137,9 @@ class Virt(func_module.FuncModule):
             "unpause"   : self.unpause,
             "delete"    : self.undefine,
             "status"    : self.get_status,
+           "state"     : self.state,
            "info"      : self.info,
-           "inventory" : self.info,   # for func-inventory
+           "inventory" : self.state,   # for func-inventory
             "list_vms"  : self.list_vms,
         }
 
@@ -148,14 +149,33 @@ class Virt(func_module.FuncModule):
        self.conn = FuncLibvirtConnection()
         return self.conn
 
+    def state(self):
+        vms = self.list_vms()
+        state = []
+        for vm in vms:
+            state_blurb = self.conn.get_status(vm)
+            state.append("%s %s" % (vm,state_blurb))
+        return state
+
     def info(self):
-       vms = self.list_vms()
-       info = []
-       for vm in vms:
-           print vm
-           info_blurb = self.conn.get_status(vm)
-           info.append("%s %s" % (vm,info_blurb))
-       return info
+        vms = self.list_vms()
+        info = []
+        for vm in vms:
+            data = self.conn.find_vm(vm).info()
+            # libvirt returns maxMem, memory, and cpuTime as long()'s, which
+            # xmlrpclib tries to convert to regular int's during serialization.
+            # This throws exceptions, so convert them to strings here and
+            # assume the other end of the xmlrpc connection can figure things
+            # out or doesn't care.
+            info.append( {
+                "id"        : vm,
+                "state"     : VIRT_STATE_NAME_MAP.get(data[0],"unknown"),
+                "maxMem"    : str(data[1]),
+                "memory"    : str(data[2]),
+                "nrVirtCpu" : data[3],
+                "cpuTime"   : str(data[4])
+            } )
+        return info
 
     def list_vms(self):
         self.conn = self.get_conn()
-- 
1.5.3.3

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/et-mgmt-tools

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux