1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

cs_instance_facts: fix pep8 (#31606)

This commit is contained in:
René Moser 2017-10-12 06:00:14 +02:00 committed by Jordan Borean
parent 9333684929
commit 540d53327d
2 changed files with 30 additions and 36 deletions

View file

@ -29,23 +29,18 @@ options:
domain: domain:
description: description:
- Domain the instance is related to. - Domain the instance is related to.
required: false
default: null
account: account:
description: description:
- Account the instance is related to. - Account the instance is related to.
required: false
default: null
project: project:
description: description:
- Project the instance is related to. - Project the instance is related to.
required: false
default: null
extends_documentation_fragment: cloudstack extends_documentation_fragment: cloudstack
''' '''
EXAMPLES = ''' EXAMPLES = '''
- cs_instance_facts: - name: gather instance facts
cs_instance_facts:
name: web-vm-1 name: web-vm-1
delegate_to: localhost delegate_to: localhost
@ -202,21 +197,21 @@ class AnsibleCloudStackInstanceFacts(AnsibleCloudStack):
'cloudstack_instance': None, 'cloudstack_instance': None,
} }
def get_instance(self): def get_instance(self):
instance = self.instance instance = self.instance
if not instance: if not instance:
instance_name = self.module.params.get('name') instance_name = self.module.params.get('name')
args = {} args = {
args['account'] = self.get_account(key='name') 'account': self.get_account(key='name'),
args['domainid'] = self.get_domain(key='id') 'domainid': self.get_domain(key='id'),
args['projectid'] = self.get_project(key='id') 'projectid': self.get_project(key='id'),
}
# Do not pass zoneid, as the instance name must be unique across zones. # 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: if instances:
for v in instances['virtualmachine']: 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 self.instance = v
break break
return self.instance return self.instance
@ -224,13 +219,14 @@ class AnsibleCloudStackInstanceFacts(AnsibleCloudStack):
def get_volumes(self, instance): def get_volumes(self, instance):
volume_details = [] volume_details = []
if instance: if instance:
args = {} args = {
args['account'] = instance.get('account') 'account': self.get_account(key='name'),
args['domainid'] = instance.get('domainid') 'domainid': self.get_domain(key='id'),
args['projectid'] = instance.get('projectid') 'projectid': self.get_project(key='id'),
args['virtualmachineid'] = instance['id'] 'virtualmachineid': instance['id'],
}
volumes = self.cs.listVolumes(**args) volumes = self.query_api('listVolumes', **args)
if volumes: if volumes:
for vol in volumes['volume']: for vol in volumes['volume']:
volume_details.append({'size': vol['size'], 'type': vol['type'], 'name': vol['name']}) 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) self.facts['cloudstack_instance'] = self.get_result(instance)
return self.facts return self.facts
def get_result(self, instance): def get_result(self, instance):
super(AnsibleCloudStackInstanceFacts, self).get_result(instance) super(AnsibleCloudStackInstanceFacts, self).get_result(instance)
if instance: if instance:
@ -270,10 +265,10 @@ class AnsibleCloudStackInstanceFacts(AnsibleCloudStack):
def main(): def main():
argument_spec = cs_argument_spec() argument_spec = cs_argument_spec()
argument_spec.update(dict( argument_spec.update(dict(
name = dict(required=True), name=dict(required=True),
domain = dict(default=None), domain=dict(),
account = dict(default=None), account=dict(),
project = dict(default=None), project=dict(),
)) ))
module = AnsibleModule( module = AnsibleModule(

View file

@ -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/azure/azure_rm_virtualnetwork_facts.py
lib/ansible/modules/cloud/centurylink/clc_loadbalancer.py lib/ansible/modules/cloud/centurylink/clc_loadbalancer.py
lib/ansible/modules/cloud/cloudstack/cs_instance.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/cloudstack/_cs_nic.py
lib/ansible/modules/cloud/docker/_docker.py lib/ansible/modules/cloud/docker/_docker.py
lib/ansible/modules/cloud/docker/docker_container.py lib/ansible/modules/cloud/docker/docker_container.py