support netbox >=2.9 #177

Merged
Solvik merged 22 commits from 176-netbox-2.9 into master 2022-03-07 16:03:05 +01:00
3 changed files with 11 additions and 8 deletions
Showing only changes of commit 3639662961 - Show all commits

View file

@ -2,6 +2,7 @@ import socket
import subprocess
from shutil import which
from slugify import slugify
from netbox_agent.config import netbox_instance as nb
@ -67,5 +68,5 @@ def create_netbox_tags(tags):
if not nb_tag:
nb_tag = nb.extras.tags.create(
name=tag,
slug=tag,
slug=slugify(tag),
)

View file

@ -28,7 +28,7 @@ class ServerBase():
self.network = None
self.tags = list(set(config.device.tags.split(','))) if config.device.tags else []
self.tags = list(set([x.strip() for x in config.device.tags.split(',') if x.strip()])) if config.device.tags else []
if self.tags and len(self.tags):
create_netbox_tags(self.tags)
@ -177,7 +177,7 @@ class ServerBase():
site=datacenter.id if datacenter else None,
tenant=tenant.id if tenant else None,
rack=rack.id if rack else None,
tags=self.tags,
tags=[{'name': x} for x in self.tags],
)
return new_chassis
@ -199,7 +199,7 @@ class ServerBase():
site=datacenter.id if datacenter else None,
tenant=tenant.id if tenant else None,
rack=rack.id if rack else None,
tags=self.tags,
tags=[{'name': x} for x in self.tags],
)
return new_blade
@ -221,7 +221,7 @@ class ServerBase():
site=datacenter.id if datacenter else None,
tenant=tenant.id if tenant else None,
rack=rack.id if rack else None,
tags=self.tags,
tags=[{'name': x} for x in self.tags],
)
return new_blade
@ -242,7 +242,7 @@ class ServerBase():
site=datacenter.id if datacenter else None,
tenant=tenant.id if tenant else None,
rack=rack.id if rack else None,
tags=self.tags,
tags=[{'name': x} for x in self.tags],
)
return new_server
@ -383,9 +383,11 @@ class ServerBase():
update += 1
server.name = self.get_hostname()
if sorted(set(server.tags)) != sorted(set(self.tags)):
if float(nb.version) < 2.8 and sorted(set(server.tags)) != sorted(set(self.tags)):
server.tags = self.tags
update += 1
else:
logging.warning("netbox-agent doesn't support tag updates for Netbox version >=2.8")
if config.update_all or config.update_location:
ret, server = self.update_netbox_location(server)

View file

@ -14,7 +14,7 @@ setup(
packages=find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]),
use_scm_version=True,
install_requires=[
'pynetbox==5.0.5',
'pynetbox==5.1.0',
'netaddr==0.8.0',
'netifaces==0.10.9',
'pyyaml==5.4.1',