From efd122c2f0beed074b412bc9b9f9320757b20734 Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Tue, 22 Sep 2015 14:44:08 +0200 Subject: [PATCH] cloudstack: add returns_to_int return handling into utils It is not uncommon that the API returns string for int values e.g. ports in listFirewallRules or listPortForwardings, --- lib/ansible/module_utils/cloudstack.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/ansible/module_utils/cloudstack.py b/lib/ansible/module_utils/cloudstack.py index e3d2614fe69..5b73228abcf 100644 --- a/lib/ansible/module_utils/cloudstack.py +++ b/lib/ansible/module_utils/cloudstack.py @@ -75,6 +75,8 @@ class AnsibleCloudStack(object): # Init returns dict for use in subclasses self.returns = {} + # these values will be casted to int + self.returns_to_int = {} self.module = module self._connect() @@ -408,6 +410,11 @@ class AnsibleCloudStack(object): if search_key in resource: self.result[return_key] = resource[search_key] + # Bad bad API does not always return int when it should. + for search_key, return_key in self.returns_to_int.iteritems(): + if search_key in resource: + self.result[return_key] = int(resource[search_key]) + # Special handling for tags if 'tags' in resource: self.result['tags'] = []