Support Netbox 3 #305
6 changed files with 23 additions and 20 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -181,3 +181,4 @@ dmypy.json
|
||||||
# End of https://www.gitignore.io/api/emacs,python
|
# End of https://www.gitignore.io/api/emacs,python
|
||||||
|
|
||||||
netbox-docker
|
netbox-docker
|
||||||
|
/.vscode
|
||||||
|
|
|
@ -20,8 +20,8 @@ The goal is to generate an existing infrastructure on Netbox and have the abilit
|
||||||
|
|
||||||
# Requirements
|
# Requirements
|
||||||
|
|
||||||
- Netbox >= 2.6
|
- Netbox >= 3.7
|
||||||
- Python >= 3.4
|
- Python >= 3.7
|
||||||
- [pynetbox](https://github.com/digitalocean/pynetbox/)
|
- [pynetbox](https://github.com/digitalocean/pynetbox/)
|
||||||
- [python3-netaddr](https://github.com/drkjam/netaddr)
|
- [python3-netaddr](https://github.com/drkjam/netaddr)
|
||||||
- [python3-netifaces](https://github.com/al45tair/netifaces)
|
- [python3-netifaces](https://github.com/al45tair/netifaces)
|
||||||
|
|
|
@ -34,8 +34,8 @@ def run(config):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
server = GenericHost(dmi=dmi)
|
server = GenericHost(dmi=dmi)
|
||||||
|
|
||||||
if version.parse(nb.version) < version.parse('2.9'):
|
if version.parse(nb.version) < version.parse('3.7'):
|
||||||
print('netbox-agent is not compatible with Netbox prior to verison 2.9')
|
print('netbox-agent is not compatible with Netbox prior to version 3.7')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if config.register or config.update_all or config.update_network or \
|
if config.register or config.update_all or config.update_network or \
|
||||||
|
|
|
@ -544,7 +544,7 @@ class ServerNetwork(Network):
|
||||||
|
|
||||||
switch_interface = self.lldp.get_switch_port(nb_server_interface.name)
|
switch_interface = self.lldp.get_switch_port(nb_server_interface.name)
|
||||||
nb_switch_interface = nb.dcim.interfaces.get(
|
nb_switch_interface = nb.dcim.interfaces.get(
|
||||||
device=nb_switch,
|
device_id=nb_switch.id,
|
||||||
name=switch_interface,
|
name=switch_interface,
|
||||||
)
|
)
|
||||||
if nb_switch_interface is None:
|
if nb_switch_interface is None:
|
||||||
|
@ -556,10 +556,12 @@ class ServerNetwork(Network):
|
||||||
switch_ip,
|
switch_ip,
|
||||||
))
|
))
|
||||||
cable = nb.dcim.cables.create(
|
cable = nb.dcim.cables.create(
|
||||||
termination_a_id=nb_server_interface.id,
|
a_terminations=[
|
||||||
termination_a_type="dcim.interface",
|
{"object_type": "dcim.interface", "object_id": nb_server_interface.id},
|
||||||
termination_b_id=nb_switch_interface.id,
|
],
|
||||||
termination_b_type="dcim.interface",
|
b_terminations=[
|
||||||
|
{"object_type": "dcim.interface", "object_id": nb_switch_interface.id},
|
||||||
|
],
|
||||||
)
|
)
|
||||||
nb_server_interface.cable = cable
|
nb_server_interface.cable = cable
|
||||||
logging.info(
|
logging.info(
|
||||||
|
@ -579,7 +581,7 @@ class ServerNetwork(Network):
|
||||||
switch_ip, switch_interface, nb_server_interface
|
switch_ip, switch_interface, nb_server_interface
|
||||||
)
|
)
|
||||||
else:
|
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_sw = nb_sw_int.device
|
||||||
nb_mgmt_int = nb.dcim.interfaces.get(
|
nb_mgmt_int = nb.dcim.interfaces.get(
|
||||||
device_id=nb_sw.id,
|
device_id=nb_sw.id,
|
||||||
|
|
|
@ -199,7 +199,7 @@ class ServerBase():
|
||||||
name=self.get_chassis_name(),
|
name=self.get_chassis_name(),
|
||||||
device_type=device_type.id,
|
device_type=device_type.id,
|
||||||
serial=serial,
|
serial=serial,
|
||||||
device_role=device_role.id,
|
role=device_role.id,
|
||||||
site=datacenter.id if datacenter else None,
|
site=datacenter.id if datacenter else None,
|
||||||
tenant=tenant.id if tenant else None,
|
tenant=tenant.id if tenant else None,
|
||||||
rack=rack.id if rack else None,
|
rack=rack.id if rack else None,
|
||||||
|
@ -220,7 +220,7 @@ class ServerBase():
|
||||||
new_blade = nb.dcim.devices.create(
|
new_blade = nb.dcim.devices.create(
|
||||||
name=hostname,
|
name=hostname,
|
||||||
serial=serial,
|
serial=serial,
|
||||||
device_role=device_role.id,
|
role=device_role.id,
|
||||||
device_type=device_type.id,
|
device_type=device_type.id,
|
||||||
parent_device=chassis.id,
|
parent_device=chassis.id,
|
||||||
site=datacenter.id if datacenter else None,
|
site=datacenter.id if datacenter else None,
|
||||||
|
@ -243,7 +243,7 @@ class ServerBase():
|
||||||
new_blade = nb.dcim.devices.create(
|
new_blade = nb.dcim.devices.create(
|
||||||
name=hostname,
|
name=hostname,
|
||||||
serial=serial,
|
serial=serial,
|
||||||
device_role=device_role.id,
|
role=device_role.id,
|
||||||
device_type=device_type.id,
|
device_type=device_type.id,
|
||||||
parent_device=chassis.id,
|
parent_device=chassis.id,
|
||||||
site=datacenter.id if datacenter else None,
|
site=datacenter.id if datacenter else None,
|
||||||
|
@ -272,7 +272,7 @@ class ServerBase():
|
||||||
new_server = nb.dcim.devices.create(
|
new_server = nb.dcim.devices.create(
|
||||||
name=hostname,
|
name=hostname,
|
||||||
serial=serial,
|
serial=serial,
|
||||||
device_role=device_role.id,
|
role=device_role.id,
|
||||||
device_type=device_type.id,
|
device_type=device_type.id,
|
||||||
platform=self.device_platform.id,
|
platform=self.device_platform.id,
|
||||||
site=datacenter.id if datacenter else None,
|
site=datacenter.id if datacenter else None,
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
pynetbox==6.1.2
|
pynetbox==7.3.4
|
||||||
netaddr==0.8.0
|
netaddr==1.3.0
|
||||||
netifaces==0.11.0
|
netifaces==0.11.0
|
||||||
pyyaml==6.0.1
|
pyyaml==6.0.1
|
||||||
jsonargparse==3.11.2
|
jsonargparse==4.32.0
|
||||||
python-slugify==8.0.1
|
python-slugify==8.0.4
|
||||||
packaging==23.1
|
packaging==23.2
|
||||||
distro==1.8.0
|
distro==1.9.0
|
||||||
|
|
Loading…
Add table
Reference in a new issue