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

cloudstack: fix case insensitivity

cloudstack: fix has_change reports changed for case insensitivity values
This commit is contained in:
Rene Moser 2016-01-10 22:37:20 +01:00
parent c3dd0213ef
commit 766738ef7c

View file

@ -78,6 +78,10 @@ class AnsibleCloudStack(object):
self.returns = {} self.returns = {}
# these values will be casted to int # these values will be casted to int
self.returns_to_int = {} self.returns_to_int = {}
# these keys will be compared case sensitive in self.has_changed()
self.case_sensitive_keys = [
'id',
]
self.module = module self.module = module
self._connect() self._connect()
@ -138,16 +142,14 @@ class AnsibleCloudStack(object):
continue continue
if key in current_dict: if key in current_dict:
if self.case_sensitive_keys and key in self.case_sensitive_keys:
# API returns string for int in some cases, just to make sure if str(value) != str(current_dict[key]):
if isinstance(value, int): return True
current_dict[key] = int(current_dict[key]) # Test for diff in case insensitive way
elif isinstance(value, str): elif str(value).lower() != str(current_dict[key]).lower():
current_dict[key] = str(current_dict[key])
# Only need to detect a singe change, not every item
if value != current_dict[key]:
return True return True
else:
return True
return False return False
@ -218,7 +220,7 @@ class AnsibleCloudStack(object):
vms = self.cs.listVirtualMachines(**args) vms = self.cs.listVirtualMachines(**args)
if vms: if vms:
for v in vms['virtualmachine']: for v in vms['virtualmachine']:
if vm in [ v['name'], v['displayname'], 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)
self.module.fail_json(msg="Virtual machine '%s' not found" % vm) self.module.fail_json(msg="Virtual machine '%s' not found" % vm)
@ -238,7 +240,7 @@ class AnsibleCloudStack(object):
if zones: if zones:
for z in zones['zone']: for z in zones['zone']:
if zone in [ z['name'], z['id'] ]: if zone.lower() in [ z['name'].lower(), z['id'] ]:
self.zone = z self.zone = z
return self._get_by_key(key, self.zone) return self._get_by_key(key, self.zone)
self.module.fail_json(msg="zone '%s' not found" % zone) self.module.fail_json(msg="zone '%s' not found" % zone)