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 { 'id' : 'viewHistory' 112 , 'name' : 'Modifications' 113 , 'action' : 'viewHistory' 114 , 'permissions' : (ZEN_VIEW_MODIFICATIONS,) 115 }, 116 ) 117 }, 118 ) 119 120
121 - def getTotalBlocks(self):
122 offset = getattr(self.primaryAq(), 'zFileSystemSizeOffset', 1.0) 123 return int(self.totalBlocks) * offset
124 125
126 - def totalBytes(self):
127 """ 128 Return the total bytes of a filesytem 129 """ 130 return int(self.blockSize) * self.getTotalBlocks()
131 132
133 - def totalBytesString(self):
134 """ 135 Return the number of total bytes in human readable from ie 10MB 136 """ 137 return convToUnits(self.totalBytes())
138 139
140 - def usedBytes(self):
141 """ 142 Return the number of used bytes on a filesytem. 143 """ 144 blocks = self.usedBlocks() 145 if blocks is not None: 146 return self.blockSize * blocks 147 return None
148 149
150 - def usedBytesString(self):
151 """ 152 Return the number of used bytes in human readable form ie 10MB 153 """ 154 __pychecker__='no-constCond' 155 ub = self.usedBytes() 156 return ub is None and "unknown" or convToUnits(ub)
157 158
159 - def availBytes(self):
160 """ 161 Return the number of availible bytes for this filesystem 162 """ 163 blocks = self.availBlocks() 164 if blocks is not None: 165 return self.blockSize * blocks 166 return None
167 168
169 - def availBytesString(self):
170 """ 171 Return the number of availible bytes in human readable form ie 10MB 172 """ 173 __pychecker__='no-constCond' 174 ab = self.availBytes() 175 return ab is None and "unknown" or convToUnits(ab)
176 177
178 - def availFiles(self):
179 """ 180 Not implemented returns 0 181 """ 182 return 0
183 184
185 - def capacity(self):
186 """ 187 Return the percentage capacity of a filesystems using its rrd file. 188 Calculate using available blocks instead used blocks to account for 189 reserved blocks. 190 """ 191 __pychecker__='no-returnvalues' 192 totalBlocks = self.getTotalBlocks() 193 availBlocks = self.availBlocks() 194 if totalBlocks and availBlocks is not None: 195 return int(100.0 * (totalBlocks - availBlocks) / totalBlocks) 196 return 'unknown'
197 198
199 - def inodeCapacity(self):
200 """ 201 Not implemented returns 0 202 """ 203 return 0
204 205
206 - def usedBlocks(self, default = None):
207 """ 208 Return the number of used blocks stored in the filesystem's rrd file 209 """ 210 blocks = self.cacheRRDValue('usedBlocks', default) 211 if blocks is not None and not isnan(blocks): 212 return long(blocks) 213 elif self.blockSize: 214 # no usedBlocks datapoint, so this is probably a Windows device 215 # using perfmon for data collection and therefore we'll look for 216 # the freeMegabytes datapoint 217 freeMB = self.cacheRRDValue('FreeMegabytes', default) 218 if freeMB is not None: 219 usedBytes = self.totalBytes() - long(freeMB) * 1024 * 1024 220 return usedBytes / self.blockSize 221 return None
222 223
224 - def availBlocks(self, default = None):
225 """ 226 Return the number of available blocks stored in the filesystem's rrd file 227 """ 228 blocks = self.cacheRRDValue('availBlocks', default) 229 if blocks is not None and not isnan(blocks): 230 return long(blocks) 231 usedBlocks = self.usedBlocks() 232 if usedBlocks is None: 233 return None 234 return self.getTotalBlocks() - usedBlocks
235 236
237 - def usedBlocksString(self):
238 """ 239 Return the number of used blocks in human readable form ie 10MB 240 """ 241 __pychecker__='no-constCond' 242 ub = self.usedBlocks() 243 return ub is None and "unknown" or convToUnits(ub)
244 245
246 - def getRRDNames(self):
247 """ 248 Return the datapoint name of this filesystem 'usedBlocks_usedBlocks' 249 """ 250 return ['usedBlocks_usedBlocks']
251 252
253 - def viewName(self):
254 """ 255 Return the mount point name of a filesystem '/boot' 256 """ 257 return self.mount
258 name = viewName 259 260 261 security.declareProtected(ZEN_MANAGE_DEVICE, 'manage_editFileSystem')
262 - def manage_editFileSystem(self, monitor=False, 263 mount=None, storageDevice=None, 264 type=None, blockSize=None, 265 totalFiles=None, maxNameLen=None, 266 snmpindex=None, REQUEST=None):
267 """ 268 Edit a Service from a web page. 269 """ 270 if mount: 271 self.mount = mount 272 self.storageDevice = storageDevice 273 self.type = type 274 self.blockSize = blockSize 275 self.totalFiles = totalFiles 276 self.maxNameLen = maxNameLen 277 self.snmpindex = snmpindex 278 279 self.monitor = monitor 280 self.index_object() 281 282 if REQUEST: 283 messaging.IMessageSender(self).sendToBrowser( 284 'Filesystem Updated', 285 'Filesystem %s was edited.' % self.id 286 ) 287 return self.callZenScreen(REQUEST)
288 289 290 InitializeClass(FileSystem) 291