add sudo support

This commit is contained in:
Thomas Davis 2020-01-20 15:15:50 -08:00
commit 66913bb59c
6 changed files with 17 additions and 7 deletions

View file

@ -138,7 +138,7 @@ def _execute_cmd():
logging.error('Dmidecode does not seem to be present on your system. Add it your path or '
'check the compatibility of this project with your distro.')
sys.exit(1)
return _subprocess.check_output(['dmidecode', ], stderr=_subprocess.PIPE)
return _subprocess.check_output(['sudo', '/usr/sbin/dmidecode', ], stderr=_subprocess.PIPE)
def _parse(buffer):

View file

@ -39,7 +39,7 @@ class Ethtool():
parse ethtool output
"""
output = subprocess.getoutput('ethtool {}'.format(self.interface))
output = subprocess.getoutput('sudo /usr/sbin/ethtool {}'.format(self.interface))
fields = {}
field = ''
@ -63,7 +63,7 @@ class Ethtool():
return fields
def _parse_ethtool_module_output(self):
status, output = subprocess.getstatusoutput('ethtool -m {}'.format(self.interface))
status, output = subprocess.getstatusoutput('sudo /usr/sbin/ethtool -m {}'.format(self.interface))
if status != 0:
return {}
r = re.search(r'Identifier.*\((\w+)\)', output)

View file

@ -34,7 +34,7 @@ class IPMI():
Bad Password Threshold : Not Available
"""
def __init__(self):
self.ret, self.output = subprocess.getstatusoutput('ipmitool lan print')
self.ret, self.output = subprocess.getstatusoutput('sudo /usr/bin/ipmitool lan print')
if self.ret != 0:
logging.error('Cannot get ipmi info: {}'.format(self.output))

View file

@ -3,7 +3,7 @@ import subprocess
class LLDP():
def __init__(self):
self.output = subprocess.getoutput('lldpctl -f keyvalue')
self.output = subprocess.getoutput('sudo /usr/sbin/lldpctl -f keyvalue')
self.data = self.parse()
def parse(self):

View file

@ -13,7 +13,7 @@ class LSHW():
sys.exit(1)
data = subprocess.getoutput(
'lshw -quiet -json'
'sudo /usr/sbin/lshw -quiet -json'
)
self.hw_info = json.loads(data)
self.info = {}
@ -86,7 +86,7 @@ class LSHW():
elif "nvme" in obj["configuration"]["driver"]:
nvme = json.loads(
subprocess.check_output(["nvme", '-list', '-o', 'json'],
subprocess.check_output(["sudo", "/usr/sbin/nvme", '-list', '-o', 'json'],
encoding='utf8')) # noqa: E128
d = {}