Skip to content

Commit

Permalink
Merge pull request #305 from CllaudiaB/version
Browse files Browse the repository at this point in the history
Support Netbox 3
  • Loading branch information
CllaudiaB authored Oct 17, 2024
2 parents ba4cdb2 + 4b54a0a commit 514627a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,4 @@ dmypy.json
# End of https://www.gitignore.io/api/emacs,python

netbox-docker
/.vscode
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions netbox_agent/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
14 changes: 8 additions & 6 deletions netbox_agent/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ def connect_interface_to_switch(self, switch_ip, switch_interface, nb_server_int

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:
Expand All @@ -556,10 +556,12 @@ def connect_interface_to_switch(self, switch_ip, switch_interface, nb_server_int
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(
Expand All @@ -579,7 +581,7 @@ def create_or_update_cable(self, switch_ip, switch_interface, nb_server_interfac
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,
Expand Down
8 changes: 4 additions & 4 deletions netbox_agent/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def _netbox_create_chassis(self, datacenter, tenant, rack):
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,
Expand All @@ -220,7 +220,7 @@ def _netbox_create_blade(self, chassis, datacenter, tenant, rack):
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,
Expand All @@ -243,7 +243,7 @@ def _netbox_create_blade_expansion(self, chassis, datacenter, tenant, rack):
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,
Expand Down Expand Up @@ -272,7 +272,7 @@ def _netbox_create_server(self, datacenter, tenant, rack):
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,
Expand Down
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 514627a

Please sign in to comment.