Fix remaining python3 compile problems

This commit is contained in:
Toshio Kuratomi
2016-10-23 16:24:38 -07:00
committed by Matt Clay
parent 3901fe72d3
commit ea05c56a41
19 changed files with 279 additions and 196 deletions

View File

@@ -22,19 +22,6 @@ You should have received a copy of the GNU General Public License
along with Ansible. If not, see <http://www.gnu.org/licenses/>.
"""
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 datetime
import base64
import os
DOCUMENTATION = '''
module: boundary_meter
@@ -88,15 +75,33 @@ EXAMPLES='''
'''
import base64
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
api_host = "api.boundary.com"
config_directory = "/etc/bprobe"
# "resource" like thing or apikey?
def auth_encode(apikey):
auth = base64.standard_b64encode(apikey)
auth.replace("\n", "")
return auth
def build_url(name, apiid, action, meter_id=None, cert_type=None):
if action == "create":
return 'https://%s/%s/meters' % (api_host, apiid)
@@ -198,7 +203,7 @@ def delete_meter(module, name, apiid, apikey):
try:
cert_file = '%s/%s.pem' % (config_directory,cert_type)
os.remove(cert_file)
except OSError, e:
except OSError:
module.fail_json("Failed to remove " + cert_type + ".pem file")
return 0, "Meter " + name + " deleted"
@@ -221,7 +226,7 @@ def download_request(module, name, apiid, apikey, cert_type):
cert_file.write(body)
cert_file.close()
os.chmod(cert_file_path, int('0600', 8))
except:
except:
module.fail_json("Could not write to certificate file")
return True
@@ -256,9 +261,7 @@ def main():
module.exit_json(status=result,changed=True)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
if __name__ == '__main__':
main()

View File

@@ -17,9 +17,6 @@
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import requests
import time
import json
DOCUMENTATION = '''
---
@@ -86,6 +83,15 @@ EXAMPLES = '''
start_time: 1395940006
end_time: 1395954407
'''
import json
import time
import requests
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
def post_annotation(annotation, api_key):
''' Takes annotation dict and api_key string'''
base_url = 'https://api.circonus.com/v2'
@@ -95,6 +101,7 @@ def post_annotation(annotation, api_key):
resp.raise_for_status()
return resp
def create_annotation(module):
''' Takes ansible module object '''
annotation = {}
@@ -116,6 +123,8 @@ def create_annotation(module):
annotation['description'] = module.params['description']
annotation['title'] = module.params['title']
return annotation
def build_headers(api_token):
'''Takes api token, returns headers with it included.'''
headers = {'X-Circonus-App-Name': 'ansible',
@@ -123,6 +132,7 @@ def build_headers(api_token):
'Accept': 'application/json'}
return headers
def main():
'''Main function, dispatches logic'''
module = AnsibleModule(
@@ -139,9 +149,11 @@ def main():
annotation = create_annotation(module)
try:
resp = post_annotation(annotation, module.params['api_key'])
except requests.exceptions.RequestException, err_str:
except requests.exceptions.RequestException:
err_str = get_exception()
module.fail_json(msg='Request Failed', reason=err_str)
module.exit_json(changed=True, annotation=resp.json())
from ansible.module_utils.basic import *
main()
if __name__ == '__main__':
main()

View File

@@ -19,13 +19,6 @@
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# import module snippets
# Import Datadog
try:
from datadog import initialize, api
HAS_DATADOG = True
except:
HAS_DATADOG = False
DOCUMENTATION = '''
---
module: datadog_monitor
@@ -144,6 +137,16 @@ datadog_monitor:
app_key: "87ce4a24b5553d2e482ea8a8500e71b8ad4554ff"
'''
# Import Datadog
try:
from datadog import initialize, api
HAS_DATADOG = True
except:
HAS_DATADOG = False
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
def main():
module = AnsibleModule(
@@ -211,7 +214,8 @@ def _post_monitor(module, options):
module.fail_json(msg=str(msg['errors']))
else:
module.exit_json(changed=True, msg=msg)
except Exception, e:
except Exception:
e = get_exception()
module.fail_json(msg=str(e))
def _equal_dicts(a, b, ignore_keys):
@@ -234,7 +238,8 @@ def _update_monitor(module, monitor, options):
module.exit_json(changed=False, msg=msg)
else:
module.exit_json(changed=True, msg=msg)
except Exception, e:
except Exception:
e = get_exception()
module.fail_json(msg=str(e))
@@ -269,7 +274,8 @@ def delete_monitor(module):
try:
msg = api.Monitor.delete(monitor['id'])
module.exit_json(changed=True, msg=msg)
except Exception, e:
except Exception:
e = get_exception()
module.fail_json(msg=str(e))
@@ -288,7 +294,8 @@ def mute_monitor(module):
else:
msg = api.Monitor.mute(id=monitor['id'], silenced=module.params['silenced'])
module.exit_json(changed=True, msg=msg)
except Exception, e:
except Exception:
e = get_exception()
module.fail_json(msg=str(e))
@@ -301,10 +308,10 @@ def unmute_monitor(module):
try:
msg = api.Monitor.unmute(monitor['id'])
module.exit_json(changed=True, msg=msg)
except Exception, e:
except Exception:
e = get_exception()
module.fail_json(msg=str(e))
from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
main()
if __name__ == '__main__':
main()

View File

@@ -78,6 +78,11 @@ EXAMPLES = '''
import urllib
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils.urls import fetch_url
def main():
module = AnsibleModule(
@@ -120,7 +125,8 @@ def main():
try:
data = urllib.urlencode(params)
response, info = fetch_url(module, url, data=data)
except Exception, e:
except Exception:
e = get_exception()
module.fail_json(msg='Unable to notify Rollbar: %s' % e)
else:
if info['status'] == 200:
@@ -128,7 +134,6 @@ def main():
else:
module.fail_json(msg='HTTP result code: %d connecting to %s' % (info['status'], url))
from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
main()
if __name__ == '__main__':
main()

View File

@@ -102,6 +102,10 @@ 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.pycompat24 import get_exception
from ansible.module_utils.urls import fetch_url
def send_deploy_event(module, key, revision_id, deployed_by='Ansible', deployed_to=None, repository=None):
"""Send a deploy event to Stackdriver"""
@@ -195,7 +199,8 @@ def main():
module.fail_json(msg="revision_id required for deploy events")
try:
send_deploy_event(module, key, revision_id, deployed_by, deployed_to, repository)
except Exception, e:
except Exception:
e = get_exception()
module.fail_json(msg="unable to sent deploy event: %s" % e)
if event == 'annotation':
@@ -203,14 +208,13 @@ def main():
module.fail_json(msg="msg required for annotation events")
try:
send_annotation_event(module, key, msg, annotated_by, level, instance_id, event_epoch)
except Exception, e:
except Exception:
e = get_exception()
module.fail_json(msg="unable to sent annotation event: %s" % e)
changed = True
module.exit_json(changed=changed, deployed_by=deployed_by)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
main()
if __name__ == '__main__':
main()