Skip to content
Snippets Groups Projects
Commit 38861584 authored by Hakan Calim's avatar Hakan Calim Committed by Neda Moeini
Browse files

NAT-243: added reserve of an interface

parent ea17cded
No related branches found
No related tags found
1 merge request!77Netbox integration including intial CLI for populating base data and ...
......@@ -49,6 +49,12 @@ class Site(pydantic.BaseModel):
slug: str
# An exception for not found search
class NotFoundError(Exception):
"""Exception raised for not found search."""
pass
def connect(api, token):
"""
Creates a netbox client to communicate
......@@ -77,7 +83,7 @@ def get_device_by_name(nbclient, device_name):
device = nbclient.dcim.devices.get(name=device_name)
if device is None:
raise ValueError(f"Device: {device_name} not found")
raise NotFoundError(f"Device: {device_name} not found")
else:
return device
......@@ -207,5 +213,27 @@ def attach_interface_to_lag(nbclient, device_name: str, lag_name: str, iface_nam
return dict(updated_iface)
def reserve_interface(nbclient, device_name: str, iface_name: str) -> dict:
# First get interface from device
device = get_device_by_name(nbclient, device_name)
interface = nbclient.dcim.interfaces.get(device_id=device.id,
name=iface_name)
# Reserve interface by enabling it
if interface is None:
raise NotFoundError(f"Interface: {iface_name} on device: {device_name} not found.")
# Check if interface is reserved
if interface.enabled:
print("Interface is reserved")
# Reserve interface by enabling it
interface.enabled = True
interface.save()
return dict(interface)
if __name__ == "__main__":
print(dict(create_device_manufacturer("Juniper", "juniper")))
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