Check if it's a VM before running lldp related actions

This commit is contained in:
Grégoire Compagnon 2023-08-21 20:39:26 +02:00 committed by Tom Hubrecht
parent 6ef23eae4d
commit 9d496c6854
Signed by: thubrecht
SSH key fingerprint: SHA256:CYNvFo44Ar9qCNnWNnvJVhs0QXO9AZjOLlPeWcSij3Q

View file

@ -213,7 +213,7 @@ class Network(object):
def reset_vlan_on_interface(self, nic, interface): def reset_vlan_on_interface(self, nic, interface):
update = False update = False
vlan_id = nic['vlan'] vlan_id = nic['vlan']
lldp_vlan = self.lldp.get_switch_vlan(nic['name']) if config.network.lldp else None lldp_vlan = self.lldp.get_switch_vlan(nic['name']) if config.network.lldp and isinstance(self, ServerNetwork) else None
# For strange reason, we need to get the object from scratch # For strange reason, we need to get the object from scratch
# The object returned by pynetbox's save isn't always working (since pynetbox 6) # The object returned by pynetbox's save isn't always working (since pynetbox 6)
interface = self.nb_net.interfaces.get(id=interface.id) interface = self.nb_net.interfaces.get(id=interface.id)
@ -301,7 +301,7 @@ class Network(object):
interface.save() interface.save()
# cable the interface # cable the interface
if config.network.lldp: if config.network.lldp and isinstance(self, ServerNetwork):
switch_ip = self.lldp.get_switch_ip(interface.name) switch_ip = self.lldp.get_switch_ip(interface.name)
switch_interface = self.lldp.get_switch_port(interface.name) switch_interface = self.lldp.get_switch_port(interface.name)
@ -478,7 +478,7 @@ class Network(object):
interface.lag = None interface.lag = None
# cable the interface # cable the interface
if config.network.lldp: if config.network.lldp and isinstance(self, ServerNetwork):
switch_ip = self.lldp.get_switch_ip(interface.name) switch_ip = self.lldp.get_switch_ip(interface.name)
switch_interface = self.lldp.get_switch_port(interface.name) switch_interface = self.lldp.get_switch_port(interface.name)
if switch_ip and switch_interface: if switch_ip and switch_interface: