virt_net: add way to get facts for only one specified network

This commit is contained in:
Trois-Six 2018-03-11 15:16:17 +01:00 committed by Gonéri Le Bouder
parent 46b821d51f
commit 6f9f67be18
2 changed files with 17 additions and 3 deletions

View file

@ -450,9 +450,13 @@ class VirtNetwork(object):
def info(self):
return self.facts(facts_mode='info')
def facts(self, facts_mode='facts'):
def facts(self, name=None, facts_mode='facts'):
results = dict()
for entry in self.list_nets():
if name:
entries = [name]
else:
entries = self.list_nets()
for entry in entries:
results[entry] = dict()
results[entry]["autostart"] = self.conn.get_autostart(entry)
results[entry]["persistent"] = self.conn.get_persistent(entry)
@ -565,6 +569,9 @@ def core(module):
return VIRT_SUCCESS, res
elif hasattr(v, command):
if command == 'facts' and name:
res = v.facts(name)
else:
res = getattr(v, command)()
if not isinstance(res, dict):
res = {command: res}

View file

@ -42,6 +42,13 @@
name: foobar
register: second_virt_net_start
- name: Get facts for default network
virt_net:
uri: qemu:///system
command: facts
name: foobar
register: virt_net_facts
- name: Destroy the foobar network
virt_net:
command: destroy