From ee41fb4fc26e9ccef1114d84cb96b64d29229937 Mon Sep 17 00:00:00 2001 From: clbu Date: Wed, 7 Aug 2024 12:24:49 +0200 Subject: [PATCH 1/8] replace device_role with role --- .gitignore | 1 + netbox_agent/cli.py | 4 ++-- netbox_agent/server.py | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index a95d78e..bc7b989 100644 --- a/.gitignore +++ b/.gitignore @@ -181,3 +181,4 @@ dmypy.json # End of https://www.gitignore.io/api/emacs,python netbox-docker +/.vscode diff --git a/netbox_agent/cli.py b/netbox_agent/cli.py index e112469..296317e 100644 --- a/netbox_agent/cli.py +++ b/netbox_agent/cli.py @@ -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 verison 3.7') return False if config.register or config.update_all or config.update_network or \ diff --git a/netbox_agent/server.py b/netbox_agent/server.py index c755a71..5077b7f 100644 --- a/netbox_agent/server.py +++ b/netbox_agent/server.py @@ -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, From a7104b6b944e69bfc72979e1783d26e6f9caf787 Mon Sep 17 00:00:00 2001 From: clbu Date: Wed, 7 Aug 2024 12:29:19 +0200 Subject: [PATCH 2/8] updating dependencies --- README.md | 2 +- requirements.txt | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 30b8240..f0e8473 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ The goal is to generate an existing infrastructure on Netbox and have the abilit # Requirements - Netbox >= 2.6 -- Python >= 3.4 +- Python >= 3.8 - [pynetbox](https://github.com/digitalocean/pynetbox/) - [python3-netaddr](https://github.com/drkjam/netaddr) - [python3-netifaces](https://github.com/al45tair/netifaces) diff --git a/requirements.txt b/requirements.txt index 10909f7..95e0ea2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,8 @@ -pynetbox==6.1.2 -netaddr==0.8.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 +pynetbox~=7.3.4 +netaddr~=1.3.0 +netifaces~=0.11.0 +pyyaml~=6.0.1 +jsonargparse~=4.32.0 +python-slugify~=8.0.4 +packaging~=23.2 +distro~=1.9.0 From 1d69f4e2f07364a28a273294ee0e0723a47430f9 Mon Sep 17 00:00:00 2001 From: clbu Date: Wed, 9 Oct 2024 15:12:39 +0200 Subject: [PATCH 3/8] python version compatible with dependencies --- .gitignore | 1 + README.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index bc7b989..b33172f 100644 --- a/.gitignore +++ b/.gitignore @@ -182,3 +182,4 @@ dmypy.json netbox-docker /.vscode +class_diagram/ diff --git a/README.md b/README.md index f0e8473..fce44ce 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ The goal is to generate an existing infrastructure on Netbox and have the abilit # Requirements - Netbox >= 2.6 -- Python >= 3.8 +- Python >= 3.7 - [pynetbox](https://github.com/digitalocean/pynetbox/) - [python3-netaddr](https://github.com/drkjam/netaddr) - [python3-netifaces](https://github.com/al45tair/netifaces) From 40af19e8017ba0d3ccbdbface3b2741afd86c17a Mon Sep 17 00:00:00 2001 From: clbu Date: Wed, 9 Oct 2024 15:32:25 +0200 Subject: [PATCH 4/8] fix(readme): required Netbox version --- .gitignore | 1 - README.md | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index b33172f..bc7b989 100644 --- a/.gitignore +++ b/.gitignore @@ -182,4 +182,3 @@ dmypy.json netbox-docker /.vscode -class_diagram/ diff --git a/README.md b/README.md index fce44ce..d9414bf 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ The goal is to generate an existing infrastructure on Netbox and have the abilit # Requirements -- Netbox >= 2.6 +- Netbox >= 3.7 - Python >= 3.7 - [pynetbox](https://github.com/digitalocean/pynetbox/) - [python3-netaddr](https://github.com/drkjam/netaddr) From 818c835711b14601a4909ecb08669b10dea05719 Mon Sep 17 00:00:00 2001 From: clbu Date: Wed, 9 Oct 2024 15:45:07 +0200 Subject: [PATCH 5/8] fix(requirements): update dependencies version --- requirements.txt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/requirements.txt b/requirements.txt index 95e0ea2..1d5cb4d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,8 @@ -pynetbox~=7.3.4 -netaddr~=1.3.0 -netifaces~=0.11.0 -pyyaml~=6.0.1 -jsonargparse~=4.32.0 -python-slugify~=8.0.4 -packaging~=23.2 -distro~=1.9.0 +pynetbox==7.3.4 +netaddr==1.3.0 +netifaces==0.11.0 +pyyaml==6.0.1 +jsonargparse==4.32.0 +python-slugify==8.0.4 +packaging==23.2 +distro==1.9.0 From 1429fedb9d892254c705e54cedcda7f41368ab65 Mon Sep 17 00:00:00 2001 From: clbu Date: Thu, 10 Oct 2024 23:15:55 +0200 Subject: [PATCH 6/8] fix(network): cable https://github.com/netbox-community/netbox/issues/9102 --- netbox_agent/network.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/netbox_agent/network.py b/netbox_agent/network.py index 673dfc1..ff1a8bf 100644 --- a/netbox_agent/network.py +++ b/netbox_agent/network.py @@ -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, From e44fd2fe78d3b00a7e7722a9ebd6f89abea90d27 Mon Sep 17 00:00:00 2001 From: clbu Date: Wed, 16 Oct 2024 10:44:08 +0200 Subject: [PATCH 7/8] fix(network): retrieve switch interface using id instead of name --- netbox_agent/network.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox_agent/network.py b/netbox_agent/network.py index ff1a8bf..41db084 100644 --- a/netbox_agent/network.py +++ b/netbox_agent/network.py @@ -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: From 4b54a0a3db9073a31c6b56f9db1322051d169536 Mon Sep 17 00:00:00 2001 From: CllaudiaB <112865371+CllaudiaB@users.noreply.github.com> Date: Thu, 17 Oct 2024 10:26:41 +0200 Subject: [PATCH 8/8] fix: typo Co-authored-by: n1nj4- <39305378+n1nj444@users.noreply.github.com> --- netbox_agent/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox_agent/cli.py b/netbox_agent/cli.py index 296317e..2d1de19 100644 --- a/netbox_agent/cli.py +++ b/netbox_agent/cli.py @@ -35,7 +35,7 @@ def run(config): server = GenericHost(dmi=dmi) if version.parse(nb.version) < version.parse('3.7'): - print('netbox-agent is not compatible with Netbox prior to verison 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 \