1
2
3
4
5
6
7
8
9
10
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
37
38 addOSProcessOrganizer = DTMLFile('dtml/addOSProcessOrganizer',globals())
39
41 meta_type = "OSProcessOrganizer"
42 dmdRootName = "Processes"
43
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 )
85 },
86 )
87
88 security = ClassSecurityInfo()
89
90 - def __init__(self, id=None, description=None):
95
96
98 """Return a list of hashs that define the screen tabs for this object.
99 [{'name':'Name','action':'template','selected':False},...]
100 """
101 tabs = Organizer.zentinelTabs(self, templateName)
102 if self.getPrimaryId() != '/zport/dmd/Processes':
103 tabs = [t for t in tabs if t['id'] != 'resequence']
104 return tabs
105
106
108 """Return generator that goes through all process classes.
109 """
110 for proc in self.osProcessClasses.objectValuesGen():
111 yield proc
112 for subgroup in self.children():
113 for proc in subgroup.getSubOSProcessClassesGen():
114 yield proc
115
116
118 '''Return list of the process classes sorted by sequence.
119 '''
120 def cmpProc(a, b):
121 return cmp(a.sequence, b.sequence)
122 procs = list(self.getSubOSProcessClassesGen())
123 procs.sort(cmpProc)
124 for i, p in enumerate(procs):
125 p.sequence = i
126 return procs
127
135
136
137 security.declareProtected(ZEN_ADD, 'manage_addOSProcessClass')
149
150
156
159
160
162 """Remove OSProcessClasses from an EventClass.
163 """
164 if not ids: return self()
165 if isinstance(ids, basestring): ids = (ids,)
166 for id in ids:
167 svc = self.osProcessClasses._getOb(id)
168 svc.setZenProperty("zMonitor", monitor)
169 if REQUEST: return self()
170
171
173 """Remove OSProcessClasses from an EventClass.
174 """
175 if not ids: return self()
176 if isinstance(ids, basestring): ids = (ids,)
177 for id in ids:
178
179 klass = self.osProcessClasses._getOb(id)
180 for p in klass.instances():
181 p.device().os.processes._delObject(p.id)
182 self.osProcessClasses._delObject(id)
183 self.manage_resequenceProcesses()
184 if REQUEST: return self()
185
186
200
201
208
209
211 ''' Called by Commandable.doCommand() to ascertain objects on which
212 a UserCommand should be executed.
213 '''
214 targets = []
215 for osc in self.osProcessClasses():
216 targets += osc.getUserCommandTargets()
217 for org in self.children():
218 targets += org.getUserCommandTargets()
219 return targets
220
221
224
225
226 InitializeClass(OSProcessOrganizer)
227