1
2
3
4
5
6
7
8
9
10
11
12
13
14 import types
15 import logging
16 log = logging.getLogger("zen.ServiceOrganizer")
17
18 from Globals import DTMLFile
19 from Globals import InitializeClass
20 from AccessControl import ClassSecurityInfo
21 from AccessControl import Permissions
22 from Products.ZenModel.ZenossSecurity import *
23 from Acquisition import aq_base
24 from Commandable import Commandable
25 from ZenPackable import ZenPackable
26
27 from Products.ZenRelations.RelSchema import *
28 from Products.ZenRelations.ZenPropertyManager import iszprop
29
30
31 from Organizer import Organizer
32 from ServiceClass import ServiceClass
33 from IpServiceClass import IpServiceClass
34
42
43 addServiceOrganizer = DTMLFile('dtml/addServiceOrganizer',globals())
44
46 meta_type = "ServiceOrganizer"
47 dmdRootName = "Services"
48 default_catalog = "serviceSearch"
49
50 description = ""
51
52 _properties = (
53 {'id':'description', 'type':'text', 'mode':'w'},
54 )
55
56 _relations = Organizer._relations + ZenPackable._relations + (
57 ("serviceclasses", ToManyCont(ToOne,"Products.ZenModel.ServiceClass","serviceorganizer")),
58 ('userCommands', ToManyCont(ToOne, 'Products.ZenModel.UserCommand', 'commandable')),
59 )
60
61 factory_type_information = (
62 {
63 'id' : 'ServiceOrganizer',
64 'meta_type' : 'ServiceOrganizer',
65 'icon' : 'ServiceOrganizer.gif',
66 'product' : 'ZenModel',
67 'factory' : 'manage_addServiceOrganizer',
68 'immediate_view' : 'serviceOrganizerOverview',
69 'actions' :
70 (
71 { 'id' : 'classes'
72 , 'name' : 'Classes'
73 , 'action' : 'serviceOrganizerOverview'
74 , 'permissions' : (
75 Permissions.view, )
76 },
77 { 'id' : 'manage'
78 , 'name' : 'Administration'
79 , 'action' : 'serviceOrganizerManage'
80 , 'permissions' : ("Manage DMD",)
81 },
82 { 'id' : 'zproperties'
83 , 'name' : 'Configuration Properties'
84 , 'action' : 'zPropertyEdit'
85 , 'permissions' : ("Change Device",)
86 },
87 { 'id' : 'viewHistory'
88 , 'name' : 'Modifications'
89 , 'action' : 'viewHistory'
90 , 'permissions' : (ZEN_VIEW_MODIFICATIONS,)
91 },
92 )
93 },
94 )
95
96 security = ClassSecurityInfo()
97
98 - def __init__(self, id=None, description=None):
104
105
106 - def find(self, query):
120
121
123 """Return generator that goes through all process classes.
124 """
125 for proc in self.serviceclasses.objectValuesGen():
126 yield proc
127 for subgroup in self.children():
128 for proc in subgroup.getSubClassesGen():
129 yield proc
130
131
133 '''Return list of the process classes sorted by sequence.
134 '''
135 def cmpProc(a, b):
136 return cmp(a.sequence, b.sequence)
137 procs = list(self.getSubClassesGen())
138 for i, p in enumerate(procs):
139 p.sequence = i
140 procs.sort(cmpProc)
141 return procs
142
143
151
152
165
180
194
196 """
197 indexes any service class instances in the hierarchy
198 """
199 organizers = [self]
200 while organizers:
201 for org in organizers:
202 for sc in org.serviceclasses():
203 sc._indexInstances()
204
205 oldOrgs = organizers
206 organizers = []
207 for org in oldOrgs:
208 organizers.extend(org.children())
209
210
211 security.declareProtected(ZEN_MANAGE_DMD, 'manage_addServiceClass')
222
223
224 security.declareProtected(ZEN_MANAGE_DMD, 'manage_addIpServiceClass')
235
236
239
240
242 """Remove ServiceClasses from an EventClass.
243 """
244 if not ids: return self()
245 if type(ids) == types.StringType: ids = (ids,)
246 for id in ids:
247 svc = self.serviceclasses._getOb(id)
248 svc.setZenProperty("zMonitor", monitor)
249 if REQUEST: return self()
250
251
253 """Remove ServiceClasses from an EventClass.
254 """
255 if not ids: return self()
256 if type(ids) == types.StringType: ids = (ids,)
257 for id in ids:
258 self.serviceclasses._delObject(id)
259 if REQUEST: return self()
260
261
275
276
282
283
291
292
294 """Create a catalog for ServiceClass searching"""
295 from Products.ZCatalog.ZCatalog import manage_addZCatalog
296 manage_addZCatalog(self, self.default_catalog,
297 self.default_catalog)
298 zcat = self._getOb(self.default_catalog)
299 zcat.addIndex('serviceKeys', 'KeywordIndex')
300 zcat.addColumn('getPrimaryId')
301
302
304 ''' Called by Commandable.doCommand() to ascertain objects on which
305 a UserCommand should be executed.
306 '''
307 targets = []
308 for sc in self.serviceclasses():
309 targets += sc.getUserCommandTargets()
310 for so in self.children():
311 targets += so.getUserCommandTargets()
312 return targets
313
314
317
318
320 """ Parse a string of id and description from a live search
321 """
322 id = str.split(' ')
323 if type(id) == types.TupleType:
324 id = id[0]
325 return id
326
327
328 InitializeClass(ServiceOrganizer)
329