associate slave device to bond device with Netbox LAG
This commit is contained in:
parent
6538493fd5
commit
f1a1e73aa3
1 changed files with 23 additions and 0 deletions
|
@ -47,6 +47,10 @@ class Network():
|
||||||
|
|
||||||
def scan(self):
|
def scan(self):
|
||||||
for interface in os.listdir('/sys/class/net/'):
|
for interface in os.listdir('/sys/class/net/'):
|
||||||
|
# ignore if it's not a link (ie: bonding_masters etc)
|
||||||
|
if not os.path.islink('/sys/class/net/{}'.format(interface)):
|
||||||
|
continue
|
||||||
|
|
||||||
if NETWORK_IGNORE_INTERFACES and \
|
if NETWORK_IGNORE_INTERFACES and \
|
||||||
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))
|
||||||
|
@ -80,6 +84,22 @@ class Network():
|
||||||
}
|
}
|
||||||
self.nics.append(nic)
|
self.nics.append(nic)
|
||||||
|
|
||||||
|
def _set_bonding_interfaces(self):
|
||||||
|
logging.debug('Setting bonding interfaces..')
|
||||||
|
for nic in [x for x in self.nics if x['bonding']]:
|
||||||
|
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)
|
||||||
|
logging.debug('Settting interface {name} as slave of {master}'.format(
|
||||||
|
name=slave_int.name, master=bond_int.name
|
||||||
|
))
|
||||||
|
slave_int.lag = bond_int
|
||||||
|
slave_int.save()
|
||||||
|
|
||||||
def get_network_cards(self):
|
def get_network_cards(self):
|
||||||
return self.nics
|
return self.nics
|
||||||
|
|
||||||
|
@ -158,6 +178,7 @@ class Network():
|
||||||
interface=new_interface.id,
|
interface=new_interface.id,
|
||||||
status=1,
|
status=1,
|
||||||
)
|
)
|
||||||
|
self._set_bonding_interfaces()
|
||||||
logging.debug('Finished creating NIC!')
|
logging.debug('Finished creating NIC!')
|
||||||
|
|
||||||
def update_netbox_network_cards(self):
|
def update_netbox_network_cards(self):
|
||||||
|
@ -231,4 +252,6 @@ class Network():
|
||||||
netbox_ip.save()
|
netbox_ip.save()
|
||||||
if nic_update:
|
if nic_update:
|
||||||
interface.save()
|
interface.save()
|
||||||
|
|
||||||
|
self._set_bonding_interfaces()
|
||||||
logging.debug('Finished updating NIC!')
|
logging.debug('Finished updating NIC!')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue