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_INTERFACES = None
|
||||||
NETWORK_IGNORE_IPS = None
|
NETWORK_IGNORE_IPS = None
|
||||||
if config.get('network'):
|
if config.get('network'):
|
||||||
NETWORK_IGNORE_INTERFACES = config['network']['ignore_interfaces']
|
NETWORK_IGNORE_INTERFACES = config['network'].get('ignore_interfaces')
|
||||||
NETWORK_IGNORE_IPS = config['network']['ignore_ips']
|
NETWORK_IGNORE_IPS = config['network'].get('ignore_ips')
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import logging
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
class Ipmi():
|
class IPMI():
|
||||||
"""
|
"""
|
||||||
Parse IPMI output
|
Parse IPMI output
|
||||||
ie:
|
ie:
|
||||||
|
|
@ -42,7 +42,7 @@ class Ipmi():
|
||||||
ret = {}
|
ret = {}
|
||||||
if self.ret != 0:
|
if self.ret != 0:
|
||||||
return ret
|
return ret
|
||||||
for line in self.output.split('\n'):
|
for line in self.output.splitlines():
|
||||||
key = line.split(':')[0].strip()
|
key = line.split(':')[0].strip()
|
||||||
value = ':'.join(line.split(':')[1:]).strip()
|
value = ':'.join(line.split(':')[1:]).strip()
|
||||||
ret[key] = value
|
ret[key] = value
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import netifaces
|
||||||
from netbox_agent.config import netbox_instance as nb
|
from netbox_agent.config import netbox_instance as nb
|
||||||
from netbox_agent.config import NETWORK_IGNORE_INTERFACES, NETWORK_IGNORE_IPS
|
from netbox_agent.config import NETWORK_IGNORE_INTERFACES, NETWORK_IGNORE_IPS
|
||||||
from netbox_agent.ethtool import Ethtool
|
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_100ME_FIXED = 800
|
||||||
IFACE_TYPE_1GE_FIXED = 1000
|
IFACE_TYPE_1GE_FIXED = 1000
|
||||||
|
|
@ -56,7 +56,7 @@ class Network():
|
||||||
re.match(NETWORK_IGNORE_INTERFACES, interface):
|
re.match(NETWORK_IGNORE_INTERFACES, interface):
|
||||||
logging.debug('Ignore interface {interface}'.format(interface=interface))
|
logging.debug('Ignore interface {interface}'.format(interface=interface))
|
||||||
continue
|
continue
|
||||||
else:
|
|
||||||
ip_addr = netifaces.ifaddresses(interface).get(netifaces.AF_INET)
|
ip_addr = netifaces.ifaddresses(interface).get(netifaces.AF_INET)
|
||||||
if NETWORK_IGNORE_IPS and ip_addr:
|
if NETWORK_IGNORE_IPS and ip_addr:
|
||||||
for i, ip in enumerate(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']]
|
bonding_nics = [x for x in self.nics if x['bonding']]
|
||||||
if not len(bonding_nics):
|
if not len(bonding_nics):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
logging.debug('Setting bonding interfaces..')
|
logging.debug('Setting bonding interfaces..')
|
||||||
for nic in bonding_nics:
|
for nic in bonding_nics:
|
||||||
bond_int = self.get_netbox_network_card(nic)
|
bond_int = self.get_netbox_network_card(nic)
|
||||||
logging.debug('Setting slave interface for {name}'.format(
|
logging.debug('Setting slave interface for {name}'.format(
|
||||||
name=bond_int.name
|
name=bond_int.name
|
||||||
))
|
))
|
||||||
for slave in nic['bonding_slaves']:
|
for slave_int in (
|
||||||
slave_nic = next(item for item in self.nics if item['name'] == slave)
|
self.get_netbox_network_card(slave_nic)
|
||||||
slave_int = 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(
|
logging.debug('Settting interface {name} as slave of {master}'.format(
|
||||||
name=slave_int.name, master=bond_int.name
|
name=slave_int.name, master=bond_int.name
|
||||||
))
|
))
|
||||||
|
|
@ -149,7 +151,7 @@ class Network():
|
||||||
return IFACE_TYPE_OTHER
|
return IFACE_TYPE_OTHER
|
||||||
|
|
||||||
def get_ipmi(self):
|
def get_ipmi(self):
|
||||||
ipmi = Ipmi().parse()
|
ipmi = IPMI().parse()
|
||||||
return ipmi
|
return ipmi
|
||||||
|
|
||||||
def get_netbox_ipmi(self):
|
def get_netbox_ipmi(self):
|
||||||
|
|
@ -199,7 +201,7 @@ class Network():
|
||||||
ip = ipmi['IP Address']
|
ip = ipmi['IP Address']
|
||||||
netmask = ipmi['Subnet Mask']
|
netmask = ipmi['Subnet Mask']
|
||||||
vlan = int(ipmi['802.1q VLAN ID']) if ipmi['802.1q VLAN ID'] != 'Disabled' else None
|
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(
|
interface = nb.dcim.interfaces.get(
|
||||||
device_id=self.device.id,
|
device_id=self.device.id,
|
||||||
|
|
|
||||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue