Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include rotational disks in grains under linux #31981

Merged
merged 1 commit into from Mar 18, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions salt/grains/disks.py
Expand Up @@ -31,7 +31,7 @@ def disks():
if salt.utils.is_freebsd():
return _freebsd_disks()
elif salt.utils.is_linux():
return {'SSDs': _linux_ssds()}
return _linux_disks()
else:
log.trace('Disk grain does not support OS')

Expand Down Expand Up @@ -118,23 +118,23 @@ def parse_inquiry(inquiry):
return ret


def _linux_ssds():
def _linux_disks():
'''
Return list of disk devices that are SSD (non-rotational)
Return list of disk devices and work out if they are SSD or HDD.
'''
ssd_devices = []
ret = {'disks': [], 'SSDs': []}

for entry in glob.glob('/sys/block/*/queue/rotational'):
with salt.utils.fopen(entry) as entry_fp:
device = entry.split('/')[3]
flag = entry_fp.read(1)
if flag == '0':
ssd_devices.append(device)
ret['SSDs'].append(device)
log.trace('Device {0} reports itself as an SSD'.format(device))
elif flag == '1':
log.trace('Device {0} does not report itself as an SSD'
.format(device))
ret['disks'].append(device)
log.trace('Device {0} reports itself as an HDD'.format(device))
else:
log.trace('Unable to identify device {0} as an SSD or not.'
log.trace('Unable to identify device {0} as an SSD or HDD.'
' It does not report 0 or 1'.format(device))
return ssd_devices
return ret