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

Source Code for Module 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   
 22  import locale 
 23   
 24  from Globals import DTMLFile 
 25  from Globals import InitializeClass 
 26   
 27  from Products.ZenUtils.Utils import convToUnits 
 28  from Products.ZenRelations.RelSchema import * 
 29   
 30  from OSComponent import OSComponent 
 31  from Products.ZenUtils.Utils import prepId 
 32   
33 -def manage_addFileSystem(context, id, userCreated, REQUEST=None):
34 """make a filesystem""" 35 fsid = prepId(id) 36 fs = FileSystem(fsid) 37 context._setObject(fsid, fs) 38 fs = context._getOb(fsid) 39 setattr(fs, 'mount', id) 40 if userCreated: fs.setUserCreateFlag() 41 if REQUEST is not None: 42 REQUEST['RESPONSE'].redirect(context.absolute_url()+'/manage_main')
43 44 addFileSystem = DTMLFile('dtml/addFileSystem',globals()) 45
46 -class FileSystem(OSComponent):
47 """FileSystem object""" 48 49 portal_type = meta_type = 'FileSystem' 50 51 manage_editFileSystemForm = DTMLFile('dtml/manageEditFileSystem',globals()) 52 53 mount = "" 54 storageDevice = "" 55 type = "" 56 blockSize = 0 57 totalBlocks = 0L 58 totalFiles = 0L 59 capacity = 0 60 inodeCapacity = 0 61 maxNameLen = 0 62 63 _properties = OSComponent._properties + ( 64 {'id':'mount', 'type':'string', 'mode':''}, 65 {'id':'storageDevice', 'type':'string', 'mode':''}, 66 {'id':'type', 'type':'string', 'mode':''}, 67 {'id':'blockSize', 'type':'int', 'mode':''}, 68 {'id':'totalBlocks', 'type':'long', 'mode':''}, 69 {'id':'totalFiles', 'type':'long', 'mode':''}, 70 {'id':'maxNameLen', 'type':'int', 'mode':''}, 71 ) 72 _relations = OSComponent._relations + ( 73 ("os", ToOne(ToManyCont, "Products.ZenModel.OperatingSystem", "filesystems")), 74 ) 75 76 77 factory_type_information = ( 78 { 79 'id' : 'FileSystem', 80 'meta_type' : 'FileSystem', 81 'description' : """Arbitrary device grouping class""", 82 'icon' : 'FileSystem_icon.gif', 83 'product' : 'ZenModel', 84 'factory' : 'manage_addFileSystem', 85 'immediate_view' : 'viewFileSystem', 86 'actions' : 87 ( 88 { 'id' : 'status' 89 , 'name' : 'Status' 90 , 'action' : 'viewFileSystem' 91 , 'permissions' : ('View',) 92 }, 93 { 'id' : 'perfConf' 94 , 'name' : 'Template' 95 , 'action' : 'objTemplates' 96 , 'permissions' : ("Change Device", ) 97 }, 98 { 'id' : 'viewHistory' 99 , 'name' : 'Modifications' 100 , 'action' : 'viewHistory' 101 , 'permissions' : ('View',) 102 }, 103 ) 104 }, 105 ) 106 107
108 - def totalBytes(self):
109 return int(self.blockSize) * int(self.totalBlocks)
110
111 - def totalBytesString(self):
112 return convToUnits(self.totalBytes())
113
114 - def usedBytes(self):
115 blocks = self.usedBlocks() 116 if blocks is not None: 117 return self.blockSize * blocks 118 return None
119
120 - def usedBytesString(self):
121 ub = self.usedBytes() 122 return ub is None and "unknown" or convToUnits(ub)
123 124
125 - def availBytes(self):
126 blocks = self.usedBlocks() 127 if blocks is not None: 128 return self.blockSize * (self.totalBlocks - self.usedBlocks()) 129 return None
130
131 - def availBytesString(self):
132 ab = self.availBytes() 133 return ab is None and "unknown" or convToUnits(ab)
134 135
136 - def availFiles(self):
137 return 0
138
139 - def capacity(self):
140 usedBytes = self.usedBytes() 141 if self.totalBytes() and usedBytes is not None: 142 return int(100.0 * self.usedBytes() / self.totalBytes()) 143 return 'unknown'
144
145 - def inodeCapacity(self):
146 return 0
147
148 - def usedBlocks(self, default = None):
149 blocks = self.cacheRRDValue('usedBlocks', default) 150 if blocks is not None: 151 return long(blocks) 152 return None
153
154 - def usedBlocksString(self):
155 ub = self.usedBlocks() 156 return ub is None and "unknown" or convToUnits(ub)
157 158
159 - def getRRDNames(self):
160 return ['usedBlocks_usedBlocks']
161
162 - def viewName(self): return self.mount
163 name = viewName 164
165 - def manage_editFileSystem(self, monitor=False, 166 mount=None, storageDevice=None, 167 type=None, blockSize=None, 168 totalFiles=None, maxNameLen=None, 169 snmpindex=None, REQUEST=None):
170 """Edit a Service from a web page. 171 """ 172 if mount: 173 self.mount = mount 174 self.storageDevice = storageDevice 175 self.type = type 176 self.blockSize = blockSize 177 self.totalFiles = totalFiles 178 self.maxNameLen = maxNameLen 179 self.snmpindex = snmpindex 180 181 self.monitor = monitor 182 183 if REQUEST: 184 REQUEST['message'] = "FileSystem updated" 185 return self.callZenScreen(REQUEST)
186 187 188 InitializeClass(FileSystem) 189