From a61978aed97018e734eaafde9deb77a7c1e412b5 Mon Sep 17 00:00:00 2001 From: Rik Theys Date: Sat, 25 May 2013 22:20:25 +0200 Subject: [PATCH 1/2] 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. --- library/cloud/virt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/library/cloud/virt b/library/cloud/virt index 6a6c04b4df..62c9158558 100644 --- a/library/cloud/virt +++ b/library/cloud/virt @@ -275,13 +275,18 @@ 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: - results.append(x.name()) + if state: + vmstate = self.conn.get_status2(x) + if vmstate == state: + results.append(x.name()) + else: + results.append(x.name()) except: pass return results @@ -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: From e97f789913f4de1069012e019eb836dd521c77cd Mon Sep 17 00:00:00 2001 From: Rik Theys Date: Sun, 26 May 2013 23:06:23 +0200 Subject: [PATCH 2/2] Fix tabs --- library/cloud/virt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/library/cloud/virt b/library/cloud/virt index 62c9158558..2ac079058a 100644 --- a/library/cloud/virt +++ b/library/cloud/virt @@ -281,11 +281,11 @@ class Virt(object): results = [] for x in vms: try: - if state: - vmstate = self.conn.get_status2(x) - if vmstate == state: - results.append(x.name()) - else: + if state: + vmstate = self.conn.get_status2(x) + if vmstate == state: + results.append(x.name()) + else: results.append(x.name()) except: pass