From 02e66617f21b174c581a8424c9395a7fc7bc7815 Mon Sep 17 00:00:00 2001 From: Sam Doran Date: Tue, 22 May 2018 14:01:19 -0400 Subject: [PATCH] Make xenserver_facts actually work (#35821) (#40552) * Get the str value of xmlrpc.client.DateTime * get_all_records should be used instead of get_all * Facts returned with 'ansible_facts' * Remove some redundant code * Add cheese as maintainer * Add changelog entry (cherry picked from commit d45b044992bf15bffcab5d620899d90714bb4ecc) --- .github/BOTMETA.yml | 11 +++++- changelogs/fragments/xenserver-facts-fix.yaml | 2 + .../modules/cloud/misc/xenserver_facts.py | 38 +++++++++---------- 3 files changed, 30 insertions(+), 21 deletions(-) create mode 100644 changelogs/fragments/xenserver-facts-fix.yaml diff --git a/.github/BOTMETA.yml b/.github/BOTMETA.yml index edf49917fa5..22689a3d4c0 100644 --- a/.github/BOTMETA.yml +++ b/.github/BOTMETA.yml @@ -263,6 +263,8 @@ 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 $modules/cloud/openstack/os_project.py: $team_openstack agireud @@ -1224,7 +1226,14 @@ files: keywords: - validate-modules docs/: - labels: docs_pull_request + labels: docs + docs/docsite/rst/network/: + labels: networking + maintainers: + - acozine + - gundalow + docs/docsite/rst/scenario_guides/guide_aci.rst: + maintainers: $team_aci notify: dharmabumstead packaging/: test/: diff --git a/changelogs/fragments/xenserver-facts-fix.yaml b/changelogs/fragments/xenserver-facts-fix.yaml new file mode 100644 index 00000000000..9e18f942556 --- /dev/null +++ b/changelogs/fragments/xenserver-facts-fix.yaml @@ -0,0 +1,2 @@ +bugfixes: + - xenserver_facts - ensure module works with newer versions of XenServer (https://github.com/ansible/ansible/pull/35821) diff --git a/lib/ansible/modules/cloud/misc/xenserver_facts.py b/lib/ansible/modules/cloud/misc/xenserver_facts.py index 4616b1cddbd..8460edf44c6 100644 --- a/lib/ansible/modules/cloud/misc/xenserver_facts.py +++ b/lib/ansible/modules/cloud/misc/xenserver_facts.py @@ -22,12 +22,13 @@ description: author: - Andy Hill (@andyhky) - Tim Rupp + - Robin Lee (@cheese) options: {} ''' EXAMPLES = ''' - name: Gather facts from xenserver - xenserver: + xenserver_facts: - name: Print running VMs debug: @@ -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): @@ -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 @@ -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(): @@ -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__':