cloudflare_dns: minor code improvments

Tweaked some things on top of the well done PR #1768

- json import
- fix expetion handling
- fix indentation
pull/18777/head
Rene Moser 9 years ago committed by Matt Clay
parent 68fc8e75f6
commit 39ece09e86

@ -18,7 +18,14 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
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 import urllib
DOCUMENTATION = ''' DOCUMENTATION = '''
@ -263,7 +270,7 @@ class CloudflareAPI(object):
result = json.loads(content) result = json.loads(content)
except AttributeError: except AttributeError:
error_msg += "; The API response was empty" error_msg += "; The API response was empty"
except JSONDecodeError: except json.JSONDecodeError:
error_msg += "; Failed to parse API response: {0}".format(content) error_msg += "; Failed to parse API response: {0}".format(content)
# received an error status but no data with details on what failed # 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): def delete_dns_records(self,**kwargs):
params = {} params = {}
for param in ['port','proto','service','solo','type','record','value','weight','zone']: for param in ['port','proto','service','solo','type','record','value','weight','zone']:
if param in kwargs: if param in kwargs:
params[param] = kwargs[param] params[param] = kwargs[param]
else: else:
params[param] = getattr(self,param) params[param] = getattr(self,param)
records = [] records = []
search_value = params['value'] search_value = params['value']

Loading…
Cancel
Save