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' : 'zProperties'
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
104
105
106 - def find(self, query):
107 """Find a service class by is serviceKey.
108 """
109 cat = getattr(self, self.default_catalog, None)
110 if not cat: return
111 brains = cat({'serviceKeys': query})
112 if not brains: return None
113 try:
114 return self.getObjByPath(brains[0].getPrimaryId)
115 except KeyError:
116 log.warn("bad path '%s' for index '%s'", brains[0].getPrimaryId,
117 self.default_catalog)
118
119
127
128
141
156
170
172 """
173 indexes any service class instances in the hierarchy
174 """
175 organizers = [self]
176 while organizers:
177 for org in organizers:
178 for sc in org.serviceclasses():
179 sc._indexInstances()
180
181 oldOrgs = organizers
182 organizers = []
183 for org in oldOrgs:
184 organizers.extend(org.children())
185
186
187 security.declareProtected(ZEN_MANAGE_DMD, 'manage_addServiceClass')
198
199
200 security.declareProtected(ZEN_MANAGE_DMD, 'manage_addIpServiceClass')
211
212
215
216
218 """Remove ServiceClasses from an EventClass.
219 """
220 if not ids: return self()
221 if type(ids) == types.StringType: ids = (ids,)
222 for id in ids:
223 svc = self.serviceclasses._getOb(id)
224 svc.setZenProperty("zMonitor", monitor)
225 if REQUEST: return self()
226
227
229 """Remove ServiceClasses from an EventClass.
230 """
231 if not ids: return self()
232 if type(ids) == types.StringType: ids = (ids,)
233 for id in ids:
234 self.serviceclasses._delObject(id)
235 if REQUEST: return self()
236
237
251
252
258
259
267
268
270 """Create a catalog for ServiceClass searching"""
271 from Products.ZCatalog.ZCatalog import manage_addZCatalog
272 manage_addZCatalog(self, self.default_catalog,
273 self.default_catalog)
274 zcat = self._getOb(self.default_catalog)
275 zcat.addIndex('serviceKeys', 'KeywordIndex')
276 zcat.addColumn('getPrimaryId')
277
278
280 ''' Called by Commandable.doCommand() to ascertain objects on which
281 a UserCommand should be executed.
282 '''
283 targets = []
284 for sc in self.serviceclasses():
285 targets += sc.getUserCommandTargets()
286 for so in self.children():
287 targets += so.getUserCommandTargets()
288 return targets
289
290
293
294
296 """ Parse a string of id and description from a live search
297 """
298 id = str.split(' ')
299 if type(id) == types.TupleType:
300 id = id[0]
301 return id
302
303
304 InitializeClass(ServiceOrganizer)
305