forked from CMSCompOps/WmAgentScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wtcClient.py
72 lines (60 loc) · 2.14 KB
/
wtcClient.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
import httplib
import ssl
import json
class wtcClient(object):
def __init__(self):
self.conn = None
if not os.path.exists('Unified/secret_act.txt'):
print 'Needs to be called from same directory as key.json'
return
with open('Unified/secret_act.txt', 'r') as key_file:
self.key_info = json.load(key_file)
self._make_conn()
def _make_conn(self):
self.conn = httplib.HTTPSConnection(self.key_info['url'], self.key_info['port'],context=ssl._create_unverified_context())
#self.conn = httplib.HTTPConnection(self.key_info['url'], self.key_info['port'])
def check(self):
## get something from the machine
pass
def get_actions(self):
try:
return self._get_actions()
except:
try:
self._make_conn()
return self._get_actions()
except Exception as e:
print str(e)
return None
def _get_actions(self):
self.conn.request(
'GET',
'/getaction?days=15',
#'/getaction?days=15&key=%s'%self.key_info['key'],
json.dumps({'key': self.key_info['key']}),
headers = {'Content-type': 'application/json'})
r= self.conn.getresponse().read()
action_list = json.loads( r )
return action_list
def remove_action(self, *args):
try:
return self._remove_action(*args)
except:
try:
self._make_conn()
return self._remove_action(*args)
except Exception as e:
print str(e)
return None
def _remove_action(self, *args):
self.conn.request(
'POST', '/reportaction',
json.dumps({'key': self.key_info['key'], 'workflows': args}),
{'Content-type': 'application/json'})
r= self.conn.getresponse().read()
jr = json.loads( r )
print jr
#conn.close()
#return (r == 'Done')
return all([w in jr['success'] for w in args])