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