more fixes
This commit is contained in:
parent
2988a8bd6a
commit
09815306ef
3 changed files with 45 additions and 43 deletions
|
|
@ -34,5 +34,5 @@ if config.get('rack_location'):
|
|||
NETWORK_IGNORE_INTERFACES = None
|
||||
NETWORK_IGNORE_IPS = None
|
||||
if config.get('network'):
|
||||
NETWORK_IGNORE_INTERFACES = config['network']['ignore_interfaces']
|
||||
NETWORK_IGNORE_IPS = config['network']['ignore_ips']
|
||||
NETWORK_IGNORE_INTERFACES = config['network'].get('ignore_interfaces')
|
||||
NETWORK_IGNORE_IPS = config['network'].get('ignore_ips')
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import logging
|
|||
import subprocess
|
||||
|
||||
|
||||
class Ipmi():
|
||||
class IPMI():
|
||||
"""
|
||||
Parse IPMI output
|
||||
ie:
|
||||
|
|
@ -42,7 +42,7 @@ class Ipmi():
|
|||
ret = {}
|
||||
if self.ret != 0:
|
||||
return ret
|
||||
for line in self.output.split('\n'):
|
||||
for line in self.output.splitlines():
|
||||
key = line.split(':')[0].strip()
|
||||
value = ':'.join(line.split(':')[1:]).strip()
|
||||
ret[key] = value
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import netifaces
|
|||
from netbox_agent.config import netbox_instance as nb
|
||||
from netbox_agent.config import NETWORK_IGNORE_INTERFACES, NETWORK_IGNORE_IPS
|
||||
from netbox_agent.ethtool import Ethtool
|
||||
from netbox_agent.ipmi import Ipmi
|
||||
from netbox_agent.ipmi import IPMI
|
||||
|
||||
IFACE_TYPE_100ME_FIXED = 800
|
||||
IFACE_TYPE_1GE_FIXED = 1000
|
||||
|
|
@ -56,7 +56,7 @@ class Network():
|
|||
re.match(NETWORK_IGNORE_INTERFACES, interface):
|
||||
logging.debug('Ignore interface {interface}'.format(interface=interface))
|
||||
continue
|
||||
else:
|
||||
|
||||
ip_addr = netifaces.ifaddresses(interface).get(netifaces.AF_INET)
|
||||
if NETWORK_IGNORE_IPS and ip_addr:
|
||||
for i, ip in enumerate(ip_addr):
|
||||
|
|
@ -94,15 +94,17 @@ class Network():
|
|||
bonding_nics = [x for x in self.nics if x['bonding']]
|
||||
if not len(bonding_nics):
|
||||
return False
|
||||
|
||||
logging.debug('Setting bonding interfaces..')
|
||||
for nic in bonding_nics:
|
||||
bond_int = self.get_netbox_network_card(nic)
|
||||
logging.debug('Setting slave interface for {name}'.format(
|
||||
name=bond_int.name
|
||||
))
|
||||
for slave in nic['bonding_slaves']:
|
||||
slave_nic = next(item for item in self.nics if item['name'] == slave)
|
||||
slave_int = self.get_netbox_network_card(slave_nic)
|
||||
for slave_int in (
|
||||
self.get_netbox_network_card(slave_nic)
|
||||
for slave_nic in self.nics
|
||||
if slave_nic['name'] in nic['bonding_slaves']):
|
||||
logging.debug('Settting interface {name} as slave of {master}'.format(
|
||||
name=slave_int.name, master=bond_int.name
|
||||
))
|
||||
|
|
@ -149,7 +151,7 @@ class Network():
|
|||
return IFACE_TYPE_OTHER
|
||||
|
||||
def get_ipmi(self):
|
||||
ipmi = Ipmi().parse()
|
||||
ipmi = IPMI().parse()
|
||||
return ipmi
|
||||
|
||||
def get_netbox_ipmi(self):
|
||||
|
|
@ -199,7 +201,7 @@ class Network():
|
|||
ip = ipmi['IP Address']
|
||||
netmask = ipmi['Subnet Mask']
|
||||
vlan = int(ipmi['802.1q VLAN ID']) if ipmi['802.1q VLAN ID'] != 'Disabled' else None
|
||||
address = IPNetwork('{}/{}'.format(ip, netmask)).__str__()
|
||||
address = str(IPNetwork('{}/{}'.format(ip, netmask)))
|
||||
|
||||
interface = nb.dcim.interfaces.get(
|
||||
device_id=self.device.id,
|
||||
|
|
|
|||
Loading…
Add table
editor.link_modal.header
Reference in a new issue