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