1
2
3
4
5
6
7
8
9
10
11
12
13
14 import logging
15 log = logging.getLogger("zen.ServiceOrganizer")
16
17 from Globals import DTMLFile
18 from Globals import InitializeClass
19 from AccessControl import ClassSecurityInfo
20 from AccessControl import Permissions
21 from Products.ZenModel.ZenossSecurity import *
22 from Acquisition import aq_base
23 from Commandable import Commandable
24 from ZenPackable import ZenPackable
25
26 from Products.ZenRelations.RelSchema import *
27 from Products.ZenRelations.ZenPropertyManager import iszprop
28
29
30 from Organizer import Organizer
31 from ServiceClass import ServiceClass
32 from IpServiceClass import IpServiceClass
33
41
42 addServiceOrganizer = DTMLFile('dtml/addServiceOrganizer',globals())
43
45 meta_type = "ServiceOrganizer"
46 dmdRootName = "Services"
47 default_catalog = "serviceSearch"
48
49 description = ""
50
51 _properties = (
52 {'id':'description', 'type':'text', 'mode':'w'},
53 )
54
55 _relations = Organizer._relations + ZenPackable._relations + (
56 ("serviceclasses", ToManyCont(ToOne,"Products.ZenModel.ServiceClass","serviceorganizer")),
57 ('userCommands', ToManyCont(ToOne, 'Products.ZenModel.UserCommand', 'commandable')),
58 )
59
60 factory_type_information = (
61 {
62 'id' : 'ServiceOrganizer',
63 'meta_type' : 'ServiceOrganizer',
64 'icon' : 'ServiceOrganizer.gif',
65 'product' : 'ZenModel',
66 'factory' : 'manage_addServiceOrganizer',
67 'immediate_view' : 'serviceOrganizerOverview',
68 'actions' :
69 (
70 { 'id' : 'classes'
71 , 'name' : 'Classes'
72 , 'action' : 'serviceOrganizerOverview'
73 , 'permissions' : (
74 Permissions.view, )
75 },
76 { 'id' : 'manage'
77 , 'name' : 'Administration'
78 , 'action' : 'serviceOrganizerManage'
79 , 'permissions' : ("Manage DMD",)
80 },
81 { 'id' : 'zproperties'
82 , 'name' : 'Configuration Properties'
83 , 'action' : 'zPropertyEdit'
84 , 'permissions' : ("Change Device",)
85 },
86 )
87 },
88 )
89
90 security = ClassSecurityInfo()
91
92 - def __init__(self, id=None, description=None):
98
99
100 - def find(self, query):
114
115
117 """Checks a valid id
118 """
119 relationship = getattr(self, 'serviceclasses')
120 try:
121 relationship.checkValidId(id)
122 return True
123 except Exception as e:
124 return str(e)
125
126
128 """Return generator that goes through all process classes.
129 """
130 for proc in self.serviceclasses.objectValuesGen():
131 yield proc
132 for subgroup in self.children():
133 for proc in subgroup.getSubClassesGen():
134 yield proc
135
136
138 '''Return list of the process classes sorted by sequence.
139 '''
140 def cmpProc(a, b):
141 return cmp(a.sequence, b.sequence)
142 procs = list(self.getSubClassesGen())
143 for i, p in enumerate(procs):
144 p.sequence = i
145 procs.sort(cmpProc)
146 return procs
147
148
156
157
170
185
199
201 """
202 indexes any service class instances in the hierarchy
203 """
204 organizers = [self]
205 while organizers:
206 for org in organizers:
207 for sc in org.serviceclasses():
208 sc._indexInstances()
209
210 oldOrgs = organizers
211 organizers = []
212 for org in oldOrgs:
213 organizers.extend(org.children())
214
215
216 security.declareProtected(ZEN_MANAGE_DMD, 'manage_addServiceClass')
227
228
229 security.declareProtected(ZEN_MANAGE_DMD, 'manage_addIpServiceClass')
240
241
244
245
247 """Remove ServiceClasses from an EventClass.
248 """
249 if not ids: return self()
250 if isinstance(ids, basestring): ids = (ids,)
251 for id in ids:
252 svc = self.serviceclasses._getOb(id)
253 svc.setZenProperty("zMonitor", monitor)
254 if REQUEST: return self()
255
256
258 """Remove ServiceClasses from an EventClass.
259 """
260 if not ids: return self()
261 if isinstance(ids, basestring): ids = (ids,)
262 for id in ids:
263 self.serviceclasses._delObject(id)
264 if REQUEST: return self()
265
266
280
281
287
288
296
297
299 """Create a catalog for ServiceClass searching"""
300 from Products.ZCatalog.ZCatalog import manage_addZCatalog
301 manage_addZCatalog(self, self.default_catalog,
302 self.default_catalog)
303 zcat = self._getOb(self.default_catalog)
304 zcat.addIndex('serviceKeys', 'KeywordIndex')
305 zcat.addColumn('getPrimaryId')
306
307
309 ''' Called by Commandable.doCommand() to ascertain objects on which
310 a UserCommand should be executed.
311 '''
312 targets = []
313 for sc in self.serviceclasses():
314 targets += sc.getUserCommandTargets()
315 for so in self.children():
316 targets += so.getUserCommandTargets()
317 return targets
318
319
322
323
325 """ Parse a string of id and description from a live search
326 """
327 id = iddescstr.split(None, 1)[0]
328 return id
329
330
331 InitializeClass(ServiceOrganizer)
332