-
Notifications
You must be signed in to change notification settings - Fork 18
/
add-task
executable file
·44 lines (32 loc) · 998 Bytes
/
add-task
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
import sys
import requests
import json
import time
import pprint
endpoint = "http://localhost:8080/tasks/"
host = sys.argv[1]
action = sys.argv[2]
parms = sys.argv[3]
data_dict = {"node_id": host,
"action": action,
"payload": parms}
r = requests.post(endpoint, data=json.dumps(data_dict),
headers={'content-type': 'application/json'})
result = json.loads(r.text)
task_id = result['task']['id']
print "Added task as task id: %s" % task_id,
result = result['task']
while result['state'] == 'pending' or result['state'] == 'running':
r = requests.get("%s%s" % (endpoint, task_id))
result = json.loads(r.text)
sys.stdout.write('.')
sys.stdout.flush()
time.sleep(1)
print "\n\n"
result = json.loads(result['result'])
pp = pprint.PrettyPrinter(indent=4)
print("Result code: %d" % result['result_code'])
print("Result msg: %s" % result['result_str'])
print("Result data:")
pp.pprint(result['result_data'])