From 766738ef7cdc9c593ae8cfd7bf6458bef9b68969 Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Sun, 10 Jan 2016 22:37:20 +0100 Subject: [PATCH] cloudstack: fix case insensitivity cloudstack: fix has_change reports changed for case insensitivity values --- lib/ansible/module_utils/cloudstack.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/ansible/module_utils/cloudstack.py b/lib/ansible/module_utils/cloudstack.py index 53d142847d6..d9b29fefe7a 100644 --- a/lib/ansible/module_utils/cloudstack.py +++ b/lib/ansible/module_utils/cloudstack.py @@ -78,6 +78,10 @@ class AnsibleCloudStack(object): self.returns = {} # these values will be casted 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._connect() @@ -138,16 +142,14 @@ class AnsibleCloudStack(object): continue if key in current_dict: - - # API returns string for int in some cases, just to make sure - if isinstance(value, int): - current_dict[key] = int(current_dict[key]) - elif isinstance(value, str): - current_dict[key] = str(current_dict[key]) - - # Only need to detect a singe change, not every item - if value != current_dict[key]: + if self.case_sensitive_keys and key in self.case_sensitive_keys: + if str(value) != str(current_dict[key]): + return True + # Test for diff in case insensitive way + elif str(value).lower() != str(current_dict[key]).lower(): return True + else: + return True return False @@ -218,7 +220,7 @@ class AnsibleCloudStack(object): vms = self.cs.listVirtualMachines(**args) if vms: 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 return self._get_by_key(key, self.vm) self.module.fail_json(msg="Virtual machine '%s' not found" % vm) @@ -238,7 +240,7 @@ class AnsibleCloudStack(object): if zones: for z in zones['zone']: - if zone in [ z['name'], z['id'] ]: + if zone.lower() in [ z['name'].lower(), z['id'] ]: self.zone = z return self._get_by_key(key, self.zone) self.module.fail_json(msg="zone '%s' not found" % zone)