Merge pull request #734 from ansible/fetch_url-uptimerobot
Port uptimerobot to fetch_url
This commit is contained in:
commit
aa1b4caa8a
1 changed files with 60 additions and 83 deletions
|
@ -51,7 +51,6 @@ EXAMPLES = '''
|
|||
|
||||
import json
|
||||
import urllib
|
||||
import urllib2
|
||||
import time
|
||||
|
||||
API_BASE = "http://api.uptimerobot.com/"
|
||||
|
@ -62,65 +61,43 @@ API_ACTIONS = dict(
|
|||
)
|
||||
|
||||
API_FORMAT = 'json'
|
||||
|
||||
API_NOJSONCALLBACK = 1
|
||||
|
||||
CHANGED_STATE = False
|
||||
|
||||
SUPPORTS_CHECK_MODE = False
|
||||
|
||||
def checkID(params):
|
||||
|
||||
def checkID(module, params):
|
||||
|
||||
data = urllib.urlencode(params)
|
||||
|
||||
full_uri = API_BASE + API_ACTIONS['status'] + data
|
||||
|
||||
req = urllib2.urlopen(full_uri)
|
||||
|
||||
req, info = fetch_url(module, full_uri)
|
||||
result = req.read()
|
||||
|
||||
jsonresult = json.loads(result)
|
||||
|
||||
req.close()
|
||||
|
||||
return jsonresult
|
||||
|
||||
|
||||
def startMonitor(params):
|
||||
def startMonitor(module, params):
|
||||
|
||||
params['monitorStatus'] = 1
|
||||
|
||||
data = urllib.urlencode(params)
|
||||
|
||||
full_uri = API_BASE + API_ACTIONS['editMonitor'] + data
|
||||
|
||||
req = urllib2.urlopen(full_uri)
|
||||
|
||||
req, info = fetch_url(module, full_uri)
|
||||
result = req.read()
|
||||
|
||||
jsonresult = json.loads(result)
|
||||
|
||||
req.close()
|
||||
|
||||
return jsonresult['stat']
|
||||
|
||||
|
||||
def pauseMonitor(params):
|
||||
def pauseMonitor(module, params):
|
||||
|
||||
params['monitorStatus'] = 0
|
||||
|
||||
data = urllib.urlencode(params)
|
||||
|
||||
full_uri = API_BASE + API_ACTIONS['editMonitor'] + data
|
||||
|
||||
req = urllib2.urlopen(full_uri)
|
||||
|
||||
req, info = fetch_url(module, full_uri)
|
||||
result = req.read()
|
||||
|
||||
jsonresult = json.loads(result)
|
||||
|
||||
req.close()
|
||||
|
||||
return jsonresult['stat']
|
||||
|
||||
|
||||
|
@ -143,7 +120,7 @@ def main():
|
|||
noJsonCallback=API_NOJSONCALLBACK
|
||||
)
|
||||
|
||||
check_result = checkID(params)
|
||||
check_result = checkID(module, params)
|
||||
|
||||
if check_result['stat'] != "ok":
|
||||
module.fail_json(
|
||||
|
@ -152,11 +129,9 @@ def main():
|
|||
)
|
||||
|
||||
if module.params['state'] == 'started':
|
||||
monitor_result = startMonitor(params)
|
||||
monitor_result = startMonitor(module, params)
|
||||
else:
|
||||
monitor_result = pauseMonitor(params)
|
||||
|
||||
|
||||
monitor_result = pauseMonitor(module, params)
|
||||
|
||||
module.exit_json(
|
||||
msg="success",
|
||||
|
@ -165,4 +140,6 @@ def main():
|
|||
|
||||
|
||||
from ansible.module_utils.basic import *
|
||||
main()
|
||||
from ansible.module_utils.urls import *
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Reference in a new issue