This commit is contained in:
Grégoire Compagnon 2023-08-28 18:54:59 +02:00 committed by GitHub
commit 687c0127ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 12 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

@ -81,7 +81,7 @@ class Network(object):
#
for addr in ip6_addr:
addr["addr"] = addr["addr"].replace('%{}'.format(interface), '')
addr["netmask"] = addr["netmask"].split('/')[0]
addr["mask"] = addr["mask"].split('/')[0]
ip_addr.append(addr)
mac = open('/sys/class/net/{}/address'.format(interface), 'r').read().strip()
@ -109,7 +109,7 @@ class Network(object):
'ip': [
'{}/{}'.format(
x['addr'],
IPAddress(x['netmask']).netmask_bits()
IPAddress(x['mask']).netmask_bits()
) for x in ip_addr
] if ip_addr else None, # FIXME: handle IPv6 addresses
'ethtool': Ethtool(interface).parse(),
@ -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)
@ -473,7 +473,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):
@ -130,3 +131,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