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
ac53b2e9
Commit
ac53b2e9
authored
1 year ago
by
JORGE SASIAIN
Committed by
Neda Moeini
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
NAT-244: create method to unattach physical interface from LAG in NetBox
parent
5ec342b3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!94
Feature/Netbox integration terminate ip trunk
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gso/services/netbox_client.py
+5
-22
5 additions, 22 deletions
gso/services/netbox_client.py
utils/netboxcli.py
+26
-4
26 additions, 4 deletions
utils/netboxcli.py
with
31 additions
and
26 deletions
gso/services/netbox_client.py
+
5
−
22
View file @
ac53b2e9
...
...
@@ -188,7 +188,11 @@ class NetboxClient:
# Get LAG
lag
=
self
.
netbox
.
dcim
.
interfaces
.
get
(
name
=
lag_name
,
device_id
=
device
.
id
)
# Assign interface to LAG
# Assign interface to LAG, ensuring it doesn't already belong to a LAG
if
iface
.
lag
:
raise
WorkflowStateError
(
f
"
The interface:
{
iface_name
}
on device:
{
device_name
}
already belongs to a LAG:
{
iface
.
lag
.
name
}
.
"
)
iface
.
lag
=
lag
.
id
# Set description if provided
...
...
@@ -220,27 +224,6 @@ class NetboxClient:
return
interface
def
free_interface
(
self
,
device_name
:
str
,
iface_name
:
str
)
->
Interfaces
:
"""
Reserve an interface by enabling it.
"""
# First get interface from device
device
=
self
.
get_device_by_name
(
device_name
)
interface
=
self
.
netbox
.
dcim
.
interfaces
.
get
(
device_id
=
device
.
id
,
name
=
iface_name
)
# Check if interface exists
if
interface
is
None
:
raise
NotFoundError
(
f
"
Interface:
{
iface_name
}
on device:
{
device_name
}
not found.
"
)
# Ensure that interface is reserved
if
not
interface
.
enabled
:
raise
WorkflowStateError
(
f
"
The interface:
{
iface_name
}
on device:
{
device_name
}
is not reserved.
"
)
# Free interface by disabling it
interface
.
enabled
=
False
interface
.
save
()
return
interface
def
allocate_interface
(
self
,
device_name
:
str
,
iface_name
:
str
)
->
Interfaces
:
"""
Allocate an interface by marking it as connected.
"""
...
...
This diff is collapsed.
Click to expand it.
utils/netboxcli.py
+
26
−
4
View file @
ac53b2e9
...
...
@@ -157,7 +157,7 @@ def action() -> None:
@action.command
()
@click.option
(
"
--fqdn
"
,
help
=
"
Device name where to get interface to edit
"
)
@click.option
(
"
--fqdn
"
,
help
=
"
Device name
from
where to get interface to edit
"
)
@click.option
(
"
--iface
"
,
help
=
"
Interface name to edit
"
)
def
reserve_interface
(
fqdn
:
str
,
iface
:
str
)
->
None
:
click
.
echo
(
f
"
Reserving interface: device =
{
fqdn
}
, interface name=
{
iface
}
"
)
...
...
@@ -166,7 +166,7 @@ def reserve_interface(fqdn: str, iface: str) -> None:
@action.command
()
@click.option
(
"
--fqdn
"
,
help
=
"
Device name where to get interface to edit
"
)
@click.option
(
"
--fqdn
"
,
help
=
"
Device name
from
where to get interface to edit
"
)
@click.option
(
"
--iface
"
,
help
=
"
Interface name to edit
"
)
def
free_interface
(
fqdn
:
str
,
iface
:
str
)
->
None
:
click
.
echo
(
f
"
Freeing interface: device=
{
fqdn
}
, interface name=
{
iface
}
"
)
...
...
@@ -175,7 +175,7 @@ def free_interface(fqdn: str, iface: str) -> None:
@action.command
()
@click.option
(
"
--fqdn
"
,
help
=
"
Device name where to get interface to edit
"
)
@click.option
(
"
--fqdn
"
,
help
=
"
Device name
from
where to get interface to edit
"
)
@click.option
(
"
--iface
"
,
help
=
"
Interface name to edit
"
)
def
allocate_interface
(
fqdn
:
str
,
iface
:
str
)
->
None
:
click
.
echo
(
f
"
Allocating interface: device=
{
fqdn
}
, interface name=
{
iface
}
"
)
...
...
@@ -184,7 +184,7 @@ def allocate_interface(fqdn: str, iface: str) -> None:
@action.command
()
@click.option
(
"
--fqdn
"
,
help
=
"
Device name where to get interface to edit
"
)
@click.option
(
"
--fqdn
"
,
help
=
"
Device name
from
where to get interface to edit
"
)
@click.option
(
"
--iface
"
,
help
=
"
Interface name to edit
"
)
def
deallocate_interface
(
fqdn
:
str
,
iface
:
str
)
->
None
:
click
.
echo
(
f
"
Deallocating interface: device=
{
fqdn
}
, interface name=
{
iface
}
"
)
...
...
@@ -192,10 +192,32 @@ def deallocate_interface(fqdn: str, iface: str) -> None:
click
.
echo
(
deallocated_iface
)
@action.command
()
@click.option
(
"
--fqdn
"
,
help
=
"
Device name from where to get physical interface to attach LAG
"
)
@click.option
(
"
--lag
"
,
help
=
"
LAG name to attach physical interface to
"
)
@click.option
(
"
--iface
"
,
help
=
"
Interface name to attach to LAG
"
)
def
attach_interface_to_lag
(
fqdn
:
str
,
lag
:
str
,
iface
:
str
)
->
None
:
click
.
echo
(
f
"
Attaching LAG to physical interface: device=
{
fqdn
}
, LAG name=
{
lag
}
, interface name=
{
iface
}
"
)
attached_iface
=
NetBoxClient
().
attach_interface_to_lag
(
fqdn
,
lag
,
iface
)
click
.
echo
(
attached_iface
)
@action.command
()
@click.option
(
"
--fqdn
"
,
help
=
"
Device name from where to get physical interface to unattach LAG
"
)
@click.option
(
"
--lag
"
,
help
=
"
LAG name to unattach from physical interface
"
)
@click.option
(
"
--iface
"
,
help
=
"
Interface name to unattach LAG from
"
)
def
unattach_interface_from_lag
(
fqdn
:
str
,
lag
:
str
,
iface
:
str
)
->
None
:
click
.
echo
(
f
"
Unattaching LAG from physical interface: device=
{
fqdn
}
, LAG name=
{
lag
}
, interface name=
{
iface
}
"
)
unattached_iface
=
NetBoxClient
().
unattach_interface_from_lag
(
fqdn
,
lag
,
iface
)
click
.
echo
(
unattached_iface
)
action
.
add_command
(
reserve_interface
)
action
.
add_command
(
free_interface
)
action
.
add_command
(
allocate_interface
)
action
.
add_command
(
deallocate_interface
)
action
.
add_command
(
attach_interface_to_lag
)
action
.
add_command
(
unattach_interface_from_lag
)
if
__name__
==
"
__main__
"
:
...
...
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