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
17c74a1f
Commit
17c74a1f
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 delete interface in NetBox
parent
ac53b2e9
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
+8
-6
8 additions, 6 deletions
gso/services/netbox_client.py
utils/netboxcli.py
+14
-16
14 additions, 16 deletions
utils/netboxcli.py
with
22 additions
and
22 deletions
gso/services/netbox_client.py
+
8
−
6
View file @
17c74a1f
...
...
@@ -131,7 +131,7 @@ class NetboxClient:
return
int
(
""
.
join
(
filter
(
str
.
isdigit
,
type_parts
[
0
])))
*
1000000
return
None
def
create_device
(
self
,
router
_name
:
str
,
site_tier
:
str
)
->
Devices
:
def
create_device
(
self
,
device
_name
:
str
,
site_tier
:
str
)
->
Devices
:
"""
Create a new device in Netbox.
"""
# Get device type id
...
...
@@ -146,7 +146,7 @@ class NetboxClient:
# Create new device
device
=
self
.
netbox
.
dcim
.
devices
.
create
(
name
=
router
_name
,
device_type
=
device_type
.
id
,
role
=
device_role
.
id
,
site
=
device_site
.
id
name
=
device
_name
,
device_type
=
device_type
.
id
,
role
=
device_role
.
id
,
site
=
device_site
.
id
)
module_bays
=
list
(
self
.
netbox
.
dcim
.
module_bays
.
filter
(
device_id
=
device
.
id
))
card_type
=
self
.
netbox
.
dcim
.
module_types
.
get
(
model
=
tier_info
.
module_type
)
...
...
@@ -168,8 +168,9 @@ class NetboxClient:
return
device
def
delete_device
(
self
,
router_name
:
str
)
->
None
:
self
.
netbox
.
dcim
.
devices
.
get
(
name
=
router_name
).
delete
()
def
delete_device
(
self
,
device_name
:
str
)
->
None
:
"""
Delete device by name
"""
self
.
netbox
.
dcim
.
devices
.
get
(
name
=
device_name
).
delete
()
return
def
attach_interface_to_lag
(
...
...
@@ -191,7 +192,8 @@ class NetboxClient:
# 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
}
.
"
)
f
"
The interface:
{
iface_name
}
on device:
{
device_name
}
already belongs to a LAG:
{
iface
.
lag
.
name
}
.
"
)
iface
.
lag
=
lag
.
id
...
...
@@ -305,4 +307,4 @@ class NetboxClient:
speed_bps
=
self
.
calculate_speed_bits_per_sec
(
speed
)
return
self
.
netbox
.
dcim
.
interfaces
.
filter
(
device
=
device
.
name
,
enabled
=
False
,
mark_connected
=
False
,
speed
=
speed_bps
)
\ No newline at end of file
)
This diff is collapsed.
Click to expand it.
utils/netboxcli.py
+
14
−
16
View file @
17c74a1f
...
...
@@ -131,9 +131,9 @@ list.add_command(interfaces)
list
.
add_command
(
devices
)
# Define
here attach
command
# Define
delete
command
s here
@cli.group
()
def
attach
()
->
None
:
def
delete
()
->
None
:
pass
...
...
@@ -147,7 +147,16 @@ def interface_to_lag(fqdn: str, iface: str, lag: str) -> None:
click
.
echo
(
new_iface
)
attach
.
add_command
(
interface_to_lag
)
@delete.command
()
@click.option
(
"
--fqdn
"
,
help
=
"
Device name from where to get interface to delete
"
)
@click.option
(
"
--iface
"
,
help
=
"
Name of interface name to delete
"
)
def
interface
(
fqdn
:
str
,
iface
:
str
)
->
None
:
click
.
echo
(
f
"
Deleting interface: device=
{
fqdn
}
, interface name=
{
iface
}
"
)
NetboxClient
().
delete_interface
(
fqdn
,
iface
)
delete
.
add_command
(
device
)
delete
.
add_command
(
interface
)
# The action command
...
...
@@ -188,7 +197,7 @@ def allocate_interface(fqdn: str, iface: str) -> None:
@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
}
"
)
deallocated_iface
=
NetboxClient
().
deallocat
e_interface
(
fqdn
,
iface
)
deallocated_iface
=
NetboxClient
().
fre
e_interface
(
fqdn
,
iface
)
click
.
echo
(
deallocated_iface
)
...
...
@@ -198,26 +207,15 @@ def deallocate_interface(fqdn: str, iface: str) -> None:
@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
=
Net
B
oxClient
().
attach_interface_to_lag
(
fqdn
,
lag
,
iface
)
attached_iface
=
Net
b
oxClient
().
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