Skip to content

Commit

Permalink
Update netbox_api.py
Browse files Browse the repository at this point in the history
  • Loading branch information
chatasos authored Oct 3, 2024
1 parent 28e9fb0 commit 48d7084
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions netbox_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand All @@ -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)

Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 48d7084

Please sign in to comment.