mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
cloudstack: fix wrong vpc found by name (#22603)
Fail fast if more than one VPC found with given identifier.
This commit is contained in:
parent
c5c0d9086e
commit
2be3418a81
2 changed files with 14 additions and 7 deletions
|
@ -235,12 +235,16 @@ class AnsibleCloudStack(object):
|
|||
self.module.fail_json(msg="No VPCs available.")
|
||||
|
||||
for v in vpcs['vpc']:
|
||||
if vpc in [v['displaytext'], v['name'], v['id']]:
|
||||
if vpc in [v['name'], v['displaytext'], v['id']]:
|
||||
# Fail if the identifyer matches more than one VPC
|
||||
if self.vpc:
|
||||
self.module.fail_json(msg="More than one VPC found with the provided identifyer '%s'" % vpc)
|
||||
else:
|
||||
self.vpc = v
|
||||
if self.vpc:
|
||||
return self._get_by_key(key, self.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):
|
||||
|
|
|
@ -260,9 +260,12 @@ class AnsibleCloudStackVpc(AnsibleCloudStack):
|
|||
if vpcs:
|
||||
vpc_name = self.module.params.get('name')
|
||||
for v in vpcs['vpc']:
|
||||
if vpc_name.lower() in [v['name'].lower(), v['id']]:
|
||||
if vpc_name in [v['name'], v['displaytext'], v['id']]:
|
||||
# Fail if the identifyer matches more than one VPC
|
||||
if self.vpc:
|
||||
self.module.fail_json(msg="More than one VPC found with the provided identifyer '%s'" % vpc_name)
|
||||
else:
|
||||
self.vpc = v
|
||||
break
|
||||
return self.vpc
|
||||
|
||||
def restart_vpc(self):
|
||||
|
|
Loading…
Reference in a new issue