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

cloudstack: add _has_changed() to utils

Generic method to compare values in dict.
This commit is contained in:
Rene Moser 2015-04-24 19:16:42 +02:00
parent 765c8fe368
commit 6354ca0718

View file

@ -69,6 +69,27 @@ class AnsibleCloudStack:
self.cs = CloudStack(**read_config()) self.cs = CloudStack(**read_config())
def _has_changed(self, want_dict, current_dict, only_keys=None):
for key, value in want_dict.iteritems():
# Optionally limit by a list of keys
if only_keys and key not in only_keys:
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]:
return True
return False
def _get_by_key(self, key=None, my_dict={}): def _get_by_key(self, key=None, my_dict={}):
if key: if key:
if key in my_dict: if key in my_dict: