cloudstack: cs_instance: revert VPC support (#22629)
Partly reverts 5374c7cd09
This commit is contained in:
parent
a2b6844858
commit
0ee108bda0
2 changed files with 1 additions and 29 deletions
|
@ -245,13 +245,6 @@ class AnsibleCloudStack(object):
|
||||||
return self._get_by_key(key, self.vpc)
|
return self._get_by_key(key, self.vpc)
|
||||||
self.module.fail_json(msg="VPC '%s' not found" % vpc)
|
self.module.fail_json(msg="VPC '%s' not found" % vpc)
|
||||||
|
|
||||||
def is_vm_in_vpc(self, vm):
|
|
||||||
for n in vm.get('nic'):
|
|
||||||
if n.get('isdefault', False):
|
|
||||||
return self.is_vpc_network(network_id=n['networkid'])
|
|
||||||
self.module.fail_json(msg="VM has no default nic")
|
|
||||||
|
|
||||||
|
|
||||||
def is_vpc_network(self, network_id):
|
def is_vpc_network(self, network_id):
|
||||||
"""Returns True if network is in VPC."""
|
"""Returns True if network is in VPC."""
|
||||||
# This is an efficient way to query a lot of networks at a time
|
# This is an efficient way to query a lot of networks at a time
|
||||||
|
@ -383,23 +376,16 @@ class AnsibleCloudStack(object):
|
||||||
if not vm:
|
if not vm:
|
||||||
self.module.fail_json(msg="Virtual machine param 'vm' is required")
|
self.module.fail_json(msg="Virtual machine param 'vm' is required")
|
||||||
|
|
||||||
vpc_id = self.get_vpc(key='id')
|
|
||||||
|
|
||||||
args = {
|
args = {
|
||||||
'account': self.get_account(key='name'),
|
'account': self.get_account(key='name'),
|
||||||
'domainid': self.get_domain(key='id'),
|
'domainid': self.get_domain(key='id'),
|
||||||
'projectid': self.get_project(key='id'),
|
'projectid': self.get_project(key='id'),
|
||||||
'zoneid': self.get_zone(key='id'),
|
'zoneid': self.get_zone(key='id'),
|
||||||
'networkid': self.get_network(key='id'),
|
'networkid': self.get_network(key='id'),
|
||||||
'vpcid': vpc_id,
|
|
||||||
}
|
}
|
||||||
vms = self.cs.listVirtualMachines(**args)
|
vms = self.cs.listVirtualMachines(**args)
|
||||||
if vms:
|
if vms:
|
||||||
for v in vms['virtualmachine']:
|
for v in vms['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 vm.lower() in [ v['name'].lower(), v['displayname'].lower(), v['id'] ]:
|
if vm.lower() in [ v['name'].lower(), v['displayname'].lower(), v['id'] ]:
|
||||||
self.vm = v
|
self.vm = v
|
||||||
return self._get_by_key(key, self.vm)
|
return self._get_by_key(key, self.vm)
|
||||||
|
|
|
@ -198,12 +198,6 @@ 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.
|
||||||
|
@ -524,22 +518,16 @@ 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 = {
|
||||||
'account': self.get_account(key='name'),
|
'account': self.get_account(key='name'),
|
||||||
'domainid': self.get_domain(key='id'),
|
'domainid': self.get_domain(key='id'),
|
||||||
'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
|
if instance_name.lower() in [v['name'].lower(), v['displayname'].lower(), v['id']]:
|
||||||
# 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'] ]:
|
|
||||||
self.instance = v
|
self.instance = v
|
||||||
break
|
break
|
||||||
return self.instance
|
return self.instance
|
||||||
|
@ -636,7 +624,6 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
|
||||||
'domainid': self.get_domain(key='id'),
|
'domainid': self.get_domain(key='id'),
|
||||||
'projectid': self.get_project(key='id'),
|
'projectid': self.get_project(key='id'),
|
||||||
'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:
|
||||||
|
@ -1017,7 +1004,6 @@ def main():
|
||||||
ssh_key = dict(default=None),
|
ssh_key = dict(default=None),
|
||||||
force = dict(type='bool', default=False),
|
force = dict(type='bool', default=False),
|
||||||
tags = dict(type='list', aliases=[ 'tag' ], default=None),
|
tags = dict(type='list', aliases=[ 'tag' ], default=None),
|
||||||
vpc = dict(default=None),
|
|
||||||
poll_async = dict(type='bool', default=True),
|
poll_async = dict(type='bool', default=True),
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue