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. This is a slightly different patch than I mistakingly sent to et-mgmt-tools in that it uses a dict of dicts rather than an array of dicts. -Al Tobey
From 3ada04894b63bb54478f4f7a656a113d4b1d92d4 Mon Sep 17 00:00:00 2001 From: Al Tobey <tobert@xxxxxxxxx> Date: Fri, 21 Dec 2007 16:32:02 -0500 Subject: [PATCH] Rename info() to state(), add a new info() that returns all of the data libvirt.info() returns. --- func/minion/modules/virt.py | 35 +++++++++++++++++++++++++++-------- 1 files changed, 27 insertions(+), 8 deletions(-) diff --git a/func/minion/modules/virt.py b/func/minion/modules/virt.py index b92dd54..74f3e85 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,32 @@ 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 = dict() + 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[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