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
53cbe8a2
Commit
53cbe8a2
authored
1 year ago
by
Hakan Calim
Committed by
Neda Moeini
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
NAT-243: added method to allocate interface
parent
38861584
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
-2
29 additions, 2 deletions
gso/services/netbox_client.py
with
29 additions
and
2 deletions
gso/services/netbox_client.py
+
29
−
2
View file @
53cbe8a2
...
...
@@ -55,6 +55,12 @@ class NotFoundError(Exception):
pass
# An exception on a workflow error
class
WorkflowStateException
(
Exception
):
"""
Exception raised on problems during workflow.
"""
pass
def
connect
(
api
,
token
):
"""
Creates a netbox client to communicate
...
...
@@ -222,10 +228,10 @@ def reserve_interface(nbclient, device_name: str, iface_name: str) -> dict:
# 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
"
)
raise
WorkflowStateException
(
f
"
The interface:
{
iface_name
}
on device:
{
device_name
}
is already
reserved
.
"
)
# Reserve interface by enabling it
interface
.
enabled
=
True
...
...
@@ -234,6 +240,27 @@ def reserve_interface(nbclient, device_name: str, iface_name: str) -> dict:
return
dict
(
interface
)
def
allocate_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
)
# allocate interface by marking it as connected
# Check if interface is available
if
interface
is
None
:
raise
NotFoundError
(
f
"
Interface:
{
iface_name
}
on device:
{
device_name
}
not found.
"
)
# Check if interface is reserved
if
interface
.
mark_connected
:
raise
WorkflowStateException
(
f
"
The interface:
{
iface_name
}
on device:
{
device_name
}
is already allocated.
"
)
# allocate interface by mark as connected
interface
.
mark_connected
=
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