From 242ff16b72cb7d66b92f69312c689e3ca058266c Mon Sep 17 00:00:00 2001 From: chatasos <47942984+chatasos@users.noreply.github.com> Date: Thu, 3 Oct 2024 10:54:28 +0300 Subject: [PATCH 1/8] Update netbox_api.py for netbox 4.1.0 devicetype_id => device_type_id moduletype_id => module_type_id https://github.com/netbox-community/Device-Type-Library-Import/issues/152#issuecomment-2364058900 https://github.com/netbox-community/netbox/issues/15410 --- netbox_api.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/netbox_api.py b/netbox_api.py index f848d492..112be9a7 100644 --- a/netbox_api.py +++ b/netbox_api.py @@ -194,16 +194,16 @@ def get_device_types(self): return {str(item): item for item in self.netbox.dcim.device_types.all()} def get_power_ports(self, device_type): - return {str(item): item for item in self.netbox.dcim.power_port_templates.filter(devicetype_id=device_type)} + return {str(item): item for item in self.netbox.dcim.power_port_templates.filter(device_type_id=device_type)} def get_rear_ports(self, device_type): - return {str(item): item for item in self.netbox.dcim.rear_port_templates.filter(devicetype_id=device_type)} + return {str(item): item for item in self.netbox.dcim.rear_port_templates.filter(device_type_id=device_type)} def get_module_power_ports(self, module_type): - return {str(item): item for item in self.netbox.dcim.power_port_templates.filter(moduletype_id=module_type)} + return {str(item): item for item in self.netbox.dcim.power_port_templates.filter(module_type_id=module_type)} def get_module_rear_ports(self, module_type): - return {str(item): item for item in self.netbox.dcim.rear_port_templates.filter(moduletype_id=module_type)} + return {str(item): item for item in self.netbox.dcim.rear_port_templates.filter(module_type_id=module_type)} def get_device_type_ports_to_create(self, dcim_ports, device_type, existing_ports): to_create = [port for port in dcim_ports if port['name'] not in existing_ports] @@ -221,7 +221,7 @@ def get_module_type_ports_to_create(self, module_ports, module_type, existing_po def create_interfaces(self, interfaces, device_type): existing_interfaces = {str(item): item for item in self.netbox.dcim.interface_templates.filter( - devicetype_id=device_type)} + device_type_id=device_type)} to_create = self.get_device_type_ports_to_create( interfaces, device_type, existing_interfaces) @@ -248,7 +248,7 @@ def create_power_ports(self, power_ports, device_type): self.handle.log(f"Error '{excep.error}' creating Power Port") def create_console_ports(self, console_ports, device_type): - existing_console_ports = {str(item): item for item in self.netbox.dcim.console_port_templates.filter(devicetype_id=device_type)} + existing_console_ports = {str(item): item for item in self.netbox.dcim.console_port_templates.filter(device_type_id=device_type)} to_create = self.get_device_type_ports_to_create(console_ports, device_type, existing_console_ports) if to_create: @@ -261,7 +261,7 @@ def create_console_ports(self, console_ports, device_type): self.handle.log(f"Error '{excep.error}' creating Console Port") def create_power_outlets(self, power_outlets, device_type): - existing_power_outlets = {str(item): item for item in self.netbox.dcim.power_outlet_templates.filter(devicetype_id=device_type)} + existing_power_outlets = {str(item): item for item in self.netbox.dcim.power_outlet_templates.filter(device_type_id=device_type)} to_create = self.get_device_type_ports_to_create(power_outlets, device_type, existing_power_outlets) if to_create: @@ -282,7 +282,7 @@ def create_power_outlets(self, power_outlets, device_type): self.handle.log(f"Error '{excep.error}' creating Power Outlet") def create_console_server_ports(self, console_server_ports, device_type): - existing_console_server_ports = {str(item): item for item in self.netbox.dcim.console_server_port_templates.filter(devicetype_id=device_type)} + existing_console_server_ports = {str(item): item for item in self.netbox.dcim.console_server_port_templates.filter(device_type_id=device_type)} to_create = self.get_device_type_ports_to_create(console_server_ports, device_type, existing_console_server_ports) if to_create: @@ -308,7 +308,7 @@ def create_rear_ports(self, rear_ports, device_type): self.handle.log(f"Error '{excep.error}' creating Rear Port") def create_front_ports(self, front_ports, device_type): - existing_front_ports = {str(item): item for item in self.netbox.dcim.front_port_templates.filter(devicetype_id=device_type)} + existing_front_ports = {str(item): item for item in self.netbox.dcim.front_port_templates.filter(device_type_id=device_type)} to_create = self.get_device_type_ports_to_create(front_ports, device_type, existing_front_ports) if to_create: @@ -330,7 +330,7 @@ def create_front_ports(self, front_ports, device_type): self.handle.log(f"Error '{excep.error}' creating Front Port") def create_device_bays(self, device_bays, device_type): - existing_device_bays = {str(item): item for item in self.netbox.dcim.device_bay_templates.filter(devicetype_id=device_type)} + existing_device_bays = {str(item): item for item in self.netbox.dcim.device_bay_templates.filter(device_type_id=device_type)} to_create = self.get_device_type_ports_to_create(device_bays, device_type, existing_device_bays) if to_create: @@ -343,7 +343,7 @@ def create_device_bays(self, device_bays, device_type): self.handle.log(f"Error '{excep.error}' creating Device Bay") def create_module_bays(self, module_bays, device_type): - existing_module_bays = {str(item): item for item in self.netbox.dcim.module_bay_templates.filter(devicetype_id=device_type)} + existing_module_bays = {str(item): item for item in self.netbox.dcim.module_bay_templates.filter(device_type_id=device_type)} to_create = self.get_device_type_ports_to_create(module_bays, device_type, existing_module_bays) if to_create: @@ -356,7 +356,7 @@ def create_module_bays(self, module_bays, device_type): self.handle.log(f"Error '{excep.error}' creating Module Bay") def create_module_interfaces(self, module_interfaces, module_type): - existing_interfaces = {str(item): item for item in self.netbox.dcim.interface_templates.filter(moduletype_id=module_type)} + existing_interfaces = {str(item): item for item in self.netbox.dcim.interface_templates.filter(module_type_id=module_type)} to_create = self.get_module_type_ports_to_create(module_interfaces, module_type, existing_interfaces) if to_create: @@ -382,7 +382,7 @@ def create_module_power_ports(self, power_ports, module_type): self.handle.log(f"Error '{excep.error}' creating Module Power Port") def create_module_console_ports(self, console_ports, module_type): - existing_console_ports = {str(item): item for item in self.netbox.dcim.console_port_templates.filter(moduletype_id=module_type)} + existing_console_ports = {str(item): item for item in self.netbox.dcim.console_port_templates.filter(module_type_id=module_type)} to_create = self.get_module_type_ports_to_create(console_ports, module_type, existing_console_ports) if to_create: @@ -395,7 +395,7 @@ def create_module_console_ports(self, console_ports, module_type): self.handle.log(f"Error '{excep.error}' creating Module Console Port") def create_module_power_outlets(self, power_outlets, module_type): - existing_power_outlets = {str(item): item for item in self.netbox.dcim.power_outlet_templates.filter(moduletype_id=module_type)} + existing_power_outlets = {str(item): item for item in self.netbox.dcim.power_outlet_templates.filter(module_type_id=module_type)} to_create = self.get_module_type_ports_to_create(power_outlets, module_type, existing_power_outlets) if to_create: @@ -416,7 +416,7 @@ def create_module_power_outlets(self, power_outlets, module_type): self.handle.log(f"Error '{excep.error}' creating Module Power Outlet") def create_module_console_server_ports(self, console_server_ports, module_type): - existing_console_server_ports = {str(item): item for item in self.netbox.dcim.console_server_port_templates.filter(moduletype_id=module_type)} + existing_console_server_ports = {str(item): item for item in self.netbox.dcim.console_server_port_templates.filter(module_type_id=module_type)} to_create = self.get_module_type_ports_to_create(console_server_ports, module_type, existing_console_server_ports) if to_create: @@ -442,7 +442,7 @@ def create_module_rear_ports(self, rear_ports, module_type): self.handle.log(f"Error '{excep.error}' creating Module Rear Port") def create_module_front_ports(self, front_ports, module_type): - existing_front_ports = {str(item): item for item in self.netbox.dcim.front_port_templates.filter(moduletype_id=module_type)} + existing_front_ports = {str(item): item for item in self.netbox.dcim.front_port_templates.filter(module_type_id=module_type)} to_create = self.get_module_type_ports_to_create(front_ports, module_type, existing_front_ports) if to_create: From 45bd1348aec753b93f69dafc98ccd7f05d5b14a7 Mon Sep 17 00:00:00 2001 From: chatasos <47942984+chatasos@users.noreply.github.com> Date: Thu, 3 Oct 2024 11:05:04 +0300 Subject: [PATCH 2/8] Update requirements.txt --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 30ac661c..9e8a6471 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ GitPython==3.1.32 -pynetbox==7.0.1 +pynetbox==7.4.0 python-dotenv==1.0.0 -PyYAML==6.0.1 \ No newline at end of file +PyYAML==6.0.1 From 10e2018a847b80774a32f42e098cacd8f1c7ff02 Mon Sep 17 00:00:00 2001 From: chatasos <47942984+chatasos@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:05:38 +0300 Subject: [PATCH 3/8] Update netbox_api.py for netbox 4.1.0 change filter names if netbox version >=4.1 --- netbox_api.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/netbox_api.py b/netbox_api.py index 112be9a7..3f88a741 100644 --- a/netbox_api.py +++ b/netbox_api.py @@ -24,6 +24,7 @@ def __init__(self, settings): self.netbox = None self.ignore_ssl = settings.IGNORE_SSL_ERRORS self.modules = False + self.new_filters = False self.connect_api() self.verify_compatibility() self.existing_manufacturers = self.get_manufacturers() @@ -54,6 +55,10 @@ def verify_compatibility(self): if version_split[0] > 3 or (version_split[0] == 3 and version_split[1] >= 2): self.modules = True + # check if version >= 4.1 in order to use new filter names + if version_split[0] >= 4 and version_split[1] >= 1: + self.new_filters = True + def get_manufacturers(self): return {str(item): item for item in self.netbox.dcim.manufacturers.all()} @@ -194,10 +199,10 @@ def get_device_types(self): return {str(item): item for item in self.netbox.dcim.device_types.all()} def get_power_ports(self, device_type): - return {str(item): item for item in self.netbox.dcim.power_port_templates.filter(device_type_id=device_type)} - + return {str(item): item for item in self.netbox.dcim.power_port_templates.filter(**{'device_type_id' if self.newfilters else 'devicetype_id': device_type})} + def get_rear_ports(self, device_type): - return {str(item): item for item in self.netbox.dcim.rear_port_templates.filter(device_type_id=device_type)} + return {str(item): item for item in self.netbox.dcim.rear_port_templates.filter(**{'device_type_id' if self.newfilters else 'devicetype_id': device_type})} def get_module_power_ports(self, module_type): return {str(item): item for item in self.netbox.dcim.power_port_templates.filter(module_type_id=module_type)} @@ -221,7 +226,7 @@ def get_module_type_ports_to_create(self, module_ports, module_type, existing_po def create_interfaces(self, interfaces, device_type): existing_interfaces = {str(item): item for item in self.netbox.dcim.interface_templates.filter( - device_type_id=device_type)} + **{'device_type_id' if self.newfilters else 'devicetype_id': device_type})} to_create = self.get_device_type_ports_to_create( interfaces, device_type, existing_interfaces) @@ -248,7 +253,7 @@ def create_power_ports(self, power_ports, device_type): self.handle.log(f"Error '{excep.error}' creating Power Port") def create_console_ports(self, console_ports, device_type): - existing_console_ports = {str(item): item for item in self.netbox.dcim.console_port_templates.filter(device_type_id=device_type)} + existing_console_ports = {str(item): item for item in self.netbox.dcim.console_port_templates.filter(**{'device_type_id' if self.newfilters else 'devicetype_id': device_type})} to_create = self.get_device_type_ports_to_create(console_ports, device_type, existing_console_ports) if to_create: @@ -261,7 +266,7 @@ def create_console_ports(self, console_ports, device_type): self.handle.log(f"Error '{excep.error}' creating Console Port") def create_power_outlets(self, power_outlets, device_type): - existing_power_outlets = {str(item): item for item in self.netbox.dcim.power_outlet_templates.filter(device_type_id=device_type)} + existing_power_outlets = {str(item): item for item in self.netbox.dcim.power_outlet_templates.filter(**{'device_type_id' if self.newfilters else 'devicetype_id': device_type})} to_create = self.get_device_type_ports_to_create(power_outlets, device_type, existing_power_outlets) if to_create: @@ -282,7 +287,7 @@ def create_power_outlets(self, power_outlets, device_type): self.handle.log(f"Error '{excep.error}' creating Power Outlet") def create_console_server_ports(self, console_server_ports, device_type): - existing_console_server_ports = {str(item): item for item in self.netbox.dcim.console_server_port_templates.filter(device_type_id=device_type)} + existing_console_server_ports = {str(item): item for item in self.netbox.dcim.console_server_port_templates.filter(**{'device_type_id' if self.newfilters else 'devicetype_id': device_type})} to_create = self.get_device_type_ports_to_create(console_server_ports, device_type, existing_console_server_ports) if to_create: @@ -308,7 +313,7 @@ def create_rear_ports(self, rear_ports, device_type): self.handle.log(f"Error '{excep.error}' creating Rear Port") def create_front_ports(self, front_ports, device_type): - existing_front_ports = {str(item): item for item in self.netbox.dcim.front_port_templates.filter(device_type_id=device_type)} + existing_front_ports = {str(item): item for item in self.netbox.dcim.front_port_templates.filter(**{'device_type_id' if self.newfilters else 'devicetype_id': device_type})} to_create = self.get_device_type_ports_to_create(front_ports, device_type, existing_front_ports) if to_create: @@ -330,7 +335,7 @@ def create_front_ports(self, front_ports, device_type): self.handle.log(f"Error '{excep.error}' creating Front Port") def create_device_bays(self, device_bays, device_type): - existing_device_bays = {str(item): item for item in self.netbox.dcim.device_bay_templates.filter(device_type_id=device_type)} + existing_device_bays = {str(item): item for item in self.netbox.dcim.device_bay_templates.filter(**{'device_type_id' if self.newfilters else 'devicetype_id': device_type})} to_create = self.get_device_type_ports_to_create(device_bays, device_type, existing_device_bays) if to_create: @@ -343,7 +348,7 @@ def create_device_bays(self, device_bays, device_type): self.handle.log(f"Error '{excep.error}' creating Device Bay") def create_module_bays(self, module_bays, device_type): - existing_module_bays = {str(item): item for item in self.netbox.dcim.module_bay_templates.filter(device_type_id=device_type)} + existing_module_bays = {str(item): item for item in self.netbox.dcim.module_bay_templates.filter(**{'device_type_id' if self.newfilters else 'devicetype_id': device_type})} to_create = self.get_device_type_ports_to_create(module_bays, device_type, existing_module_bays) if to_create: From 1e1524e1515bb178f206a7d354bbdf15309d9dc0 Mon Sep 17 00:00:00 2001 From: chatasos <47942984+chatasos@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:11:46 +0300 Subject: [PATCH 4/8] Update netbox_api.py for netbox 4.1.0 print the version number --- netbox_api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/netbox_api.py b/netbox_api.py index 3f88a741..442c507c 100644 --- a/netbox_api.py +++ b/netbox_api.py @@ -58,6 +58,7 @@ def verify_compatibility(self): # check if version >= 4.1 in order to use new filter names if version_split[0] >= 4 and version_split[1] >= 1: self.new_filters = True + self.handle.log(f'Netbox version {self.netbox.version} found. Using new filters.') def get_manufacturers(self): return {str(item): item for item in self.netbox.dcim.manufacturers.all()} From 5a198a4ddda0ed179a9bd3ee9e4f562814846a96 Mon Sep 17 00:00:00 2001 From: chatasos <47942984+chatasos@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:12:48 +0300 Subject: [PATCH 5/8] Update netbox_api.py --- netbox_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox_api.py b/netbox_api.py index 442c507c..1e0dbc91 100644 --- a/netbox_api.py +++ b/netbox_api.py @@ -55,7 +55,7 @@ def verify_compatibility(self): if version_split[0] > 3 or (version_split[0] == 3 and version_split[1] >= 2): self.modules = True - # check if version >= 4.1 in order to use new filter names + # check if version >= 4.1 in order to use new filter names (https://github.com/netbox-community/netbox/issues/15410) if version_split[0] >= 4 and version_split[1] >= 1: self.new_filters = True self.handle.log(f'Netbox version {self.netbox.version} found. Using new filters.') From 28e9fb060f3ea1c8740b992f2005f3b53ad454b1 Mon Sep 17 00:00:00 2001 From: chatasos <47942984+chatasos@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:27:11 +0300 Subject: [PATCH 6/8] Update netbox_api.py --- netbox_api.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/netbox_api.py b/netbox_api.py index 1e0dbc91..cac755c1 100644 --- a/netbox_api.py +++ b/netbox_api.py @@ -28,7 +28,7 @@ def __init__(self, settings): self.connect_api() self.verify_compatibility() self.existing_manufacturers = self.get_manufacturers() - self.device_types = DeviceTypes(self.netbox, self.handle, self.counter, self.ignore_ssl) + self.device_types = DeviceTypes(self.netbox, self.handle, self.counter, self.ignore_ssl, self.new_filters) def connect_api(self): try: @@ -189,12 +189,13 @@ class DeviceTypes: def __new__(cls, *args, **kwargs): return super().__new__(cls) - def __init__(self, netbox, handle, counter, ignore_ssl): + def __init__(self, netbox, handle, counter, ignore_ssl, new_filters): self.netbox = netbox self.handle = handle self.counter = counter self.existing_device_types = self.get_device_types() self.ignore_ssl = ignore_ssl + self.new_filters = new_filters def get_device_types(self): return {str(item): item for item in self.netbox.dcim.device_types.all()} From 48d70848651d8bb62bcf858fbe4a68173bf51377 Mon Sep 17 00:00:00 2001 From: chatasos <47942984+chatasos@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:29:08 +0300 Subject: [PATCH 7/8] Update netbox_api.py --- netbox_api.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/netbox_api.py b/netbox_api.py index cac755c1..fb6bc5d8 100644 --- a/netbox_api.py +++ b/netbox_api.py @@ -201,10 +201,10 @@ def get_device_types(self): return {str(item): item for item in self.netbox.dcim.device_types.all()} def get_power_ports(self, device_type): - return {str(item): item for item in self.netbox.dcim.power_port_templates.filter(**{'device_type_id' if self.newfilters else 'devicetype_id': device_type})} + return {str(item): item for item in self.netbox.dcim.power_port_templates.filter(**{'device_type_id' if self.new_filters else 'devicetype_id': device_type})} def get_rear_ports(self, device_type): - return {str(item): item for item in self.netbox.dcim.rear_port_templates.filter(**{'device_type_id' if self.newfilters else 'devicetype_id': device_type})} + return {str(item): item for item in self.netbox.dcim.rear_port_templates.filter(**{'device_type_id' if self.new_filters else 'devicetype_id': device_type})} def get_module_power_ports(self, module_type): return {str(item): item for item in self.netbox.dcim.power_port_templates.filter(module_type_id=module_type)} @@ -228,7 +228,7 @@ def get_module_type_ports_to_create(self, module_ports, module_type, existing_po def create_interfaces(self, interfaces, device_type): existing_interfaces = {str(item): item for item in self.netbox.dcim.interface_templates.filter( - **{'device_type_id' if self.newfilters else 'devicetype_id': device_type})} + **{'device_type_id' if self.new_filters else 'devicetype_id': device_type})} to_create = self.get_device_type_ports_to_create( interfaces, device_type, existing_interfaces) @@ -255,7 +255,7 @@ def create_power_ports(self, power_ports, device_type): self.handle.log(f"Error '{excep.error}' creating Power Port") def create_console_ports(self, console_ports, device_type): - existing_console_ports = {str(item): item for item in self.netbox.dcim.console_port_templates.filter(**{'device_type_id' if self.newfilters else 'devicetype_id': device_type})} + existing_console_ports = {str(item): item for item in self.netbox.dcim.console_port_templates.filter(**{'device_type_id' if self.new_filters else 'devicetype_id': device_type})} to_create = self.get_device_type_ports_to_create(console_ports, device_type, existing_console_ports) if to_create: @@ -268,7 +268,7 @@ def create_console_ports(self, console_ports, device_type): self.handle.log(f"Error '{excep.error}' creating Console Port") def create_power_outlets(self, power_outlets, device_type): - existing_power_outlets = {str(item): item for item in self.netbox.dcim.power_outlet_templates.filter(**{'device_type_id' if self.newfilters else 'devicetype_id': device_type})} + existing_power_outlets = {str(item): item for item in self.netbox.dcim.power_outlet_templates.filter(**{'device_type_id' if self.new_filters else 'devicetype_id': device_type})} to_create = self.get_device_type_ports_to_create(power_outlets, device_type, existing_power_outlets) if to_create: @@ -289,7 +289,7 @@ def create_power_outlets(self, power_outlets, device_type): self.handle.log(f"Error '{excep.error}' creating Power Outlet") def create_console_server_ports(self, console_server_ports, device_type): - existing_console_server_ports = {str(item): item for item in self.netbox.dcim.console_server_port_templates.filter(**{'device_type_id' if self.newfilters else 'devicetype_id': device_type})} + existing_console_server_ports = {str(item): item for item in self.netbox.dcim.console_server_port_templates.filter(**{'device_type_id' if self.new_filters else 'devicetype_id': device_type})} to_create = self.get_device_type_ports_to_create(console_server_ports, device_type, existing_console_server_ports) if to_create: @@ -315,7 +315,7 @@ def create_rear_ports(self, rear_ports, device_type): self.handle.log(f"Error '{excep.error}' creating Rear Port") def create_front_ports(self, front_ports, device_type): - existing_front_ports = {str(item): item for item in self.netbox.dcim.front_port_templates.filter(**{'device_type_id' if self.newfilters else 'devicetype_id': device_type})} + existing_front_ports = {str(item): item for item in self.netbox.dcim.front_port_templates.filter(**{'device_type_id' if self.new_filters else 'devicetype_id': device_type})} to_create = self.get_device_type_ports_to_create(front_ports, device_type, existing_front_ports) if to_create: @@ -337,7 +337,7 @@ def create_front_ports(self, front_ports, device_type): self.handle.log(f"Error '{excep.error}' creating Front Port") def create_device_bays(self, device_bays, device_type): - existing_device_bays = {str(item): item for item in self.netbox.dcim.device_bay_templates.filter(**{'device_type_id' if self.newfilters else 'devicetype_id': device_type})} + existing_device_bays = {str(item): item for item in self.netbox.dcim.device_bay_templates.filter(**{'device_type_id' if self.new_filters else 'devicetype_id': device_type})} to_create = self.get_device_type_ports_to_create(device_bays, device_type, existing_device_bays) if to_create: @@ -350,7 +350,7 @@ def create_device_bays(self, device_bays, device_type): self.handle.log(f"Error '{excep.error}' creating Device Bay") def create_module_bays(self, module_bays, device_type): - existing_module_bays = {str(item): item for item in self.netbox.dcim.module_bay_templates.filter(**{'device_type_id' if self.newfilters else 'devicetype_id': device_type})} + existing_module_bays = {str(item): item for item in self.netbox.dcim.module_bay_templates.filter(**{'device_type_id' if self.new_filters else 'devicetype_id': device_type})} to_create = self.get_device_type_ports_to_create(module_bays, device_type, existing_module_bays) if to_create: From d2e3181c742bad1f79d4fc7e7de951bd01678905 Mon Sep 17 00:00:00 2001 From: chatasos <47942984+chatasos@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:51:15 +0300 Subject: [PATCH 8/8] Update netbox_api.py --- netbox_api.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/netbox_api.py b/netbox_api.py index fb6bc5d8..0d11f394 100644 --- a/netbox_api.py +++ b/netbox_api.py @@ -207,10 +207,10 @@ def get_rear_ports(self, device_type): return {str(item): item for item in self.netbox.dcim.rear_port_templates.filter(**{'device_type_id' if self.new_filters else 'devicetype_id': device_type})} def get_module_power_ports(self, module_type): - return {str(item): item for item in self.netbox.dcim.power_port_templates.filter(module_type_id=module_type)} + return {str(item): item for item in self.netbox.dcim.power_port_templates.filter(**{'module_type_id' if self.new_filters else 'moduletype_id': module_type})} def get_module_rear_ports(self, module_type): - return {str(item): item for item in self.netbox.dcim.rear_port_templates.filter(module_type_id=module_type)} + return {str(item): item for item in self.netbox.dcim.rear_port_templates.filter(**{'module_type_id' if self.new_filters else 'moduletype_id': module_type})} def get_device_type_ports_to_create(self, dcim_ports, device_type, existing_ports): to_create = [port for port in dcim_ports if port['name'] not in existing_ports] @@ -363,7 +363,7 @@ def create_module_bays(self, module_bays, device_type): self.handle.log(f"Error '{excep.error}' creating Module Bay") def create_module_interfaces(self, module_interfaces, module_type): - existing_interfaces = {str(item): item for item in self.netbox.dcim.interface_templates.filter(module_type_id=module_type)} + existing_interfaces = {str(item): item for item in self.netbox.dcim.interface_templates.filter(**{'module_type_id' if self.new_filters else 'moduletype_id': module_type})} to_create = self.get_module_type_ports_to_create(module_interfaces, module_type, existing_interfaces) if to_create: @@ -389,7 +389,7 @@ def create_module_power_ports(self, power_ports, module_type): self.handle.log(f"Error '{excep.error}' creating Module Power Port") def create_module_console_ports(self, console_ports, module_type): - existing_console_ports = {str(item): item for item in self.netbox.dcim.console_port_templates.filter(module_type_id=module_type)} + existing_console_ports = {str(item): item for item in self.netbox.dcim.console_port_templates.filter(**{'module_type_id' if self.new_filters else 'moduletype_id': module_type})} to_create = self.get_module_type_ports_to_create(console_ports, module_type, existing_console_ports) if to_create: @@ -402,7 +402,7 @@ def create_module_console_ports(self, console_ports, module_type): self.handle.log(f"Error '{excep.error}' creating Module Console Port") def create_module_power_outlets(self, power_outlets, module_type): - existing_power_outlets = {str(item): item for item in self.netbox.dcim.power_outlet_templates.filter(module_type_id=module_type)} + existing_power_outlets = {str(item): item for item in self.netbox.dcim.power_outlet_templates.filter(**{'module_type_id' if self.new_filters else 'moduletype_id': module_type})} to_create = self.get_module_type_ports_to_create(power_outlets, module_type, existing_power_outlets) if to_create: @@ -423,7 +423,7 @@ def create_module_power_outlets(self, power_outlets, module_type): self.handle.log(f"Error '{excep.error}' creating Module Power Outlet") def create_module_console_server_ports(self, console_server_ports, module_type): - existing_console_server_ports = {str(item): item for item in self.netbox.dcim.console_server_port_templates.filter(module_type_id=module_type)} + existing_console_server_ports = {str(item): item for item in self.netbox.dcim.console_server_port_templates.filter(**{'module_type_id' if self.new_filters else 'moduletype_id': module_type})} to_create = self.get_module_type_ports_to_create(console_server_ports, module_type, existing_console_server_ports) if to_create: @@ -449,7 +449,7 @@ def create_module_rear_ports(self, rear_ports, module_type): self.handle.log(f"Error '{excep.error}' creating Module Rear Port") def create_module_front_ports(self, front_ports, module_type): - existing_front_ports = {str(item): item for item in self.netbox.dcim.front_port_templates.filter(module_type_id=module_type)} + existing_front_ports = {str(item): item for item in self.netbox.dcim.front_port_templates.filter(**{'module_type_id' if self.new_filters else 'moduletype_id': module_type})} to_create = self.get_module_type_ports_to_create(front_ports, module_type, existing_front_ports) if to_create: