Skip to content
Snippets Groups Projects
Commit 20dbf2e2 authored by Ubuntu's avatar Ubuntu Committed by Neda Moeini
Browse files

NAT-243: added custom fields filter to get interfaces

parent 2ce67726
No related branches found
No related tags found
1 merge request!77Netbox integration including intial CLI for populating base data and ...
......@@ -74,19 +74,22 @@ def get_all_devices(nbclient):
# We need sometimes a specific device
# for creating devices
def get_device_by_name(nbclient, device_name):
return nbclient.dcim.devices.get(name=device_name)
device = nbclient.dcim.devices.get(name=device_name)
if device is None:
raise ValueError(f"Device: {device_name} not found")
else:
return device
# get all interfaces for a device
def get_interfaces_by_device(nbclient, device_name):
device = get_device_by_name(nbclient, device_name)
if device is None:
raise ValueError(f"Device: {device_name} not found")
return list(nbclient.dcim.interfaces.filter(device_id=device.id,
enabled=False,
mark_connected=False,
# enabled=False,
# mark_connected=False,
custom_fields={"states": "UNUSED"}
))
......@@ -105,13 +108,11 @@ def create_interface(nbclient,
"""
device = get_device_by_name(nbclient, device_name)
if device is None:
raise ValueError(f"Device: {device_name} not found")
new_iface = nbclient.dcim.interfaces.create(name=iface_name,
type=type,
enabled=False,
mark_connected=False,
custom_fields={"states": "RESERVED"},
device=device.id)
return dict(new_iface)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment