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 Acquisition import aq_base
23 from Commandable import Commandable
24 from ZenMenuable import ZenMenuable
25 from ZenPackable import ZenPackable
26
27 from Products.ZenRelations.RelSchema import *
28
29 from Organizer import Organizer
30 from ServiceClass import ServiceClass
31 from IpServiceClass import IpServiceClass
32
40
41 addServiceOrganizer = DTMLFile('dtml/addServiceOrganizer',globals())
42
44 meta_type = "ServiceOrganizer"
45 dmdRootName = "Services"
46 default_catalog = "serviceSearch"
47
48 description = ""
49
50 _properties = (
51 {'id':'description', 'type':'text', 'mode':'w'},
52 )
53
54 _relations = Organizer._relations + ZenPackable._relations + (
55 ("serviceclasses", ToManyCont(ToOne,"Products.ZenModel.ServiceClass","serviceorganizer")),
56 ('userCommands', ToManyCont(ToOne, 'Products.ZenModel.UserCommand', 'commandable')),
57 )
58
59 factory_type_information = (
60 {
61 'id' : 'ServiceOrganizer',
62 'meta_type' : 'ServiceOrganizer',
63 'icon' : 'ServiceOrganizer.gif',
64 'product' : 'ZenModel',
65 'factory' : 'manage_addServiceOrganizer',
66 'immediate_view' : 'serviceOrganizerOverview',
67 'actions' :
68 (
69 { 'id' : 'classes'
70 , 'name' : 'Classes'
71 , 'action' : 'serviceOrganizerOverview'
72 , 'permissions' : (
73 Permissions.view, )
74 },
75 { 'id' : 'manage'
76 , 'name' : 'Administration'
77 , 'action' : 'serviceOrganizerManage'
78 , 'permissions' : ("Manage DMD",)
79 },
80 { 'id' : 'zproperties'
81 , 'name' : 'zProperties'
82 , 'action' : 'zPropertyEdit'
83 , 'permissions' : ("Change Device",)
84 },
85 { 'id' : 'viewHistory'
86 , 'name' : 'Modifications'
87 , 'action' : 'viewHistory'
88 , 'permissions' : (
89 Permissions.view, )
90 },
91 )
92 },
93 )
94
95 security = ClassSecurityInfo()
96
103
104
105 - def find(self, query):
117
118
126
127
140
141
152
153
164
165
168
169
171 """Remove ServiceClasses from an EventClass.
172 """
173 if not ids: return self()
174 if type(ids) == types.StringType: ids = (ids,)
175 for id in ids:
176 svc = self.serviceclasses._getOb(id)
177 svc.setZenProperty("zMonitor", monitor)
178 if REQUEST: return self()
179
180
182 """Remove ServiceClasses from an EventClass.
183 """
184 if not ids: return self()
185 if type(ids) == types.StringType: ids = (ids,)
186 for id in ids:
187 self.serviceclasses._delObject(id)
188 if REQUEST: return self()
189
190
204
205
211
212
220
221
223 """Create a catalog for ServiceClass searching"""
224 from Products.ZCatalog.ZCatalog import manage_addZCatalog
225 manage_addZCatalog(self, self.default_catalog,
226 self.default_catalog)
227 zcat = self._getOb(self.default_catalog)
228 zcat.addIndex('serviceKeys', 'KeywordIndex')
229 zcat.addColumn('getPrimaryId')
230
231
233 ''' Called by Commandable.doCommand() to ascertain objects on which
234 a UserCommand should be executed.
235 '''
236 targets = []
237 for sc in self.serviceclasses():
238 targets += sc.getUserCommandTargets()
239 for so in self.children():
240 targets += so.getUserCommandTargets()
241 return targets
242
243
246
247
249 """ Get a list of id and descriptions for a live search
250 """
251 liveSearchList = []
252 for srv in self.getSubInstancesGen(rel='serviceclasses'):
253 if getattr(srv, 'description', None):
254 liveSearchList.append('%s [%s]' % (srv.id, srv.description))
255 else:
256 liveSearchList.append(srv.id)
257 return liveSearchList
258
260 """ Parse a string of id and description from a live search
261 """
262 id = str.split(' ')
263 if type(id) == types.TupleType:
264 id = id[0]
265 return id
266
267
268 InitializeClass(ServiceOrganizer)
269