1
2
3
4
5
6
7
8
9
10
11 __doc__="""FileSystem
12
13 FileSystem is a file system on a server
14
15 $Id: FileSystem.py,v 1.12 2004/04/06 22:33:23 edahl Exp $"""
16
17 __version__ = "$Revision: 1.12 $"[11:-2]
18
19 from math import isnan
20
21 from Globals import DTMLFile
22 from Globals import InitializeClass
23 from AccessControl import ClassSecurityInfo
24
25 from Products.ZenUtils.Utils import convToUnits
26 from Products.ZenRelations.RelSchema import *
27
28 from OSComponent import OSComponent
29 from Products.ZenUtils.Utils import prepId
30 from Products.ZenWidgets import messaging
31
32 from Products.ZenModel.ZenossSecurity import *
33
44
45 addFileSystem = DTMLFile('dtml/addFileSystem',globals())
46
48 """
49 FileSystem object
50 """
51
52 portal_type = meta_type = 'FileSystem'
53
54 manage_editFileSystemForm = DTMLFile('dtml/manageEditFileSystem',globals())
55
56 mount = ""
57 storageDevice = ""
58 type = ""
59 blockSize = 0
60 totalBlocks = 0L
61 totalFiles = 0L
62 capacity = 0
63 inodeCapacity = 0
64 maxNameLen = 0
65
66 security = ClassSecurityInfo()
67
68 _properties = OSComponent._properties + (
69 {'id':'mount', 'type':'string', 'mode':''},
70 {'id':'storageDevice', 'type':'string', 'mode':''},
71 {'id':'type', 'type':'string', 'mode':''},
72 {'id':'blockSize', 'type':'int', 'mode':''},
73 {'id':'totalBlocks', 'type':'long', 'mode':''},
74 {'id':'totalFiles', 'type':'long', 'mode':''},
75 {'id':'maxNameLen', 'type':'int', 'mode':''},
76 )
77 _relations = OSComponent._relations + (
78 ("os", ToOne(ToManyCont, "Products.ZenModel.OperatingSystem", "filesystems")),
79 )
80
81
82 factory_type_information = (
83 {
84 'id' : 'FileSystem',
85 'meta_type' : 'FileSystem',
86 'description' : """Arbitrary device grouping class""",
87 'icon' : 'FileSystem_icon.gif',
88 'product' : 'ZenModel',
89 'factory' : 'manage_addFileSystem',
90 'immediate_view' : 'viewFileSystem',
91 'actions' :
92 (
93 { 'id' : 'status'
94 , 'name' : 'Status'
95 , 'action' : 'viewFileSystem'
96 , 'permissions' : (ZEN_VIEW,)
97 },
98 { 'id' : 'events'
99 , 'name' : 'Events'
100 , 'action' : 'viewEvents'
101 , 'permissions' : (ZEN_VIEW, )
102 },
103 { 'id' : 'perfConf'
104 , 'name' : 'Template'
105 , 'action' : 'objTemplates'
106 , 'permissions' : ("Change Device", )
107 },
108 )
109 },
110 )
111
112
116
117
123
124
126 """
127 Return the number of total bytes in human readable from ie 10MB
128 """
129 return convToUnits(self.totalBytes())
130
131
133 """
134 Return the number of used bytes on a filesytem.
135 """
136 blocks = self.usedBlocks()
137 if blocks is not None:
138 return self.blockSize * blocks
139 return None
140
141
143 """
144 Return the number of used bytes in human readable form ie 10MB
145 """
146 __pychecker__='no-constCond'
147 ub = self.usedBytes()
148 return ub is None and "unknown" or convToUnits(ub)
149
150
152 """
153 Return the number of availible bytes for this filesystem
154 """
155 blocks = self.availBlocks()
156 if blocks is not None:
157 return self.blockSize * blocks
158 return None
159
160
162 """
163 Return the number of availible bytes in human readable form ie 10MB
164 """
165 __pychecker__='no-constCond'
166 ab = self.availBytes()
167 return ab is None and "unknown" or convToUnits(ab)
168
169
171 """
172 Not implemented returns 0
173 """
174 return 0
175
176
189
190
192 """
193 Not implemented returns 0
194 """
195 return 0
196
197
199 """
200 Return the number of used blocks stored in the filesystem's rrd file
201 """
202
203 dskPercent = self.cacheRRDValue("dskPercent")
204 if dskPercent is not None and dskPercent != "Unknown" and not isnan(dskPercent):
205 return self.getTotalBlocks() * dskPercent / 100.0
206
207 blocks = self.cacheRRDValue('usedBlocks', default)
208 if blocks is not None and not isnan(blocks):
209 return long(blocks)
210 elif self.blockSize:
211
212
213
214 freeMB = self.cacheRRDValue('FreeMegabytes', default)
215 if freeMB is not None and not isnan(freeMB):
216 usedBytes = self.totalBytes() - long(freeMB) * 1024 * 1024
217 return usedBytes / self.blockSize
218 return None
219
220
232
233
235 """
236 Return the number of used blocks in human readable form ie 10MB
237 """
238 __pychecker__='no-constCond'
239 ub = self.usedBlocks()
240 return ub is None and "unknown" or convToUnits(ub)
241
242
244 """
245 Return the datapoint name of this filesystem 'usedBlocks_usedBlocks'
246 """
247 return ['usedBlocks_usedBlocks']
248
249
251 """
252 Return the mount point name of a filesystem '/boot'
253 """
254 return self.mount
255 name = viewName
256
257
258 security.declareProtected(ZEN_MANAGE_DEVICE, 'manage_editFileSystem')
259 - def manage_editFileSystem(self, monitor=False,
260 mount=None, storageDevice=None,
261 type=None, blockSize=None,
262 totalFiles=None, maxNameLen=None,
263 snmpindex=None, REQUEST=None):
285
286
287 InitializeClass(FileSystem)
288