Package Products :: Package ZenModel :: Module FileSystem
[hide private]
[frames] | no frames]

Source Code for Module Products.ZenModel.FileSystem

  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  __doc__="""FileSystem 
 15   
 16  FileSystem is a file system on a server 
 17   
 18  $Id: FileSystem.py,v 1.12 2004/04/06 22:33:23 edahl Exp $""" 
 19   
 20  __version__ = "$Revision: 1.12 $"[11:-2] 
 21   
 22  from math import isnan 
 23   
 24  from Globals import DTMLFile 
 25  from Globals import InitializeClass 
 26  from AccessControl import ClassSecurityInfo 
 27   
 28  from Products.ZenUtils.Utils import convToUnits 
 29  from Products.ZenRelations.RelSchema import * 
 30   
 31  from OSComponent import OSComponent 
 32  from Products.ZenUtils.Utils import prepId 
 33  from Products.ZenWidgets import messaging 
 34   
 35  from Products.ZenModel.ZenossSecurity import * 
 36   
37 -def manage_addFileSystem(context, newId, userCreated, REQUEST=None):
38 """make a filesystem""" 39 fsid = prepId(newId) 40 fs = FileSystem(fsid) 41 context._setObject(fsid, fs) 42 fs = context._getOb(fsid) 43 fs.mount = newId 44 if userCreated: fs.setUserCreateFlag() 45 if REQUEST is not None: 46 REQUEST['RESPONSE'].redirect(context.absolute_url()+'/manage_main')
47 48 addFileSystem = DTMLFile('dtml/addFileSystem',globals()) 49
50 -class FileSystem(OSComponent):
51 """ 52 FileSystem object 53 """ 54 55 portal_type = meta_type = 'FileSystem' 56 57 manage_editFileSystemForm = DTMLFile('dtml/manageEditFileSystem',globals()) 58 59 mount = "" 60 storageDevice = "" 61 type = "" 62 blockSize = 0 63 totalBlocks = 0L 64 totalFiles = 0L 65 capacity = 0 66 inodeCapacity = 0 67 maxNameLen = 0 68 69 security = ClassSecurityInfo() 70 71 _properties = OSComponent._properties + ( 72 {'id':'mount', 'type':'string', 'mode':''}, 73 {'id':'storageDevice', 'type':'string', 'mode':''}, 74 {'id':'type', 'type':'string', 'mode':''}, 75 {'id':'blockSize', 'type':'int', 'mode':''}, 76 {'id':'totalBlocks', 'type':'long', 'mode':''}, 77 {'id':'totalFiles', 'type':'long', 'mode':''}, 78 {'id':'maxNameLen', 'type':'int', 'mode':''}, 79 ) 80 _relations = OSComponent._relations + ( 81 ("os", ToOne(ToManyCont, "Products.ZenModel.OperatingSystem", "filesystems")), 82 ) 83 84 85 factory_type_information = ( 86 { 87 'id' : 'FileSystem', 88 'meta_type' : 'FileSystem', 89 'description' : """Arbitrary device grouping class""", 90 'icon' : 'FileSystem_icon.gif', 91 'product' : 'ZenModel', 92 'factory' : 'manage_addFileSystem', 93 'immediate_view' : 'viewFileSystem', 94 'actions' : 95 ( 96 { 'id' : 'status' 97 , 'name' : 'Status' 98 , 'action' : 'viewFileSystem' 99 , 'permissions' : (ZEN_VIEW,) 100 }, 101 { 'id' : 'events' 102 , 'name' : 'Events' 103 , 'action' : 'viewEvents' 104 , 'permissions' : (ZEN_VIEW, ) 105 }, 106 { 'id' : 'perfConf' 107 , 'name' : 'Template' 108 , 'action' : 'objTemplates' 109 , 'permissions' : ("Change Device", ) 110 }, 111 ) 112 }, 113 ) 114 115
116 - def getTotalBlocks(self):
117 offset = getattr(self.primaryAq(), 'zFileSystemSizeOffset', 1.0) 118 return int(self.totalBlocks) * offset
119 120
121 - def totalBytes(self):
122 """ 123 Return the total bytes of a filesytem 124 """ 125 return int(self.blockSize) * self.getTotalBlocks()
126 127
128 - def totalBytesString(self):
129 """ 130 Return the number of total bytes in human readable from ie 10MB 131 """ 132 return convToUnits(self.totalBytes())
133 134
135 - def usedBytes(self):
136 """ 137 Return the number of used bytes on a filesytem. 138 """ 139 blocks = self.usedBlocks() 140 if blocks is not None: 141 return self.blockSize * blocks 142 return None
143 144
145 - def usedBytesString(self):
146 """ 147 Return the number of used bytes in human readable form ie 10MB 148 """ 149 __pychecker__='no-constCond' 150 ub = self.usedBytes() 151 return ub is None and "unknown" or convToUnits(ub)
152 153
154 - def availBytes(self):
155 """ 156 Return the number of availible bytes for this filesystem 157 """ 158 blocks = self.availBlocks() 159 if blocks is not None: 160 return self.blockSize * blocks 161 return None
162 163
164 - def availBytesString(self):
165 """ 166 Return the number of availible bytes in human readable form ie 10MB 167 """ 168 __pychecker__='no-constCond' 169 ab = self.availBytes() 170 return ab is None and "unknown" or convToUnits(ab)
171 172
173 - def availFiles(self):
174 """ 175 Not implemented returns 0 176 """ 177 return 0
178 179
180 - def capacity(self):
181 """ 182 Return the percentage capacity of a filesystems using its rrd file. 183 Calculate using available blocks instead used blocks to account for 184 reserved blocks. 185 """ 186 __pychecker__='no-returnvalues' 187 totalBlocks = self.getTotalBlocks() 188 availBlocks = self.availBlocks() 189 if totalBlocks and availBlocks is not None: 190 return int(100.0 * (totalBlocks - availBlocks) / totalBlocks) 191 return 'unknown'
192 193
194 - def inodeCapacity(self):
195 """ 196 Not implemented returns 0 197 """ 198 return 0
199 200
201 - def usedBlocks(self, default = None):
202 """ 203 Return the number of used blocks stored in the filesystem's rrd file 204 """ 205 blocks = self.cacheRRDValue('usedBlocks', default) 206 if blocks is not None and not isnan(blocks): 207 return long(blocks) 208 elif self.blockSize: 209 # no usedBlocks datapoint, so this is probably a Windows device 210 # using perfmon for data collection and therefore we'll look for 211 # the freeMegabytes datapoint 212 freeMB = self.cacheRRDValue('FreeMegabytes', default) 213 if freeMB is not None: 214 usedBytes = self.totalBytes() - long(freeMB) * 1024 * 1024 215 return usedBytes / self.blockSize 216 return None
217 218
219 - def availBlocks(self, default = None):
220 """ 221 Return the number of available blocks stored in the filesystem's rrd file 222 """ 223 blocks = self.cacheRRDValue('availBlocks', default) 224 if blocks is not None and not isnan(blocks): 225 return long(blocks) 226 usedBlocks = self.usedBlocks() 227 if usedBlocks is None: 228 return None 229 return self.getTotalBlocks() - usedBlocks
230 231
232 - def usedBlocksString(self):
233 """ 234 Return the number of used blocks in human readable form ie 10MB 235 """ 236 __pychecker__='no-constCond' 237 ub = self.usedBlocks() 238 return ub is None and "unknown" or convToUnits(ub)
239 240
241 - def getRRDNames(self):
242 """ 243 Return the datapoint name of this filesystem 'usedBlocks_usedBlocks' 244 """ 245 return ['usedBlocks_usedBlocks']
246 247
248 - def viewName(self):
249 """ 250 Return the mount point name of a filesystem '/boot' 251 """ 252 return self.mount
253 name = viewName 254 255 256 security.declareProtected(ZEN_MANAGE_DEVICE, 'manage_editFileSystem')
257 - def manage_editFileSystem(self, monitor=False, 258 mount=None, storageDevice=None, 259 type=None, blockSize=None, 260 totalFiles=None, maxNameLen=None, 261 snmpindex=None, REQUEST=None):
262 """ 263 Edit a Service from a web page. 264 """ 265 if mount: 266 self.mount = mount 267 self.storageDevice = storageDevice 268 self.type = type 269 self.blockSize = blockSize 270 self.totalFiles = totalFiles 271 self.maxNameLen = maxNameLen 272 self.snmpindex = snmpindex 273 274 self.monitor = monitor 275 self.index_object() 276 277 if REQUEST: 278 messaging.IMessageSender(self).sendToBrowser( 279 'Filesystem Updated', 280 'Filesystem %s was edited.' % self.id 281 ) 282 return self.callZenScreen(REQUEST)
283 284 285 InitializeClass(FileSystem) 286