Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GÉANT Service Orchestrator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GÉANT Orchestration and Automation Team
GAP
GÉANT Service Orchestrator
Commits
38861584
Commit
38861584
authored
1 year ago
by
Hakan Calim
Committed by
Neda Moeini
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
NAT-243: added reserve of an interface
parent
ea17cded
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!77
Netbox integration including intial CLI for populating base data and ...
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gso/services/netbox_client.py
+29
-1
29 additions, 1 deletion
gso/services/netbox_client.py
with
29 additions
and
1 deletion
gso/services/netbox_client.py
+
29
−
1
View file @
38861584
...
...
@@ -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
Value
Error
(
f
"
Device:
{
device_name
}
not found
"
)
raise
NotFound
Error
(
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
"
)))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment