1
2
3
4
5
6
7
8
9
10
11 import logging
12 log = logging.getLogger("zen.OSProcessOrganizer")
13
14 from Globals import DTMLFile
15 from Globals import InitializeClass
16 from AccessControl import ClassSecurityInfo
17 from AccessControl import Permissions
18 from Products.ZenModel.ZenossSecurity import *
19 from Acquisition import aq_base
20 from Commandable import Commandable
21 from Products.ZenRelations.RelSchema import *
22 from ZenPackable import ZenPackable
23
24 from Organizer import Organizer
25 from OSProcessClass import OSProcessClass
26
34
35 addOSProcessOrganizer = DTMLFile('dtml/addOSProcessOrganizer',globals())
36
38 meta_type = "OSProcessOrganizer"
39 dmdRootName = "Processes"
40
41
42 description = ""
43
44 _properties = (
45 {'id':'description', 'type':'text', 'mode':'w'},
46 )
47
48 _relations = Organizer._relations + ZenPackable._relations + (
49 ("osProcessClasses", ToManyCont(
50 ToOne,"Products.ZenModel.OSProcessClass","osProcessOrganizer")),
51 ('userCommands', ToManyCont(ToOne, 'Products.ZenModel.UserCommand', 'commandable')),
52 )
53
54 factory_type_information = (
55 {
56 'immediate_view' : 'osProcessOrganizerOverview',
57 'actions' :
58 (
59 { 'id' : 'classes'
60 , 'name' : 'Classes'
61 , 'action' : 'osProcessOrganizerOverview'
62 , 'permissions' : (
63 Permissions.view, )
64 },
65 { 'id' : 'resequence'
66 , 'name' : 'Sequence'
67 , 'action' : 'osProcessResequence'
68 , 'permissions' : (
69 Permissions.view, )
70 },
71 { 'id' : 'manage'
72 , 'name' : 'Administration'
73 , 'action' : 'osProcessOrganizerManage'
74 , 'permissions' : ("Manage DMD",)
75 },
76 { 'id' : 'zProperties'
77 , 'name' : 'Configuration Properties'
78 , 'action' : 'zPropertyEdit'
79 , 'permissions' : ("Change Device",)
80 },
81 )
82 },
83 )
84
85 security = ClassSecurityInfo()
86
87 - def __init__(self, id=None, description=None):
92
93
95 """Return a list of hashs that define the screen tabs for this object.
96 [{'name':'Name','action':'template','selected':False},...]
97 """
98 tabs = Organizer.zentinelTabs(self, templateName)
99 if self.getPrimaryId() != '/zport/dmd/Processes':
100 tabs = [t for t in tabs if t['id'] != 'resequence']
101 return tabs
102
103
105 """Return generator that goes through all process classes.
106 """
107 for proc in self.osProcessClasses.objectValuesGen():
108 yield proc
109 for subgroup in self.children():
110 for proc in subgroup.getSubOSProcessClassesGen():
111 yield proc
112
113
115 '''Return list of the process classes sorted by sequence.
116 '''
117 procs = sorted(self.getSubOSProcessClassesGen(),
118 key=lambda a: a.sequence)
119
120 for i, p in enumerate(procs):
121 p.sequence = i
122 return procs
123
131
132
133 security.declareProtected(ZEN_ADD, 'manage_addOSProcessClass')
145
146
152
155
156
158 """Remove OSProcessClasses from an EventClass.
159 """
160 if not ids: return self()
161 if isinstance(ids, basestring): ids = (ids,)
162 for id in ids:
163 svc = self.osProcessClasses._getOb(id)
164 svc.setZenProperty("zMonitor", monitor)
165 if REQUEST: return self()
166
167
169 """Remove OSProcessClasses from an EventClass.
170 """
171 if not ids: return self()
172 if isinstance(ids, basestring): ids = (ids,)
173 for id in ids:
174
175 klass = self.osProcessClasses._getOb(id)
176 for p in klass.instances():
177 p.device().os.processes._delObject(p.id)
178 self.osProcessClasses._delObject(id)
179 self.manage_resequenceProcesses()
180 if REQUEST: return self()
181
182
196
197
204
205
207 ''' Called by Commandable.doCommand() to ascertain objects on which
208 a UserCommand should be executed.
209 '''
210 targets = []
211 for osc in self.osProcessClasses():
212 targets += osc.getUserCommandTargets()
213 for org in self.children():
214 targets += org.getUserCommandTargets()
215 return targets
216
217
220
221
222 InitializeClass(OSProcessOrganizer)
223