Merge pull request #305 from CllaudiaB/version

Support Netbox 3
This commit is contained in:
CllaudiaB 2024-10-17 10:37:09 +02:00 committed by GitHub
commit 514627aa72
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 23 additions and 20 deletions

1
.gitignore vendored
View file

@ -181,3 +181,4 @@ dmypy.json
# End of https://www.gitignore.io/api/emacs,python
netbox-docker
/.vscode

View file

@ -20,8 +20,8 @@ The goal is to generate an existing infrastructure on Netbox and have the abilit
# Requirements
- Netbox >= 2.6
- Python >= 3.4
- Netbox >= 3.7
- Python >= 3.7
- [pynetbox](https://github.com/digitalocean/pynetbox/)
- [python3-netaddr](https://github.com/drkjam/netaddr)
- [python3-netifaces](https://github.com/al45tair/netifaces)

View file

@ -34,8 +34,8 @@ def run(config):
except KeyError:
server = GenericHost(dmi=dmi)
if version.parse(nb.version) < version.parse('2.9'):
print('netbox-agent is not compatible with Netbox prior to verison 2.9')
if version.parse(nb.version) < version.parse('3.7'):
print('netbox-agent is not compatible with Netbox prior to version 3.7')
return False
if config.register or config.update_all or config.update_network or \

View file

@ -544,7 +544,7 @@ class ServerNetwork(Network):
switch_interface = self.lldp.get_switch_port(nb_server_interface.name)
nb_switch_interface = nb.dcim.interfaces.get(
device=nb_switch,
device_id=nb_switch.id,
name=switch_interface,
)
if nb_switch_interface is None:
@ -556,10 +556,12 @@ class ServerNetwork(Network):
switch_ip,
))
cable = nb.dcim.cables.create(
termination_a_id=nb_server_interface.id,
termination_a_type="dcim.interface",
termination_b_id=nb_switch_interface.id,
termination_b_type="dcim.interface",
a_terminations=[
{"object_type": "dcim.interface", "object_id": nb_server_interface.id},
],
b_terminations=[
{"object_type": "dcim.interface", "object_id": nb_switch_interface.id},
],
)
nb_server_interface.cable = cable
logging.info(
@ -579,7 +581,7 @@ class ServerNetwork(Network):
switch_ip, switch_interface, nb_server_interface
)
else:
nb_sw_int = nb_server_interface.cable.termination_b
nb_sw_int = nb_server_interface.cable.b_terminations[0]
nb_sw = nb_sw_int.device
nb_mgmt_int = nb.dcim.interfaces.get(
device_id=nb_sw.id,

View file

@ -199,7 +199,7 @@ class ServerBase():
name=self.get_chassis_name(),
device_type=device_type.id,
serial=serial,
device_role=device_role.id,
role=device_role.id,
site=datacenter.id if datacenter else None,
tenant=tenant.id if tenant else None,
rack=rack.id if rack else None,
@ -220,7 +220,7 @@ class ServerBase():
new_blade = nb.dcim.devices.create(
name=hostname,
serial=serial,
device_role=device_role.id,
role=device_role.id,
device_type=device_type.id,
parent_device=chassis.id,
site=datacenter.id if datacenter else None,
@ -243,7 +243,7 @@ class ServerBase():
new_blade = nb.dcim.devices.create(
name=hostname,
serial=serial,
device_role=device_role.id,
role=device_role.id,
device_type=device_type.id,
parent_device=chassis.id,
site=datacenter.id if datacenter else None,
@ -272,7 +272,7 @@ class ServerBase():
new_server = nb.dcim.devices.create(
name=hostname,
serial=serial,
device_role=device_role.id,
role=device_role.id,
device_type=device_type.id,
platform=self.device_platform.id,
site=datacenter.id if datacenter else None,

View file

@ -1,8 +1,8 @@
pynetbox==6.1.2
netaddr==0.8.0
pynetbox==7.3.4
netaddr==1.3.0
netifaces==0.11.0
pyyaml==6.0.1
jsonargparse==3.11.2
python-slugify==8.0.1
packaging==23.1
distro==1.8.0
jsonargparse==4.32.0
python-slugify==8.0.4
packaging==23.2
distro==1.9.0