2020-04-19 12:28:49 +02:00
|
|
|
import socket
|
|
|
|
import subprocess
|
2019-08-26 16:54:48 +02:00
|
|
|
from shutil import which
|
|
|
|
|
|
|
|
|
|
|
|
def is_tool(name):
|
|
|
|
'''Check whether `name` is on PATH and marked as executable.'''
|
|
|
|
return which(name) is not None
|
2019-09-05 15:13:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
def get_vendor(name):
|
|
|
|
vendors = {
|
2019-09-11 14:22:07 +02:00
|
|
|
'PERC': 'Dell',
|
|
|
|
'SANDISK': 'SanDisk',
|
2019-09-10 11:44:23 +02:00
|
|
|
'DELL': 'Dell',
|
2019-09-05 15:13:36 +02:00
|
|
|
'ST': 'Seagate',
|
|
|
|
'CRUCIAL': 'Crucial',
|
|
|
|
'MICRON': 'Micron',
|
|
|
|
'INTEL': 'Intel',
|
|
|
|
'SAMSUNG': 'Samsung',
|
|
|
|
'EH0': 'HP',
|
|
|
|
'HGST': 'HGST',
|
|
|
|
'HUH': 'HGST',
|
|
|
|
'MB': 'Toshiba',
|
|
|
|
'MC': 'Toshiba',
|
|
|
|
'MD': 'Toshiba',
|
|
|
|
'MG': 'Toshiba',
|
|
|
|
'WD': 'WDC'
|
2020-02-02 20:08:56 +01:00
|
|
|
}
|
2019-09-05 15:13:36 +02:00
|
|
|
for key, value in vendors.items():
|
|
|
|
if name.upper().startswith(key):
|
|
|
|
return value
|
|
|
|
return name
|
2020-04-19 12:28:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
def get_hostname(config):
|
|
|
|
if config.hostname_cmd is None:
|
|
|
|
return '{}'.format(socket.gethostname())
|
|
|
|
return subprocess.getoutput(config.hostname_cmd)
|