Merge pull request #8037 from pyinx/patch-1

Update disk.py
This commit is contained in:
Joseph Hall 2013-10-23 03:22:15 -07:00
commit ac5953bd4c

View File

@ -142,3 +142,42 @@ def inodeusage(args=None):
log.warn("Problem parsing inode usage information")
ret = {}
return ret
def percent(args=None):
'''
Return partion information for volumes mounted on this minion
CLI Example::
salt '*' disk.percent /var
'''
if __grains__['kernel'] == 'Linux':
cmd = 'df -P'
elif __grains__['kernel'] == 'OpenBSD':
cmd = 'df -kP'
else:
cmd = 'df'
ret = {}
out = __salt__['cmd.run'](cmd).splitlines()
for line in out:
if not line:
continue
if line.startswith('Filesystem'):
continue
comps = line.split()
while not comps[1].isdigit():
comps[0] = '{0} {1}'.format(comps[0], comps[1])
comps.pop(1)
try:
if __grains__['kernel'] == 'Darwin':
ret[comps[8]] = comps[4]
else:
ret[comps[5]] = comps[4]
except IndexError:
log.warn("Problem parsing disk usage information")
ret = {}
if args:
return ret[args]
else:
return ret