Merge pull request 'Virtualmachine corrections' (#279) from obeone/virtualmachine_corrections into master

Reviewed-on: #279
This commit is contained in:
thubrecht 2024-10-21 12:32:30 +02:00
commit c1a7f661a3
3 changed files with 16 additions and 4 deletions

View file

@ -47,7 +47,7 @@ def run(config):
def main():
return run(config)
return 0 if run(config) else 1
if __name__ == '__main__':

View file

@ -213,7 +213,7 @@ class Network(object):
def reset_vlan_on_interface(self, nic, interface):
update = False
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
# The object returned by pynetbox's save isn't always working (since pynetbox 6)
interface = self.nb_net.interfaces.get(id=interface.id)
@ -301,7 +301,7 @@ class Network(object):
interface.save()
# 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_interface = self.lldp.get_switch_port(interface.name)
@ -478,7 +478,7 @@ class Network(object):
interface.lag = None
# 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_interface = self.lldp.get_switch_port(interface.name)
if switch_ip and switch_interface:

View file

@ -7,6 +7,7 @@ from netbox_agent.location import Tenant
from netbox_agent.logging import logging # NOQA
from netbox_agent.misc import create_netbox_tags, get_hostname, get_device_platform
from netbox_agent.network import VirtualNetwork
from pprint import pprint
def is_vm(dmi):
@ -138,3 +139,14 @@ class VirtualMachine(object):
if updated:
vm.save()
def print_debug(self):
self.network = VirtualNetwork(server=self)
print('Cluster:', self.get_netbox_cluster(config.virtual.cluster_name))
print('Platform:', self.device_platform)
print('VM:', self.get_netbox_vm())
print('vCPU:', self.get_vcpus())
print('Memory:', f"{self.get_memory()} MB")
print('NIC:',)
pprint(self.network.get_network_cards())
pass