diff options
author | Toshio Kuratomi <a.badger@gmail.com> | 2015-07-27 15:24:56 -0700 |
---|---|---|
committer | Toshio Kuratomi <a.badger@gmail.com> | 2015-07-27 15:24:56 -0700 |
commit | 551972c26d01ddd85928d9f91e2c88a19627d8ce (patch) | |
tree | 801bfe0e280953c5dd750f79a206034feb333dc4 | |
parent | 3cbe8cea0b6de9279feeeb0720479d4f26160f8e (diff) | |
parent | 626977f90e68282db4449f4cd3d8be7361cef597 (diff) | |
download | ansible-modules-extras-551972c26d01ddd85928d9f91e2c88a19627d8ce.tar.gz |
Merge pull request #733 from ansible/fetch_url-librato
Port librato_annotation to fetch_url
-rw-r--r-- | monitoring/librato_annotation.py | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/monitoring/librato_annotation.py b/monitoring/librato_annotation.py index c606dfdc..4927a9cf 100644 --- a/monitoring/librato_annotation.py +++ b/monitoring/librato_annotation.py @@ -105,9 +105,6 @@ EXAMPLES = ''' end_time: 1395954406 ''' - -import urllib2 - def post_annotation(module): user = module.params['user'] api_key = module.params['api_key'] @@ -134,10 +131,9 @@ def post_annotation(module): headers = {} headers['Content-Type'] = 'application/json' headers['Authorization'] = "Basic " + base64.b64encode(user + ":" + api_key).strip() - req = urllib2.Request(url, json_body, headers) - try: - response = urllib2.urlopen(req) - except urllib2.HTTPError, e: + + response, info = fetch_url(module, url, data=json_body, headers=headers) + if info['status'] != 200: module.fail_json(msg="Request Failed", reason=e.reason) response = response.read() module.exit_json(changed=True, annotation=response) @@ -161,4 +157,6 @@ def main(): post_annotation(module) from ansible.module_utils.basic import * -main() +from ansible.module_utils.urls import * +if __name__ == '__main__': + main() |