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

Source Code for Module Products.ZenModel.FileSystem

  1  ############################################################################## 
  2  #  
  3  # Copyright (C) Zenoss, Inc. 2007, all rights reserved. 
  4  #  
  5  # This content is made available according to terms specified in 
  6  # License.zenoss under the directory where your Zenoss product is installed. 
  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   
34 -def manage_addFileSystem(context, newId, userCreated, REQUEST=None):
35 """make a filesystem""" 36 fsid = prepId(newId) 37 fs = FileSystem(fsid) 38 context._setObject(fsid, fs) 39 fs = context._getOb(fsid) 40 fs.mount = newId 41 if userCreated: fs.setUserCreateFlag() 42 if REQUEST is not None: 43 REQUEST['RESPONSE'].redirect(context.absolute_url()+'/manage_main')
44 45 addFileSystem = DTMLFile('dtml/addFileSystem',globals()) 46
47 -class FileSystem(OSComponent):
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
113 - def getTotalBlocks(self):
114 offset = getattr(self.primaryAq(), 'zFileSystemSizeOffset', 1.0) 115 return int(self.totalBlocks) * offset
116 117
118 - def totalBytes(self):
119 """ 120 Return the total bytes of a filesytem 121 """ 122 return int(self.blockSize) * self.getTotalBlocks()
123 124
125 - def totalBytesString(self):
126 """ 127 Return the number of total bytes in human readable from ie 10MB 128 """ 129 return convToUnits(self.totalBytes())
130 131
132 - def usedBytes(self):
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
142 - def usedBytesString(self):
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
151 - def availBytes(self):
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
161 - def availBytesString(self):
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
170 - def availFiles(self):
171 """ 172 Not implemented returns 0 173 """ 174 return 0
175 176
177 - def capacity(self):
178 """ 179 Return the percentage capacity of a filesystems using its rrd file. 180 Calculate using available blocks instead used blocks to account for 181 reserved blocks. 182 """ 183 __pychecker__='no-returnvalues' 184 totalBlocks = self.getTotalBlocks() 185 availBlocks = self.availBlocks() 186 if totalBlocks and availBlocks is not None: 187 return round(100.0 * (totalBlocks - availBlocks) / totalBlocks) 188 return 'unknown'
189 190
191 - def inodeCapacity(self):
192 """ 193 Not implemented returns 0 194 """ 195 return 0
196 197
198 - def usedBlocks(self, default = None):
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 # no usedBlocks datapoint, so this is probably a Windows device 212 # using perfmon for data collection and therefore we'll look for 213 # the freeMegabytes datapoint 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
221 - def availBlocks(self, default = None):
222 """ 223 Return the number of available blocks stored in the filesystem's rrd file 224 """ 225 blocks = self.cacheRRDValue('availBlocks', default) 226 if blocks is not None and not isnan(blocks): 227 return long(blocks) 228 usedBlocks = self.usedBlocks() 229 if usedBlocks is None: 230 return None 231 return self.getTotalBlocks() - usedBlocks
232 233
234 - def usedBlocksString(self):
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
243 - def getRRDNames(self):
244 """ 245 Return the datapoint name of this filesystem 'usedBlocks_usedBlocks' 246 """ 247 return ['usedBlocks_usedBlocks']
248 249
250 - def viewName(self):
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):
264 """ 265 Edit a Service from a web page. 266 """ 267 if mount: 268 self.mount = mount 269 self.storageDevice = storageDevice 270 self.type = type 271 self.blockSize = blockSize 272 self.totalFiles = totalFiles 273 self.maxNameLen = maxNameLen 274 self.snmpindex = snmpindex 275 276 self.monitor = monitor 277 self.index_object() 278 279 if REQUEST: 280 messaging.IMessageSender(self).sendToBrowser( 281 'Filesystem Updated', 282 'Filesystem %s was edited.' % self.id 283 ) 284 return self.callZenScreen(REQUEST)
285 286 287 InitializeClass(FileSystem) 288