add sudo support
This commit is contained in:
parent
957e5f4fb9
commit
66913bb59c
6 changed files with 17 additions and 7 deletions
10
README.md
10
README.md
|
|
@ -73,6 +73,16 @@ rack_location:
|
||||||
inventory: true
|
inventory: true
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# using SUDO.
|
||||||
|
|
||||||
|
if you install run as root, no extra configuration is needed.
|
||||||
|
|
||||||
|
If you desire to run as a-non-root user, you will need to either create or add to the /etc/sudoers or create a new file in /etc/sudoers.d with a line like so:
|
||||||
|
|
||||||
|
USERNAME ALL=(ALL) NOPASSWD: /usr/sbin/lshw, /usr/bin/ipmitool, /usr/bin/ovs-vsctl, /usr/sbin/dmidecode, /usr/sbin/ethtool, /usr/sbin/lldpcli, /usr/sbin/nvme
|
||||||
|
|
||||||
|
Replace USERNAME with the username you wish to run the agent under.
|
||||||
|
|
||||||
# Specific workflow
|
# Specific workflow
|
||||||
|
|
||||||
## Blades
|
## Blades
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ def _execute_cmd():
|
||||||
logging.error('Dmidecode does not seem to be present on your system. Add it your path or '
|
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.')
|
'check the compatibility of this project with your distro.')
|
||||||
sys.exit(1)
|
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):
|
def _parse(buffer):
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ class Ethtool():
|
||||||
parse ethtool output
|
parse ethtool output
|
||||||
"""
|
"""
|
||||||
|
|
||||||
output = subprocess.getoutput('ethtool {}'.format(self.interface))
|
output = subprocess.getoutput('sudo /usr/sbin/ethtool {}'.format(self.interface))
|
||||||
|
|
||||||
fields = {}
|
fields = {}
|
||||||
field = ''
|
field = ''
|
||||||
|
|
@ -63,7 +63,7 @@ class Ethtool():
|
||||||
return fields
|
return fields
|
||||||
|
|
||||||
def _parse_ethtool_module_output(self):
|
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:
|
if status != 0:
|
||||||
return {}
|
return {}
|
||||||
r = re.search(r'Identifier.*\((\w+)\)', output)
|
r = re.search(r'Identifier.*\((\w+)\)', output)
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ class IPMI():
|
||||||
Bad Password Threshold : Not Available
|
Bad Password Threshold : Not Available
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
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:
|
if self.ret != 0:
|
||||||
logging.error('Cannot get ipmi info: {}'.format(self.output))
|
logging.error('Cannot get ipmi info: {}'.format(self.output))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import subprocess
|
||||||
|
|
||||||
class LLDP():
|
class LLDP():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.output = subprocess.getoutput('lldpctl -f keyvalue')
|
self.output = subprocess.getoutput('sudo /usr/sbin/lldpctl -f keyvalue')
|
||||||
self.data = self.parse()
|
self.data = self.parse()
|
||||||
|
|
||||||
def parse(self):
|
def parse(self):
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ class LSHW():
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
data = subprocess.getoutput(
|
data = subprocess.getoutput(
|
||||||
'lshw -quiet -json'
|
'sudo /usr/sbin/lshw -quiet -json'
|
||||||
)
|
)
|
||||||
self.hw_info = json.loads(data)
|
self.hw_info = json.loads(data)
|
||||||
self.info = {}
|
self.info = {}
|
||||||
|
|
@ -86,7 +86,7 @@ class LSHW():
|
||||||
|
|
||||||
elif "nvme" in obj["configuration"]["driver"]:
|
elif "nvme" in obj["configuration"]["driver"]:
|
||||||
nvme = json.loads(
|
nvme = json.loads(
|
||||||
subprocess.check_output(["nvme", '-list', '-o', 'json'],
|
subprocess.check_output(["sudo", "/usr/sbin/nvme", '-list', '-o', 'json'],
|
||||||
encoding='utf8')) # noqa: E128
|
encoding='utf8')) # noqa: E128
|
||||||
|
|
||||||
d = {}
|
d = {}
|
||||||
|
|
|
||||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue