Created
January 23, 2016 00:03
-
-
Save sjmh/ccbff7d9af827c634d14 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
''' | |
SCSI administration module | |
''' | |
from __future__ import absolute_import | |
import os.path | |
import logging | |
log = logging.getLogger(__name__) | |
__func_alias__ = { | |
'ls_': 'ls' | |
} | |
def ls_(get_size=True): | |
''' | |
List SCSI devices, with details | |
CLI Example: | |
.. code-block:: bash | |
salt '*' scsi.ls | |
''' | |
if get_size: | |
cmd = 'lsscsi -dLsv' | |
else: | |
cmd = 'lsscsi -dLv' | |
ret = {} | |
for line in __salt__['cmd.run'](cmd).splitlines(): | |
if line.startswith('['): | |
size = None | |
major = None | |
minor = None | |
mode = 'start' | |
comps = line.strip().split() | |
key = comps[0] | |
if get_size: | |
size = comps.pop() | |
majmin = comps.pop() | |
if majmin.startswith('['): | |
major, minor = majmin.replace('[', '').replace(']', '').split(':') | |
device = comps.pop() | |
model = ' '.join(comps[3:]) | |
ret[key] = { | |
'lun': key.replace('[', '').replace(']', ''), | |
'size': size, | |
'major': major, | |
'minor': minor, | |
'device': device, | |
'model': model, | |
} | |
elif line.startswith(' '): | |
if line.strip().startswith('dir'): | |
comps = line.strip().split() | |
ret[key]['dir'] = [ | |
comps[1], | |
comps[2].replace('[', '').replace(']', '') | |
] | |
else: | |
comps = line.strip().split('=') | |
ret[key][comps[0]] = comps[1] | |
return ret | |
def rescan_all(host): | |
''' | |
List scsi devices | |
CLI Example: | |
.. code-block:: bash | |
salt '*' scsi.rescan_all(0) | |
''' | |
if os.path.isdir('/sys/class/scsi_host/host{0}'.format(host)): | |
cmd = 'echo "- - -" > /sys/class/scsi_host/host{0}/scan'.format(host) | |
else: | |
return 'Host {0} does not exist'.format(host) | |
return __salt__['cmd.run'](cmd).splitlines() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment