Support state parameter in list_vms command
Support the state parameter in the list_vms command to filter the VM's to list based on their state.
This commit is contained in:
parent
4105813ebe
commit
588784ca71
1 changed files with 12 additions and 2 deletions
12
cloud/virt
12
cloud/virt
|
@ -275,12 +275,17 @@ class Virt(object):
|
|||
}
|
||||
return info
|
||||
|
||||
def list_vms(self):
|
||||
def list_vms(self, state=None):
|
||||
self.conn = self.__get_conn()
|
||||
vms = self.conn.find_vm(-1)
|
||||
results = []
|
||||
for x in vms:
|
||||
try:
|
||||
if state:
|
||||
vmstate = self.conn.get_status2(x)
|
||||
if vmstate == state:
|
||||
results.append(x.name())
|
||||
else:
|
||||
results.append(x.name())
|
||||
except:
|
||||
pass
|
||||
|
@ -395,6 +400,11 @@ def core(module):
|
|||
v = Virt(uri)
|
||||
res = {}
|
||||
|
||||
if state and command=='list_vms':
|
||||
res = v.list_vms(state=state)
|
||||
if type(res) != dict:
|
||||
res = { command: res }
|
||||
return VIRT_SUCCESS, res
|
||||
|
||||
if state:
|
||||
if not guest:
|
||||
|
|
Loading…
Reference in a new issue