| Trees | Indices | Help |
|
|---|
|
|
1 ###########################################################################
2 #
3 # This program is part of Zenoss Core, an open source monitoring platform.
4 # Copyright (C) 2007, Zenoss Inc.
5 #
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License version 2 or (at your
8 # option) any later version as published by the Free Software Foundation.
9 #
10 # For complete information please visit: http://www.zenoss.com/oss/
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
35 """make a device class"""
36 sc = ServiceOrganizer(id)
37 context._setObject(id, sc)
38 sc = context._getOb(id)
39 if REQUEST is not None:
40 REQUEST['RESPONSE'].redirect(context.absolute_url() + '/manage_main')
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 { 'id' : 'viewHistory'
87 , 'name' : 'Modifications'
88 , 'action' : 'viewHistory'
89 , 'permissions' : (ZEN_VIEW_MODIFICATIONS,)
90 },
91 )
92 },
93 )
94
95 security = ClassSecurityInfo()
96
98 if not id: id = self.dmdRootName
99 super(ServiceOrganizer, self).__init__(id, description)
100 if self.id == self.dmdRootName:
101 self.createCatalog()
102 self.buildZProperties()
103
104
106 """Find a service class by is serviceKey.
107 """
108 cat = getattr(self, self.default_catalog, None)
109 if not cat: return
110 brains = cat({'serviceKeys': query})
111 if not brains: return None
112 for brain in brains:
113 if brain.getPrimaryId.startswith(self.getPrimaryId()):
114 try:
115 return self.getObjByPath(brain.getPrimaryId)
116 except KeyError:
117 log.warn("bad path '%s' for index '%s'",
118 brain.getPrimaryId, self.default_catalog)
119
120
122 """Checks a valid id
123 """
124 relationship = getattr(self, 'serviceclasses')
125 try:
126 relationship.checkValidId(id)
127 return True
128 except Exception as e:
129 return str(e)
130
131
133 """Return generator that goes through all process classes.
134 """
135 for proc in self.serviceclasses.objectValuesGen():
136 yield proc
137 for subgroup in self.children():
138 for proc in subgroup.getSubClassesGen():
139 yield proc
140
141
143 '''Return list of the process classes sorted by sequence.
144 '''
145 def cmpProc(a, b):
146 return cmp(a.sequence, b.sequence)
147 procs = list(self.getSubClassesGen())
148 for i, p in enumerate(procs):
149 p.sequence = i
150 procs.sort(cmpProc)
151 return procs
152
153
155 """Count all serviceclasses with in a ServiceOrganizer.
156 """
157 count = self.serviceclasses.countObjects()
158 for group in self.children():
159 count += group.countClasses()
160 return count
161
162
163 - def createServiceClass(self, name="", description="",
164 path="", factory=ServiceClass, **kwargs):
165 """Create a service class (or retrun existing) based on keywords.
166 """
167 svcs = self.getDmdRoot(self.dmdRootName)
168 svcorg = svcs.createOrganizer(path)
169 svccl = svcorg.find(name)
170 if not svccl:
171 svccl = factory(name, (name,),description=description, **kwargs)
172 svcorg.serviceclasses._setObject(svccl.id, svccl)
173 svccl = svcorg.serviceclasses._getOb(svccl.id)
174 return svccl
175
177 """
178 Save all ZenProperties found in the REQUEST.form object.
179 Overridden so that service instances can be re-indexed if needed
180 """
181 #get value to see if it changes
182 monitor = self.zMonitor
183 result = super(ServiceOrganizer, self).saveZenProperties( pfilt, REQUEST)
184
185 if monitor != self.zMonitor :
186 #indexes need to be updated so that the updated config will be sent
187 #can be slow if done at /Services would be nice to run asynch
188 self._indexServiceClassInstances()
189 return result
190
192 """
193 Delete device tree properties from the this DeviceClass object.
194 Overridden to intercept zMonitor changes
195 """
196 monitor = self.zMonitor
197 result = super(ServiceOrganizer, self).deleteZenProperty( propname, REQUEST)
198 if monitor != self.zMonitor :
199 #indexes need to be updated so that the updated config will be sent
200 #can be slow if done at /Services would be nice to run asynch
201 self._indexServiceClassInstances()
202
203 return result
204
206 """
207 indexes any service class instances in the hierarchy
208 """
209 organizers = [self]
210 while organizers:
211 for org in organizers:
212 for sc in org.serviceclasses():
213 sc._indexInstances()
214
215 oldOrgs = organizers
216 organizers = []
217 for org in oldOrgs:
218 organizers.extend(org.children())
219
220
221 security.declareProtected(ZEN_MANAGE_DMD, 'manage_addServiceClass')
223 """Create a new service class in this Organizer.
224 """
225 if id:
226 sc = ServiceClass(id)
227 self.serviceclasses._setObject(id, sc)
228 if REQUEST or not id:
229 return self.callZenScreen(REQUEST)
230 else:
231 return self.serviceclasses._getOb(id)
232
233
234 security.declareProtected(ZEN_MANAGE_DMD, 'manage_addIpServiceClass')
236 """Create a new service class in this Organizer.
237 """
238 if id:
239 sc = IpServiceClass(id)
240 self.serviceclasses._setObject(id, sc)
241 if REQUEST or not id:
242 return self.callZenScreen(REQUEST)
243 else:
244 return self.serviceclasses._getOb(id)
245
246
249
250
252 """Remove ServiceClasses from an EventClass.
253 """
254 if not ids: return self()
255 if isinstance(ids, basestring): ids = (ids,)
256 for id in ids:
257 svc = self.serviceclasses._getOb(id)
258 svc.setZenProperty("zMonitor", monitor)
259 if REQUEST: return self()
260
261
263 """Remove ServiceClasses from an EventClass.
264 """
265 if not ids: return self()
266 if isinstance(ids, basestring): ids = (ids,)
267 for id in ids:
268 self.serviceclasses._delObject(id)
269 if REQUEST: return self()
270
271
273 """Move ServiceClasses from this EventClass to moveTarget.
274 """
275 if not moveTarget or not ids: return self()
276 if isinstance(ids, basestring): ids = (ids,)
277 target = self.getChildMoveTarget(moveTarget)
278 for id in ids:
279 rec = self.serviceclasses._getOb(id)
280 rec._operation = 1 # moving object state
281 self.serviceclasses._delObject(id)
282 target.serviceclasses._setObject(id, rec)
283 if REQUEST:
284 REQUEST['RESPONSE'].redirect(target.getPrimaryUrlPath())
285
286
288 if hasattr(aq_base(self), "zMonitor"): return
289 self._setProperty("zMonitor", False, type="boolean")
290 self._setProperty("zFailSeverity", 5, type="int")
291 self._setProperty("zHideFieldsFromList", [], type="lines")
292
293
295 """Go through all devices in this tree and reindex them."""
296 zcat = self._getOb(self.default_catalog)
297 zcat.manage_catalogClear()
298 for srv in self.getSubOrganizers():
299 for inst in srv.serviceclasses():
300 inst.index_object()
301
302
304 """Create a catalog for ServiceClass searching"""
305 from Products.ZCatalog.ZCatalog import manage_addZCatalog
306 manage_addZCatalog(self, self.default_catalog,
307 self.default_catalog)
308 zcat = self._getOb(self.default_catalog)
309 zcat.addIndex('serviceKeys', 'KeywordIndex')
310 zcat.addColumn('getPrimaryId')
311
312
314 ''' Called by Commandable.doCommand() to ascertain objects on which
315 a UserCommand should be executed.
316 '''
317 targets = []
318 for sc in self.serviceclasses():
319 targets += sc.getUserCommandTargets()
320 for so in self.children():
321 targets += so.getUserCommandTargets()
322 return targets
323
324
326 return self.getPrimaryUrlPath() + '/serviceOrganizerManage'
327
328
334
335
336 InitializeClass(ServiceOrganizer)
337
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1.1812 on Thu Sep 1 19:03:50 2011 | http://epydoc.sourceforge.net |