| 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 re
15 import types
16 import logging
17 log = logging.getLogger("zen.OSProcessOrganizer")
18
19 from Globals import DTMLFile
20 from Globals import InitializeClass
21 from AccessControl import ClassSecurityInfo
22 from AccessControl import Permissions
23 from Acquisition import aq_base
24 from Commandable import Commandable
25 from Products.ZenRelations.RelSchema import *
26 from ZenPackable import ZenPackable
27
28 from Organizer import Organizer
29 from OSProcessClass import OSProcessClass
30
32 """make a device class"""
33 sc = OSProcessOrganizer(id)
34 context._setObject(id, sc)
35 sc = context._getOb(id)
36 if REQUEST is not None:
37 REQUEST['RESPONSE'].redirect(context.absolute_url() + '/manage_main')
38
39 addOSProcessOrganizer = DTMLFile('dtml/addOSProcessOrganizer',globals())
40
42 meta_type = "OSProcessOrganizer"
43 dmdRootName = "Processes"
44 #default_catalog = "osprocessSearch"
45
46 description = ""
47
48 _properties = (
49 {'id':'description', 'type':'text', 'mode':'w'},
50 )
51
52 _relations = Organizer._relations + ZenPackable._relations + (
53 ("osProcessClasses", ToManyCont(
54 ToOne,"Products.ZenModel.OSProcessClass","osProcessOrganizer")),
55 ('userCommands', ToManyCont(ToOne, 'Products.ZenModel.UserCommand', 'commandable')),
56 )
57
58 factory_type_information = (
59 {
60 'immediate_view' : 'osProcessOrganizerOverview',
61 'actions' :
62 (
63 { 'id' : 'classes'
64 , 'name' : 'Classes'
65 , 'action' : 'osProcessOrganizerOverview'
66 , 'permissions' : (
67 Permissions.view, )
68 },
69 { 'id' : 'resequence'
70 , 'name' : 'Sequence'
71 , 'action' : 'osProcessResequence'
72 , 'permissions' : (
73 Permissions.view, )
74 },
75 { 'id' : 'manage'
76 , 'name' : 'Administration'
77 , 'action' : 'osProcessOrganizerManage'
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
98 if not id: id = self.dmdRootName
99 super(OSProcessOrganizer, self).__init__(id)
100 if self.id == self.dmdRootName:
101 self.buildZProperties()
102
103
105 """Return a list of hashs that define the screen tabs for this object.
106 [{'name':'Name','action':'template','selected':False},...]
107 """
108 tabs = Organizer.zentinelTabs(self, templateName)
109 if self.getPrimaryId() != '/zport/dmd/Processes':
110 tabs = [t for t in tabs if t['id'] != 'resequence']
111 return tabs
112
113
115 """Return generator that goes through all process classes.
116 """
117 for proc in self.osProcessClasses.objectValuesGen():
118 yield proc
119 for subgroup in self.children():
120 for proc in subgroup.getSubOSProcessClassesGen():
121 yield proc
122
123
125 '''Return list of the process classes sorted by sequence.
126 '''
127 def cmpProc(a, b):
128 return cmp(a.sequence, b.sequence)
129 procs = list(self.getSubOSProcessClassesGen())
130 procs.sort(cmpProc)
131 for i, p in enumerate(procs):
132 p.sequence = i
133 return procs
134
135
137 """Count all osprocessclasses with in a ServiceOrganizer.
138 """
139 count = self.osProcessClasses.countObjects()
140 for group in self.children():
141 count += group.countClasses()
142 return count
143
144
146 """Create a new service class in this Organizer.
147 """
148 if id:
149 sc = OSProcessClass(id)
150 sc.sequence = len(self.osProcessClasses())
151 self.osProcessClasses._setObject(id, sc)
152 if REQUEST:
153 return self.callZenScreen(REQUEST)
154 else:
155 return self.osProcessClasses._getOb(id)
156
157
159 "resequence the OsProcesses"
160 from Products.ZenUtils.Utils import resequence
161 return resequence(self, self.getSubOSProcessClassesGen(),
162 seqmap, origseq, REQUEST)
163
166
167
169 """Remove OSProcessClasses from an EventClass.
170 """
171 if not ids: return self()
172 if type(ids) == types.StringType: ids = (ids,)
173 for id in ids:
174 svc = self.osProcessClasses._getOb(id)
175 svc.setZenProperty("zMonitor", monitor)
176 if REQUEST: return self()
177
178
180 """Remove OSProcessClasses from an EventClass.
181 """
182 if not ids: return self()
183 if type(ids) == types.StringType: ids = (ids,)
184 for id in ids:
185 # delete related os process instances
186 klass = self.osProcessClasses._getOb(id)
187 for p in klass.instances():
188 p.device().os.processes._delObject(p.id)
189 self.osProcessClasses._delObject(id)
190 self.manage_resequenceProcesses()
191 if REQUEST: return self()
192
193
195 """Move OSProcessClasses from this EventClass to moveTarget.
196 """
197 if not moveTarget or not ids: return self()
198 if type(ids) == types.StringType: ids = (ids,)
199 target = self.getChildMoveTarget(moveTarget)
200 for id in ids:
201 rec = self.osProcessClasses._getOb(id)
202 rec._operation = 1 # moving object state
203 self.osProcessClasses._delObject(id)
204 target.osProcessClasses._setObject(id, rec)
205 if REQUEST:
206 REQUEST['RESPONSE'].redirect(target.getPrimaryUrlPath())
207
208
210 if hasattr(aq_base(self), "zCountProcs"): return
211 self._setProperty("zCountProcs", False, type="boolean")
212 self._setProperty("zAlertOnRestart", False, type="boolean")
213 self._setProperty("zMonitor", True, type="boolean")
214 self._setProperty("zFailSeverity", 4, type="int")
215
216
218 ''' Called by Commandable.doCommand() to ascertain objects on which
219 a UserCommand should be executed.
220 '''
221 targets = []
222 for osc in self.osProcessClasses():
223 targets += osc.getUserCommandTargets()
224 for org in self.children():
225 targets += org.getUserCommandTargets()
226 return targets
227
228
230 return self.getPrimaryUrlPath() + '/osProcessOrganizerManage'
231
232
233 InitializeClass(OSProcessOrganizer)
234
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0beta1 on Thu Oct 25 16:28:45 2007 | http://epydoc.sourceforge.net |