diff --git a/lib/ansible/modules/cloud/cloudstack/cs_instance_facts.py b/lib/ansible/modules/cloud/cloudstack/cs_instance_facts.py index 55f886664aa..49e8f9bb50d 100644 --- a/lib/ansible/modules/cloud/cloudstack/cs_instance_facts.py +++ b/lib/ansible/modules/cloud/cloudstack/cs_instance_facts.py @@ -29,23 +29,18 @@ options: domain: description: - Domain the instance is related to. - required: false - default: null account: description: - Account the instance is related to. - required: false - default: null project: description: - Project the instance is related to. - required: false - default: null extends_documentation_fragment: cloudstack ''' EXAMPLES = ''' -- cs_instance_facts: +- name: gather instance facts + cs_instance_facts: name: web-vm-1 delegate_to: localhost @@ -187,36 +182,36 @@ class AnsibleCloudStackInstanceFacts(AnsibleCloudStack): super(AnsibleCloudStackInstanceFacts, self).__init__(module) self.instance = None self.returns = { - 'group': 'group', - 'hypervisor': 'hypervisor', - 'instancename': 'instance_name', - 'publicip': 'public_ip', - 'passwordenabled': 'password_enabled', - 'password': 'password', - 'serviceofferingname': 'service_offering', - 'isoname': 'iso', - 'templatename': 'template', - 'keypair': 'ssh_key', + 'group': 'group', + 'hypervisor': 'hypervisor', + 'instancename': 'instance_name', + 'publicip': 'public_ip', + 'passwordenabled': 'password_enabled', + 'password': 'password', + 'serviceofferingname': 'service_offering', + 'isoname': 'iso', + 'templatename': 'template', + 'keypair': 'ssh_key', } self.facts = { 'cloudstack_instance': None, } - def get_instance(self): instance = self.instance if not instance: instance_name = self.module.params.get('name') - args = {} - args['account'] = self.get_account(key='name') - args['domainid'] = self.get_domain(key='id') - args['projectid'] = self.get_project(key='id') + args = { + 'account': self.get_account(key='name'), + 'domainid': self.get_domain(key='id'), + 'projectid': self.get_project(key='id'), + } # Do not pass zoneid, as the instance name must be unique across zones. - instances = self.cs.listVirtualMachines(**args) + instances = self.query_api('listVirtualMachines', **args) if instances: for v in instances['virtualmachine']: - if instance_name.lower() in [ v['name'].lower(), v['displayname'].lower(), v['id'] ]: + if instance_name.lower() in [v['name'].lower(), v['displayname'].lower(), v['id']]: self.instance = v break return self.instance @@ -224,13 +219,14 @@ class AnsibleCloudStackInstanceFacts(AnsibleCloudStack): def get_volumes(self, instance): volume_details = [] if instance: - args = {} - args['account'] = instance.get('account') - args['domainid'] = instance.get('domainid') - args['projectid'] = instance.get('projectid') - args['virtualmachineid'] = instance['id'] + args = { + 'account': self.get_account(key='name'), + 'domainid': self.get_domain(key='id'), + 'projectid': self.get_project(key='id'), + 'virtualmachineid': instance['id'], + } - volumes = self.cs.listVolumes(**args) + volumes = self.query_api('listVolumes', **args) if volumes: for vol in volumes['volume']: volume_details.append({'size': vol['size'], 'type': vol['type'], 'name': vol['name']}) @@ -243,7 +239,6 @@ class AnsibleCloudStackInstanceFacts(AnsibleCloudStack): self.facts['cloudstack_instance'] = self.get_result(instance) return self.facts - def get_result(self, instance): super(AnsibleCloudStackInstanceFacts, self).get_result(instance) if instance: @@ -270,10 +265,10 @@ class AnsibleCloudStackInstanceFacts(AnsibleCloudStack): def main(): argument_spec = cs_argument_spec() argument_spec.update(dict( - name = dict(required=True), - domain = dict(default=None), - account = dict(default=None), - project = dict(default=None), + name=dict(required=True), + domain=dict(), + account=dict(), + project=dict(), )) module = AnsibleModule( diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt index 40906aae4da..7449af7109a 100644 --- a/test/sanity/pep8/legacy-files.txt +++ b/test/sanity/pep8/legacy-files.txt @@ -65,7 +65,6 @@ lib/ansible/modules/cloud/azure/azure_rm_virtualnetwork.py lib/ansible/modules/cloud/azure/azure_rm_virtualnetwork_facts.py lib/ansible/modules/cloud/centurylink/clc_loadbalancer.py lib/ansible/modules/cloud/cloudstack/cs_instance.py -lib/ansible/modules/cloud/cloudstack/cs_instance_facts.py lib/ansible/modules/cloud/cloudstack/_cs_nic.py lib/ansible/modules/cloud/docker/_docker.py lib/ansible/modules/cloud/docker/docker_container.py