continue parsing even if the command return is different from 0
This commit is contained in:
parent
0cf5861272
commit
2caf2a0042
1 changed files with 10 additions and 8 deletions
|
@ -39,12 +39,10 @@ class IPMI():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.ret, self.output = subprocess.getstatusoutput('ipmitool lan print')
|
self.ret, self.output = subprocess.getstatusoutput('ipmitool lan print')
|
||||||
if self.ret != 0:
|
if self.ret != 0:
|
||||||
logging.error('Cannot get ipmi info: {}'.format(self.output))
|
logging.warning('IPMI command failed: {}'.format(self.output))
|
||||||
|
|
||||||
def parse(self):
|
def parse(self):
|
||||||
_ipmi = {}
|
_ipmi = {}
|
||||||
if self.ret != 0:
|
|
||||||
return _ipmi
|
|
||||||
|
|
||||||
for line in self.output.splitlines():
|
for line in self.output.splitlines():
|
||||||
key = line.split(':')[0].strip()
|
key = line.split(':')[0].strip()
|
||||||
|
@ -57,11 +55,15 @@ class IPMI():
|
||||||
ret['name'] = 'IPMI'
|
ret['name'] = 'IPMI'
|
||||||
ret["mtu"] = 1500
|
ret["mtu"] = 1500
|
||||||
ret['bonding'] = False
|
ret['bonding'] = False
|
||||||
|
try:
|
||||||
ret['mac'] = _ipmi['MAC Address']
|
ret['mac'] = _ipmi['MAC Address']
|
||||||
ret['vlan'] = int(_ipmi['802.1q VLAN ID']) \
|
ret['vlan'] = int(_ipmi['802.1q VLAN ID']) \
|
||||||
if _ipmi['802.1q VLAN ID'] != 'Disabled' else None
|
if _ipmi['802.1q VLAN ID'] != 'Disabled' else None
|
||||||
ip = _ipmi['IP Address']
|
ip = _ipmi['IP Address']
|
||||||
netmask = _ipmi['Subnet Mask']
|
netmask = _ipmi['Subnet Mask']
|
||||||
|
except KeyError as e:
|
||||||
|
logging.error("IPMI decoding failed, missing: ", e.args[0])
|
||||||
|
return {}
|
||||||
address = str(IPNetwork('{}/{}'.format(ip, netmask)))
|
address = str(IPNetwork('{}/{}'.format(ip, netmask)))
|
||||||
|
|
||||||
ret['ip'] = [address]
|
ret['ip'] = [address]
|
||||||
|
|
Loading…
Reference in a new issue