Fix undefined variables, basestring usage, and some associated python3 issues

This commit is contained in:
Toshio Kuratomi
2017-07-22 18:15:46 -07:00
parent 9f7b0dfc30
commit 225fa5d092
84 changed files with 652 additions and 963 deletions

View File

@@ -88,17 +88,9 @@ EXAMPLES='''
'''
import base64
import json
import os
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
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url
@@ -205,6 +197,7 @@ def delete_meter(module, name, apiid, apikey):
if meter_id is None:
return 1, "Meter does not exist, so can't delete it"
else:
action = "delete"
response, info = http_request(module, name, apiid, apikey, action, meter_id)
if info['status'] != 200:
module.fail_json(msg="Failed to delete meter")
@@ -230,7 +223,7 @@ def download_request(module, name, apiid, apikey, cert_type):
if info['status'] != 200:
module.fail_json(msg="Failed to connect to api host to download certificate")
if result:
if response:
try:
cert_file_path = '%s/%s.pem' % (config_directory,cert_type)
body = response.read()
@@ -276,4 +269,3 @@ def main():
if __name__ == '__main__':
main()

View File

@@ -108,6 +108,10 @@ EXAMPLES = '''
end_time: 1395954406
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url
def post_annotation(module):
user = module.params['user']
api_key = module.params['api_key']
@@ -139,7 +143,7 @@ def post_annotation(module):
module.params['url_password'] = api_key
response, info = fetch_url(module, url, data=json_body, headers=headers)
if info['status'] != 200:
module.fail_json(msg="Request Failed", reason=e.reason)
module.fail_json(msg="Request Failed", reason=info.get('msg', ''), status_code=info['status'])
response = response.read()
module.exit_json(changed=True, annotation=response)
@@ -161,7 +165,6 @@ def main():
post_annotation(module)
from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
if __name__ == '__main__':
main()

View File

@@ -190,6 +190,11 @@ EXAMPLES = '''
RETURN = ''' # '''
import datetime
import json
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
from ansible.module_utils.urls import open_url
def get_api_auth_headers(api_id, api_key, url, statuspage):
@@ -210,8 +215,8 @@ def get_api_auth_headers(api_id, api_key, url, statuspage):
else:
auth_headers = headers
auth_content = data
except:
return 1, None, None, e
except Exception as e:
return 1, None, None, to_native(e)
return 0, auth_headers, auth_content, None
@@ -320,9 +325,8 @@ def create_maintenance(auth_headers, url, statuspage, host_ids,
if data["status"]["error"] == "yes":
return 1, None, data["status"]["message"]
except Exception:
e = get_exception()
return 1, None, str(e)
except Exception as e:
return 1, None, to_native(e)
return 0, None, None
@@ -339,9 +343,8 @@ def delete_maintenance(auth_headers, url, statuspage, maintenance_id):
data = json.loads(response.read())
if data["status"]["error"] == "yes":
return 1, None, "Invalid maintenance_id"
except Exception:
e = get_exception()
return 1, None, str(e)
except Exception as e:
return 1, None, to_native(e)
return 0, None, None
@@ -475,7 +478,6 @@ def main():
module.fail_json(
msg="Failed to delete maintenance: %s" % error)
from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
if __name__ == '__main__':
main()