Add disk.inodeusage and fix disk.usage logic

Previously, disk.usage was returning a dictionary where the key was in
the "Filesystem" column. It seemed proper to return every  filesystem,
even the virtual ones so the dict key was changed to  the  mountpoint.

$ df -P
Filesystem         1024-blocks      Used Available Capacity Mounted on
/dev/sda8            177822980  12504764 156285272       8% /
none                   6154104       312   6153792       1% /dev
none                   6161372      3736   6157636       1% /dev/shm
none                   6161372       336   6161036       1% /var/run
none                   6161372         0   6161372       0% /var/lock
/dev/sda1               101086     85423     15663      85% /boot
/dev/sda5            240308484 219822840  20485644      92% /home
/dev/sda7             54791132   1104204  50903672       3% /var

This can be changed to skip anything that has a Filesystem of none
down the road, but I don't have any non-Linux hosts  to  test  on.
This commit is contained in:
Jeff Schroeder 2011-12-14 20:47:13 -08:00
parent 98148b33e4
commit 5e6f23fbef

View File

@ -20,11 +20,42 @@ def usage():
if line.startswith('Filesystem'): if line.startswith('Filesystem'):
continue continue
comps = line.split() comps = line.split()
ret[comps[0]] = { ret[comps[5]] = {
'1K-blocks': comps[1], 'filesystem': comps[0],
'available': comps[3], '1K-blocks': comps[1],
'capacity': comps[4], 'used': comps[2],
'mountpoint': comps[5], 'available': comps[3],
'used': comps[2] 'capacity': comps[4],
} }
return ret return ret
def inodeusage():
'''
Return inode usage information for volumes mounted on this minion
CLI Example::
salt '*' disk.inodeusage
'''
cmd = 'df -i'
ret = {}
out = __salt__['cmd.run'](cmd).split('\n')
for line in out:
if line.startswith('Filesystem'):
continue
comps = line.split()
# Don't choke on empty lines
if not comps:
continue
try:
ret[comps[5]] = {
'inodes': comps[1],
'used': comps[2],
'free': comps[3],
'use': comps[4],
'filesystem': comps[0],
}
except IndexError:
print "DEBUG: comps='%s'" % comps
return ret