| 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 as published by
8 # the Free Software Foundation.
9 #
10 # For complete information please visit: http://www.zenoss.com/oss/
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
36 """make a device class"""
37 sc = ServiceOrganizer(id)
38 context._setObject(id, sc)
39 sc = context._getOb(id)
40 if REQUEST is not None:
41 REQUEST['RESPONSE'].redirect(context.absolute_url() + '/manage_main')
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
99 if not id: id = self.dmdRootName
100 super(ServiceOrganizer, self).__init__(id)
101 if self.id == self.dmdRootName:
102 self.createCatalog()
103 self.buildZProperties()
104
105
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
121 """Count all serviceclasses with in a ServiceOrganizer.
122 """
123 count = self.serviceclasses.countObjects()
124 for group in self.children():
125 count += group.countClasses()
126 return count
127
128
129 - def createServiceClass(self, name="", description="",
130 path="", factory=ServiceClass, **kwargs):
131 """Create a service class (or retrun existing) based on keywords.
132 """
133 svcs = self.getDmdRoot(self.dmdRootName)
134 svccl = svcs.find(name)
135 if not svccl:
136 svcorg = svcs.createOrganizer(path)
137 svccl = factory(name, (name,),description=description, **kwargs)
138 svcorg.serviceclasses._setObject(svccl.id, svccl)
139 svccl = svcorg.serviceclasses._getOb(svccl.id)
140 return svccl
141
143 """
144 Save all ZenProperties found in the REQUEST.form object.
145 Overridden so that service instances can be re-indexed if needed
146 """
147 #get value to see if it changes
148 monitor = self.zMonitor
149 result = super(ServiceOrganizer, self).saveZenProperties( pfilt, REQUEST)
150
151 if monitor != self.zMonitor :
152 #indexes need to be updated so that the updated config will be sent
153 #can be slow if done at /Services would be nice to run asynch
154 self._indexServiceClassInstances()
155 return result
156
158 """
159 Delete device tree properties from the this DeviceClass object.
160 Overridden to intercept zMonitor changes
161 """
162 monitor = self.zMonitor
163 result = super(ServiceOrganizer, self).deleteZenProperty( propname, REQUEST)
164 if monitor != self.zMonitor :
165 #indexes need to be updated so that the updated config will be sent
166 #can be slow if done at /Services would be nice to run asynch
167 self._indexServiceClassInstances()
168
169 return result
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')
189 """Create a new service class in this Organizer.
190 """
191 if id:
192 sc = ServiceClass(id)
193 self.serviceclasses._setObject(id, sc)
194 if REQUEST or not id:
195 return self.callZenScreen(REQUEST)
196 else:
197 return self.serviceclasses._getOb(id)
198
199
200 security.declareProtected(ZEN_MANAGE_DMD, 'manage_addIpServiceClass')
202 """Create a new service class in this Organizer.
203 """
204 if id:
205 sc = IpServiceClass(id)
206 self.serviceclasses._setObject(id, sc)
207 if REQUEST or not id:
208 return self.callZenScreen(REQUEST)
209 else:
210 return self.serviceclasses._getOb(id)
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
239 """Move ServiceClasses from this EventClass to moveTarget.
240 """
241 if not moveTarget or not ids: return self()
242 if type(ids) == types.StringType: ids = (ids,)
243 target = self.getChildMoveTarget(moveTarget)
244 for id in ids:
245 rec = self.serviceclasses._getOb(id)
246 rec._operation = 1 # moving object state
247 self.serviceclasses._delObject(id)
248 target.serviceclasses._setObject(id, rec)
249 if REQUEST:
250 REQUEST['RESPONSE'].redirect(target.getPrimaryUrlPath())
251
252
254 if hasattr(aq_base(self), "zMonitor"): return
255 self._setProperty("zMonitor", False, type="boolean")
256 self._setProperty("zFailSeverity", 5, type="int")
257 self._setProperty("zHideFieldsFromList", [], type="lines")
258
259
261 """Go through all devices in this tree and reindex them."""
262 zcat = self._getOb(self.default_catalog)
263 zcat.manage_catalogClear()
264 for srv in self.getSubOrganizers():
265 for inst in srv.serviceclasses():
266 inst.index_object()
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
292 return self.getPrimaryUrlPath() + '/serviceOrganizerManage'
293
294
302
303
304 InitializeClass(ServiceOrganizer)
305
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0beta1 on Thu May 7 11:46:33 2009 | http://epydoc.sourceforge.net |