Test error handling for itf creation.
This commit is contained in:
parent
bc297ea337
commit
93b540f643
1 changed files with 48 additions and 47 deletions
|
|
@ -450,56 +450,57 @@ class Network(object):
|
||||||
)
|
)
|
||||||
interface = self.create_netbox_nic(nic)
|
interface = self.create_netbox_nic(nic)
|
||||||
|
|
||||||
nic_update = 0
|
if interface:
|
||||||
if nic['name'] != interface.name:
|
nic_update = 0
|
||||||
logging.info('Updating interface {interface} name to: {name}'.format(
|
if nic['name'] != interface.name:
|
||||||
interface=interface, name=nic['name']))
|
logging.info('Updating interface {interface} name to: {name}'.format(
|
||||||
interface.name = nic['name']
|
interface=interface, name=nic['name']))
|
||||||
nic_update += 1
|
interface.name = nic['name']
|
||||||
|
|
||||||
ret, interface = self.reset_vlan_on_interface(nic, interface)
|
|
||||||
nic_update += ret
|
|
||||||
|
|
||||||
if hasattr(interface, 'mtu'):
|
|
||||||
if nic['mtu'] != interface.mtu:
|
|
||||||
logging.info('Interface mtu is wrong, updating to: {mtu}'.format(
|
|
||||||
mtu=nic['mtu']))
|
|
||||||
interface.mtu = nic['mtu']
|
|
||||||
nic_update += 1
|
nic_update += 1
|
||||||
|
|
||||||
if hasattr(interface, 'type'):
|
ret, interface = self.reset_vlan_on_interface(nic, interface)
|
||||||
_type = self.get_netbox_type_for_nic(nic)
|
nic_update += ret
|
||||||
if not interface.type or \
|
|
||||||
_type != interface.type.value:
|
|
||||||
logging.info('Interface type is wrong, resetting')
|
|
||||||
interface.type = _type
|
|
||||||
nic_update += 1
|
|
||||||
|
|
||||||
if hasattr(interface, 'lag') and interface.lag is not None:
|
if hasattr(interface, 'mtu'):
|
||||||
local_lag_int = next(
|
if nic['mtu'] != interface.mtu:
|
||||||
item for item in self.nics if item['name'] == interface.lag.name
|
logging.info('Interface mtu is wrong, updating to: {mtu}'.format(
|
||||||
)
|
mtu=nic['mtu']))
|
||||||
if nic['name'] not in local_lag_int['bonding_slaves']:
|
interface.mtu = nic['mtu']
|
||||||
logging.info('Interface has no LAG, resetting')
|
nic_update += 1
|
||||||
nic_update += 1
|
|
||||||
interface.lag = None
|
|
||||||
|
|
||||||
# cable the interface
|
if hasattr(interface, 'type'):
|
||||||
if config.network.lldp:
|
_type = self.get_netbox_type_for_nic(nic)
|
||||||
switch_ip = self.lldp.get_switch_ip(interface.name)
|
if not interface.type or \
|
||||||
switch_interface = self.lldp.get_switch_port(interface.name)
|
_type != interface.type.value:
|
||||||
if switch_ip and switch_interface:
|
logging.info('Interface type is wrong, resetting')
|
||||||
ret, interface = self.create_or_update_cable(
|
interface.type = _type
|
||||||
switch_ip, switch_interface, interface
|
nic_update += 1
|
||||||
|
|
||||||
|
if hasattr(interface, 'lag') and interface.lag is not None:
|
||||||
|
local_lag_int = next(
|
||||||
|
item for item in self.nics if item['name'] == interface.lag.name
|
||||||
)
|
)
|
||||||
nic_update += ret
|
if nic['name'] not in local_lag_int['bonding_slaves']:
|
||||||
|
logging.info('Interface has no LAG, resetting')
|
||||||
|
nic_update += 1
|
||||||
|
interface.lag = None
|
||||||
|
|
||||||
if nic['ip']:
|
# cable the interface
|
||||||
# sync local IPs
|
if config.network.lldp:
|
||||||
for ip in nic['ip']:
|
switch_ip = self.lldp.get_switch_ip(interface.name)
|
||||||
self.create_or_update_netbox_ip_on_interface(ip, interface)
|
switch_interface = self.lldp.get_switch_port(interface.name)
|
||||||
if nic_update > 0:
|
if switch_ip and switch_interface:
|
||||||
interface.save()
|
ret, interface = self.create_or_update_cable(
|
||||||
|
switch_ip, switch_interface, interface
|
||||||
|
)
|
||||||
|
nic_update += ret
|
||||||
|
|
||||||
|
if nic['ip']:
|
||||||
|
# sync local IPs
|
||||||
|
for ip in nic['ip']:
|
||||||
|
self.create_or_update_netbox_ip_on_interface(ip, interface)
|
||||||
|
if nic_update > 0:
|
||||||
|
interface.save()
|
||||||
|
|
||||||
self._set_bonding_interfaces()
|
self._set_bonding_interfaces()
|
||||||
logging.debug('Finished updating NIC!')
|
logging.debug('Finished updating NIC!')
|
||||||
|
|
|
||||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue