-
Notifications
You must be signed in to change notification settings - Fork 10
/
zenApiImpactRouterHelper.py
64 lines (53 loc) · 2.29 KB
/
zenApiImpactRouterHelper.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
import zenApiLib
IMPACT_ROOT = '/zport/dmd/DynamicServices'
class zenApiImpactRouterHelper():
def __init__(self, debug=False):
"""
Initialize the API connection, log in, and store authentication cookie
"""
self.api = zenApiLib.zenConnector(section = 'default', routerName = 'ImpactRouter')
def impact_request(self, method, data=[{}]):
results = self.api.callMethod(method, **dict(data[0]))
return results['result']
def get_services_tree(self):
return self.impact_request('getTree')[0]
def get_service_info(self, uid):
data = {'uid': uid}
return self.impact_request('getInfo', [data])
def delete_node(self, uid):
data = {'uid': uid}
return self.impact_request('deleteNode', [data])
def create_organizer(self, contextUid, id):
data = dict(contextUid=contextUid, id=id)
return self.impact_request('addOrganizer', [data])
def create_service(self, contextUid, id):
data = dict(contextUid=contextUid, id=id)
return self.impact_request('addNode', [data])
def add_impact(self, parentUid, childUids):
if isinstance(childUids, basestring):
childUids = [childUids]
data = dict(targetUid=parentUid, uids=childUids)
return self.impact_request('addToDynamicService', [data])
# Extending the api_helper.py for setting policy gates
def set_policy(self, serviceUid, contextUid, policyType, dependentState, state, threshold, triggerType):
data = {
"permissionUid": serviceUid,
"contextUid": contextUid,
"uid": serviceUid,
"policyType": policyType,
"data": {
"dependentState":dependentState,
"state": state,
"threshold": threshold,
"triggerType": triggerType,
"metaTypes":[]
}
}
return self.impact_request('addStateTrigger', [data])
def get_policies(self, contextUid, serviceUid, policyType):
data = {
"contextUid": contextUid,
"uid": serviceUid,
"policyType": policyType,
}
return self.impact_request('getStateTriggers', [data])