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)
|
||||
|
||||
nic_update = 0
|
||||
if nic['name'] != interface.name:
|
||||
logging.info('Updating interface {interface} name to: {name}'.format(
|
||||
interface=interface, name=nic['name']))
|
||||
interface.name = nic['name']
|
||||
nic_update += 1
|
||||
|
||||
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']
|
||||
if interface:
|
||||
nic_update = 0
|
||||
if nic['name'] != interface.name:
|
||||
logging.info('Updating interface {interface} name to: {name}'.format(
|
||||
interface=interface, name=nic['name']))
|
||||
interface.name = nic['name']
|
||||
nic_update += 1
|
||||
|
||||
if hasattr(interface, 'type'):
|
||||
_type = self.get_netbox_type_for_nic(nic)
|
||||
if not interface.type or \
|
||||
_type != interface.type.value:
|
||||
logging.info('Interface type is wrong, resetting')
|
||||
interface.type = _type
|
||||
nic_update += 1
|
||||
ret, interface = self.reset_vlan_on_interface(nic, interface)
|
||||
nic_update += ret
|
||||
|
||||
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
|
||||
)
|
||||
if nic['name'] not in local_lag_int['bonding_slaves']:
|
||||
logging.info('Interface has no LAG, resetting')
|
||||
nic_update += 1
|
||||
interface.lag = None
|
||||
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
|
||||
|
||||
# cable the interface
|
||||
if config.network.lldp:
|
||||
switch_ip = self.lldp.get_switch_ip(interface.name)
|
||||
switch_interface = self.lldp.get_switch_port(interface.name)
|
||||
if switch_ip and switch_interface:
|
||||
ret, interface = self.create_or_update_cable(
|
||||
switch_ip, switch_interface, interface
|
||||
if hasattr(interface, 'type'):
|
||||
_type = self.get_netbox_type_for_nic(nic)
|
||||
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:
|
||||
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']:
|
||||
# sync local IPs
|
||||
for ip in nic['ip']:
|
||||
self.create_or_update_netbox_ip_on_interface(ip, interface)
|
||||
if nic_update > 0:
|
||||
interface.save()
|
||||
# cable the interface
|
||||
if config.network.lldp:
|
||||
switch_ip = self.lldp.get_switch_ip(interface.name)
|
||||
switch_interface = self.lldp.get_switch_port(interface.name)
|
||||
if switch_ip and switch_interface:
|
||||
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()
|
||||
logging.debug('Finished updating NIC!')
|
||||
|
|
|
|||
Loading…
Add table
editor.link_modal.header
Reference in a new issue