Test error handling for itf creation.

This commit is contained in:
Pierre Lannoy 2025-08-18 18:33:23 +02:00
commit 74af9e31b6

View file

@ -291,37 +291,37 @@ class Network(object):
name=nic['name'], mac=nic['mac'], device=self.device.name
)
)
nic['vlan'] = None
if nic['vlan']:
nb_vlan = self.get_or_create_vlan(nic['vlan'])
interface.mode = self.dcim_choices['interface:mode']['Tagged']
interface.tagged_vlans = [nb_vlan.id]
interface.save()
elif config.network.lldp and self.lldp.get_switch_vlan(nic['name']) is not None:
# if lldp reports a vlan on an interface, tag the interface in access and set the vlan
# report only the interface which has `pvid=yes` (ie: lldp.eth3.vlan.pvid=yes)
# if pvid is not present, it'll be processed as a vlan tagged interface
vlans = self.lldp.get_switch_vlan(nic['name'])
for vid, vlan_infos in vlans.items():
nb_vlan = self.get_or_create_vlan(vid)
if vlan_infos.get('vid'):
interface.mode = self.dcim_choices['interface:mode']['Access']
interface.untagged_vlan = nb_vlan.id
interface.save()
if interface:
if nic['vlan']:
nb_vlan = self.get_or_create_vlan(nic['vlan'])
interface.mode = self.dcim_choices['interface:mode']['Tagged']
interface.tagged_vlans = [nb_vlan.id]
interface.save()
elif config.network.lldp and self.lldp.get_switch_vlan(nic['name']) is not None:
# if lldp reports a vlan on an interface, tag the interface in access and set the vlan
# report only the interface which has `pvid=yes` (ie: lldp.eth3.vlan.pvid=yes)
# if pvid is not present, it'll be processed as a vlan tagged interface
vlans = self.lldp.get_switch_vlan(nic['name'])
for vid, vlan_infos in vlans.items():
nb_vlan = self.get_or_create_vlan(vid)
if vlan_infos.get('vid'):
interface.mode = self.dcim_choices['interface:mode']['Access']
interface.untagged_vlan = nb_vlan.id
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)
# 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:
nic_update, interface = self.create_or_update_cable(
switch_ip, switch_interface, interface
)
if nic_update:
interface.save()
if switch_ip and switch_interface:
nic_update, interface = self.create_or_update_cable(
switch_ip, switch_interface, interface
)
if nic_update:
interface.save()
return interface
def create_or_update_netbox_ip_on_interface(self, ip, interface):