cloudstack: cs_instance: implement vpc support (#3402)

* cloudstack: cs_instance: implement vpc support

* cloudstack: cs_instance: distinguish VPC and non VPC VMs
pull/18777/head
René Moser 8 years ago committed by Matt Clay
parent 46e1380532
commit 5374c7cd09

@ -194,6 +194,12 @@ options:
- Consider switching to HTTP_POST by using C(CLOUDSTACK_METHOD=post) to increase the HTTP_GET size limit of 2KB to 32 KB. - Consider switching to HTTP_POST by using C(CLOUDSTACK_METHOD=post) to increase the HTTP_GET size limit of 2KB to 32 KB.
required: false required: false
default: null default: null
vpc:
description:
- Name of the VPC.
required: false
default: null
version_added: "2.3"
force: force:
description: description:
- Force stop/start the instance if required to apply changes, otherwise a running instance will not be changed. - Force stop/start the instance if required to apply changes, otherwise a running instance will not be changed.
@ -495,15 +501,21 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
instance = self.instance instance = self.instance
if not instance: if not instance:
instance_name = self.get_or_fallback('name', 'display_name') instance_name = self.get_or_fallback('name', 'display_name')
vpc_id = self.get_vpc(key='id')
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'),
'vpcid': vpc_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.cs.listVirtualMachines(**args)
if instances: if instances:
for v in instances['virtualmachine']: for v in instances['virtualmachine']:
# Due the limitation of the API, there is no easy way (yet) to get only those VMs
# not belonging to a VPC.
if not vpc_id and self.is_vm_in_vpc(vm=v):
continue
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
@ -554,12 +566,13 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
if not network_names: if not network_names:
return None return None
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'),
args['zoneid'] = self.get_zone(key='id') 'zoneid': self.get_zone(key='id'),
'vpcid': self.get_vpc(key='id'),
}
networks = self.cs.listNetworks(**args) networks = self.cs.listNetworks(**args)
if not networks: if not networks:
self.module.fail_json(msg="No networks available") self.module.fail_json(msg="No networks available")
@ -935,7 +948,8 @@ def main():
ssh_key = dict(default=None), ssh_key = dict(default=None),
force = dict(choices=BOOLEANS, default=False), force = dict(choices=BOOLEANS, default=False),
tags = dict(type='list', aliases=[ 'tag' ], default=None), tags = dict(type='list', aliases=[ 'tag' ], default=None),
poll_async = dict(choices=BOOLEANS, default=True), vpc = dict(default=None),
poll_async = dict(type='bool', default=True),
)) ))
required_together = cs_required_together() required_together = cs_required_together()

Loading…
Cancel
Save