From 39ece09e8673b14d5790a3981dfc37f3fa9e740d Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Sat, 19 Mar 2016 00:02:33 +0100 Subject: [PATCH] cloudflare_dns: minor code improvments Tweaked some things on top of the well done PR #1768 - json import - fix expetion handling - fix indentation --- .../modules/extras/network/cloudflare_dns.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/ansible/modules/extras/network/cloudflare_dns.py b/lib/ansible/modules/extras/network/cloudflare_dns.py index 7b380450457..a5d03ba5479 100644 --- a/lib/ansible/modules/extras/network/cloudflare_dns.py +++ b/lib/ansible/modules/extras/network/cloudflare_dns.py @@ -18,7 +18,14 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . -import json +try: + import json +except ImportError: + try: + import simplejson as json + except ImportError: + # Let snippet from module_utils/basic.py return a proper error in this case + pass import urllib DOCUMENTATION = ''' @@ -263,7 +270,7 @@ class CloudflareAPI(object): result = json.loads(content) except AttributeError: error_msg += "; The API response was empty" - except JSONDecodeError: + except json.JSONDecodeError: error_msg += "; Failed to parse API response: {0}".format(content) # received an error status but no data with details on what failed @@ -358,10 +365,10 @@ class CloudflareAPI(object): def delete_dns_records(self,**kwargs): params = {} for param in ['port','proto','service','solo','type','record','value','weight','zone']: - if param in kwargs: - params[param] = kwargs[param] - else: - params[param] = getattr(self,param) + if param in kwargs: + params[param] = kwargs[param] + else: + params[param] = getattr(self,param) records = [] search_value = params['value']