Oob ip #307

Open
CllaudiaB wants to merge 3 commits from CllaudiaB/oob_ip into main
2 changed files with 18 additions and 8 deletions

View file

@ -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
ret['mac'] = _ipmi['MAC Address'] try:
ret['vlan'] = int(_ipmi['802.1q VLAN ID']) \ ret['mac'] = _ipmi['MAC Address']
if _ipmi['802.1q VLAN ID'] != 'Disabled' else None ret['vlan'] = int(_ipmi['802.1q VLAN ID']) \
ip = _ipmi['IP Address'] if _ipmi['802.1q VLAN ID'] != 'Disabled' else None
netmask = _ipmi['Subnet Mask'] ip = _ipmi['IP Address']
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]

View file

@ -482,6 +482,14 @@ class ServerBase():
update += 1 update += 1
if update: if update:
expansion.save() expansion.save()
myips = nb.ipam.ip_addresses.filter(device_id=server.id)
for ip in myips:
if ip.assigned_object.display == "IPMI":
server.update({'oob_ip': ip.id})
break
logging.debug('Finished updating Server!') logging.debug('Finished updating Server!')
def print_debug(self): def print_debug(self):