| 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.OSProcessOrganizer")
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 Products.ZenRelations.RelSchema import *
25 from ZenPackable import ZenPackable
26
27 from Organizer import Organizer
28 from OSProcessClass import OSProcessClass
29
31 """make a device class"""
32 sc = OSProcessOrganizer(id)
33 context._setObject(id, sc)
34 sc = context._getOb(id)
35 if REQUEST is not None:
36 REQUEST['RESPONSE'].redirect(context.absolute_url() + '/manage_main')
37
38 addOSProcessOrganizer = DTMLFile('dtml/addOSProcessOrganizer',globals())
39
41 meta_type = "OSProcessOrganizer"
42 dmdRootName = "Processes"
43 #default_catalog = "osprocessSearch"
44
45 description = ""
46
47 _properties = (
48 {'id':'description', 'type':'text', 'mode':'w'},
49 )
50
51 _relations = Organizer._relations + ZenPackable._relations + (
52 ("osProcessClasses", ToManyCont(
53 ToOne,"Products.ZenModel.OSProcessClass","osProcessOrganizer")),
54 ('userCommands', ToManyCont(ToOne, 'Products.ZenModel.UserCommand', 'commandable')),
55 )
56
57 factory_type_information = (
58 {
59 'immediate_view' : 'osProcessOrganizerOverview',
60 'actions' :
61 (
62 { 'id' : 'classes'
63 , 'name' : 'Classes'
64 , 'action' : 'osProcessOrganizerOverview'
65 , 'permissions' : (
66 Permissions.view, )
67 },
68 { 'id' : 'resequence'
69 , 'name' : 'Sequence'
70 , 'action' : 'osProcessResequence'
71 , 'permissions' : (
72 Permissions.view, )
73 },
74 { 'id' : 'manage'
75 , 'name' : 'Administration'
76 , 'action' : 'osProcessOrganizerManage'
77 , 'permissions' : ("Manage DMD",)
78 },
79 { 'id' : 'zProperties'
80 , 'name' : 'Configuration Properties'
81 , 'action' : 'zPropertyEdit'
82 , 'permissions' : ("Change Device",)
83 },
84 { 'id' : 'viewHistory'
85 , 'name' : 'Modifications'
86 , 'action' : 'viewHistory'
87 , 'permissions' : (ZEN_VIEW_MODIFICATIONS,)
88 },
89 )
90 },
91 )
92
93 security = ClassSecurityInfo()
94
96 if not id: id = self.dmdRootName
97 super(OSProcessOrganizer, self).__init__(id, description)
98 if self.id == self.dmdRootName:
99 self.buildZProperties()
100
101
103 """Return a list of hashs that define the screen tabs for this object.
104 [{'name':'Name','action':'template','selected':False},...]
105 """
106 tabs = Organizer.zentinelTabs(self, templateName)
107 if self.getPrimaryId() != '/zport/dmd/Processes':
108 tabs = [t for t in tabs if t['id'] != 'resequence']
109 return tabs
110
111
113 """Return generator that goes through all process classes.
114 """
115 for proc in self.osProcessClasses.objectValuesGen():
116 yield proc
117 for subgroup in self.children():
118 for proc in subgroup.getSubOSProcessClassesGen():
119 yield proc
120
121
123 '''Return list of the process classes sorted by sequence.
124 '''
125 def cmpProc(a, b):
126 return cmp(a.sequence, b.sequence)
127 procs = list(self.getSubOSProcessClassesGen())
128 procs.sort(cmpProc)
129 for i, p in enumerate(procs):
130 p.sequence = i
131 return procs
132
134 """Count all osprocessclasses with in a ServiceOrganizer.
135 """
136 count = self.osProcessClasses.countObjects()
137 for group in self.children():
138 count += group.countClasses()
139 return count
140
141
142 security.declareProtected(ZEN_ADD, 'manage_addOSProcessClass')
144 """Create a new service class in this Organizer.
145 """
146 if id:
147 sc = OSProcessClass(id)
148 sc.sequence = len(self.osProcessClasses())
149 self.osProcessClasses._setObject(id, sc)
150 if REQUEST:
151 return self.callZenScreen(REQUEST)
152 else:
153 return self.osProcessClasses._getOb(id)
154
155
157 "resequence the OsProcesses"
158 from Products.ZenUtils.Utils import resequence
159 return resequence(self, self.getSubOSProcessClassesGen(),
160 seqmap, origseq, REQUEST)
161
164
165
167 """Remove OSProcessClasses from an EventClass.
168 """
169 if not ids: return self()
170 if isinstance(ids, basestring): ids = (ids,)
171 for id in ids:
172 svc = self.osProcessClasses._getOb(id)
173 svc.setZenProperty("zMonitor", monitor)
174 if REQUEST: return self()
175
176
178 """Remove OSProcessClasses from an EventClass.
179 """
180 if not ids: return self()
181 if isinstance(ids, basestring): ids = (ids,)
182 for id in ids:
183 # delete related os process instances
184 klass = self.osProcessClasses._getOb(id)
185 for p in klass.instances():
186 p.device().os.processes._delObject(p.id)
187 self.osProcessClasses._delObject(id)
188 self.manage_resequenceProcesses()
189 if REQUEST: return self()
190
191
193 """Move OSProcessClasses from this EventClass to moveTarget.
194 """
195 if not moveTarget or not ids: return self()
196 if isinstance(ids, basestring): ids = (ids,)
197 target = self.getChildMoveTarget(moveTarget)
198 for id in ids:
199 rec = self.osProcessClasses._getOb(id)
200 rec._operation = 1 # moving object state
201 self.osProcessClasses._delObject(id)
202 target.osProcessClasses._setObject(id, rec)
203 if REQUEST:
204 REQUEST['RESPONSE'].redirect(target.getPrimaryUrlPath())
205
206
208 if hasattr(aq_base(self), "zCountProcs"): return
209 self._setProperty("zCountProcs", False, type="boolean")
210 self._setProperty("zAlertOnRestart", False, type="boolean")
211 self._setProperty("zMonitor", True, type="boolean")
212 self._setProperty("zFailSeverity", 4, type="int")
213
214
216 ''' Called by Commandable.doCommand() to ascertain objects on which
217 a UserCommand should be executed.
218 '''
219 targets = []
220 for osc in self.osProcessClasses():
221 targets += osc.getUserCommandTargets()
222 for org in self.children():
223 targets += org.getUserCommandTargets()
224 return targets
225
226
228 return self.getPrimaryUrlPath() + '/osProcessOrganizerManage'
229
230
231 InitializeClass(OSProcessOrganizer)
232
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1.1812 on Thu Sep 1 19:03:41 2011 | http://epydoc.sourceforge.net |