Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make xenserver_facts actually work #35821

Merged
merged 1 commit into from
May 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/BOTMETA.yml
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ files:
$modules/cloud/misc/virt_pool.py: drybjed
$modules/cloud/misc/xenserver_facts.py:
ignored: andyhky
maintainers: cheese
$modules/cloud/opennebula/: ilicmilan kustodian
$modules/cloud/openstack/: $team_openstack
$modules/cloud/openstack/os_keystone_service.py: $team_openstack SamYaple
Expand Down
2 changes: 2 additions & 0 deletions changelogs/fragments/xenserver-facts-fix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- xenserver_facts - ensure module works with newer versions of XenServer (https://github.com/ansible/ansible/pull/35821)
38 changes: 18 additions & 20 deletions lib/ansible/modules/cloud/misc/xenserver_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
author:
- Andy Hill (@andyhky)
- Tim Rupp
- Robin Lee (@cheese)
options: {}
'''

EXAMPLES = '''
- name: Gather facts from xenserver
xenserver:
xenserver_facts:

- name: Print running VMs
debug:
Expand Down Expand Up @@ -91,11 +92,8 @@ def get_xenapi_session():

def get_networks(session):
recs = session.xenapi.network.get_all_records()
xs_networks = {}
networks = change_keys(recs, key='uuid')
for network in networks.values():
xs_networks[network['name_label']] = network
return xs_networks
networks = change_keys(recs, key='name_label')
return networks


def get_pifs(session):
Expand Down Expand Up @@ -132,6 +130,13 @@ def change_keys(recs, key='uuid', filter_func=None):
if filter_func is not None and not filter_func(rec):
continue

for param_name, param_value in rec.items():
# param_value may be of type xmlrpc.client.DateTime,
# which is not simply convertable to str.
# Use 'value' attr to get the str value,
# following an example in xmlrpc.client.DateTime document
if hasattr(param_value, "value"):
rec[param_name] = param_value.value
new_recs[rec[key]] = rec
new_recs[rec[key]]['ref'] = ref

Expand All @@ -146,26 +151,19 @@ def get_host(session):


def get_vms(session):
xs_vms = {}
recs = session.xenapi.VM.get_all()
recs = session.xenapi.VM.get_all_records()
if not recs:
return None

vms = change_keys(recs, key='uuid')
for vm in vms.values():
xs_vms[vm['name_label']] = vm
return xs_vms
vms = change_keys(recs, key='name_label')
return vms


def get_srs(session):
xs_srs = {}
recs = session.xenapi.SR.get_all()
recs = session.xenapi.SR.get_all_records()
if not recs:
return None
srs = change_keys(recs, key='uuid')
for sr in srs.values():
xs_srs[sr['name_label']] = sr
return xs_srs
srs = change_keys(recs, key='name_label')
return srs


def main():
Expand Down Expand Up @@ -204,7 +202,7 @@ def main():
if xs_srs:
data['xs_srs'] = xs_srs

module.exit_json(ansible=data)
module.exit_json(ansible_facts=data)


if __name__ == '__main__':
Expand Down