1
2
3
4
5
6
7
8
9
10
11 """
12 Operations for Processes.
13
14 Available at: /zport/dmd/process_router
15 """
16
17 from Products import Zuul
18 from Products.Zuul.decorators import require
19 from Products.Zuul.routers import TreeRouter
20 from Products.ZenUtils.Ext import DirectResponse
21 from Products.ZenUtils.jsonutils import unjson
22 from Products.ZenMessaging.audit import audit
26 """
27 A JSON/ExtDirect interface to operations on processes
28 """
29
31 return Zuul.getFacade('process', self.context)
32
34 """
35 Returns the tree structure of an organizer hierarchy where
36 the root node is the organizer identified by the id parameter.
37
38 @type id: string
39 @param id: Id of the root node of the tree to be returned
40 @rtype: [dictionary]
41 @return: Object representing the tree
42 """
43 facade = self._getFacade()
44 tree = facade.getTree(id)
45 data = Zuul.marshal(tree)
46 return [data]
47
49 """
50 Move a process or organizer from one organizer to another.
51
52 @type uid: string
53 @param uid: UID of the process or organizer to move
54 @type targetUid: string
55 @param targetUid: UID of the organizer to move to
56 @rtype: DirectResponse
57 @return: B{Properties}:
58 - uid: (dictionary) The new uid for moved process or organizer
59 """
60 facade = self._getFacade()
61 old_uid = uid
62 primaryPath = facade.moveProcess(uid, targetUid)
63 id = '.'.join(primaryPath)
64 uid = '/'.join(primaryPath)
65
66
67 audit('UI.Process.Move', uid, old=old_uid)
68 return DirectResponse.succeed(uid=uid, id=id)
69
71 """
72 Get the properties of a process.
73
74 @type uid: string
75 @param uid: Unique identifier of a process
76 @type keys: list
77 @param keys: (optional) List of keys to include in the returned
78 dictionary. If None then all keys will be returned
79 (default: None)
80 @rtype: DirectResponse
81 @return: B{Properties}
82 - data: (dictionary) Object representing a process's properties
83 """
84 facade = self._getFacade()
85 process = facade.getInfo(uid)
86 data = Zuul.marshal(process, keys)
87 return DirectResponse.succeed(data=data)
88
89 @require('Manage DMD')
91 """
92 Set attributes on a process.
93 This method accepts any keyword argument for the property that you wish
94 to set. The only required property is "uid".
95
96 @type uid: string
97 @keyword uid: Unique identifier of a process
98 @rtype: DirectResponse
99 @return: B{Properties}
100 - data: (dictionary) Object representing a process's new properties
101 """
102 facade = self._getFacade()
103 processUid = data['uid']
104 process = facade.getInfo(processUid)
105 audit('UI.Process.Edit', processUid, data_=data, skipFields_=('uid'))
106 return DirectResponse.succeed(data=Zuul.unmarshal(data, process))
107
108 - def getInstances(self, uid, start=0, params=None, limit=50, sort='name',
109 page=None, dir='ASC'):
110 """
111 Get a list of instances for a process UID.
112
113 @type uid: string
114 @param uid: Process UID to get instances of
115 @type start: integer
116 @param start: (optional) Offset to return the results from; used in
117 pagination (default: 0)
118 @type params: dictionary
119 @param params: (optional) Key-value pair of filters for this search.
120 @type limit: integer
121 @param limit: (optional) Number of items to return; used in pagination
122 (default: 50)
123 @type sort: string
124 @param sort: (optional) Key on which to sort the return results (default:
125 'name')
126 @type dir: string
127 @param dir: (optional) Sort order; can be either 'ASC' or 'DESC'
128 (default: 'ASC')
129 @rtype: DirectResponse
130 @return: B{Properties}:
131 - data: ([dictionary]) List of objects representing process instances
132 - total: (integer) Total number of instances
133 """
134 facade = self._getFacade()
135 instances = facade.getInstances(uid, start, limit, sort, dir, params)
136 keys = ['device', 'monitored', 'pingStatus', 'processName', 'name', 'uid']
137 data = Zuul.marshal(instances, keys)
138 return DirectResponse.succeed(data=data, totalCount=instances.total)
139
141 """
142 Get the current processes sequence.
143
144 @rtype: DirectResponse
145 @return: B{Properties}:
146 - data: ([dictionary]) List of objects representing processes in
147 sequence order
148 """
149 facade = self._getFacade()
150 sequence = facade.getSequence()
151 data = Zuul.marshal(sequence)
152 return DirectResponse.succeed(data=data)
153
155 """
156 Set the current processes sequence.
157
158 @type uids: [string]
159 @param uids: The set of process uid's in the desired sequence
160 @rtype: DirectResponse
161 @return: Success message
162 """
163 facade = self._getFacade()
164 facade.setSequence(uids)
165 audit('UI.Process.SetSequence', sequence=uids)
166 return DirectResponse.succeed()
167
168
169 - def query(self, limit=None, start=None, sort=None, dir=None, params=None,
170 page=None, history=False, uid=None, criteria=()):
171 """
172 Retrieve a list of processes based on a set of parameters.
173
174 @type limit: integer
175 @param limit: (optional) Number of items to return; used in pagination
176 (default: None)
177 @type start: integer
178 @param start: (optional) Offset to return the results from; used in
179 pagination (default: None)
180 @type sort: string
181 @param sort: (optional) Key on which to sort the return results (default:
182 None)
183 @type dir: string
184 @param dir: (optional) Sort order; can be either 'ASC' or 'DESC'
185 (default: None)
186 @type params: dictionary
187 @param params: (optional) Key-value pair of filters for this search.
188 @type history: boolean
189 @param history: not used
190 @type uid: string
191 @param uid: Service class UID to query
192 @type criteria: list
193 @param criteria: not used
194 @rtype: DirectResponse
195 @return: B{Properties}:
196 - processes: ([dictionary]) List of objects representing processes
197 - totalCount: (integer) Total number of processes
198 - hash: (string) Hashcheck of the current processes state
199 - disabled: (boolean) True if current user cannot manage processes
200 """
201 facade = self._getFacade()
202 if uid is None:
203 uid = self.context
204
205 if isinstance(params, basestring):
206 params = unjson(params)
207
208 processes = facade.getList(limit, start, sort, dir, params, uid,
209 criteria)
210 disabled = not Zuul.checkPermission('Manage DMD')
211
212 data = Zuul.marshal(processes)
213 return DirectResponse(processes=data, totalCount=processes.total,
214 hash=processes.hash_, disabled=disabled)
215