-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add cmdlet for StaticRoutes (Add/Get/Remove) #43
Open
alagoutte
wants to merge
23
commits into
PowerAruba:master
Choose a base branch
from
alagoutte:static-route
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
be76800
StaticRoutes : Add Get-ArubaCXStaticRoutes
alagoutte 3f11d50
StaticRoutes: Add pipeline support for vrf
alagoutte 87f9d3c
Confirm: Add Confirm-ArubaCXStaticRoutes for check if it is a SR object
alagoutte 26e521c
StaticRoutes: Add Add-ArubaCXStaticRoutes for add Static Route
alagoutte 9c3ae26
Confirm: Fix typo for Confirm-ArubaCXStaticRoutes
alagoutte 1f0f337
StaticRoutes: Add Remove-ArubaCXStaticRoutes for remove a Static Route
alagoutte 28095cc
StaticRoutes(Add): Fix add Static Routes, need to set the full URI fo…
alagoutte c0726e7
StaticRoutes(Add): Don't need to replace / on prefix when add static …
alagoutte 33d8976
Connection(Tests): Add Static Routes to Multi Connection tests
alagoutte 42a733a
StaticRoutes(Tests): Add Tests for Add/Get/Remove Static Routes
alagoutte bed972f
StaticRoutes: Fix typo (rject -> reject)
alagoutte c491e2e
StaticRoutes: Add vrf when use Get-ArubaCXStaticRoutes with prefix pa…
alagoutte 31ca21c
Confirm(StaticRoutes): Add check of vrf attributes
alagoutte a3c5fd4
StaticRoutes: Get vrf info from SR ps object when using pipeline
alagoutte a4401eb
StaticRoutes(Tests): rename for add Tests to filename
alagoutte 3db2cf3
StaticRoutes(Tests): add first part of VRF support for Tests Static R…
alagoutte 7bd8865
StaticRoutes: Add Tests with a different VRF (for Get)
alagoutte 83e8b24
StaticRoutes: Add Tests with a different VRF (for Add)
alagoutte 59e7850
StaticRoutes: Add Tests with a different VRF (for Remove)
alagoutte 7a4440c
StaticRoutes: Enhance Example for remove
alagoutte f37258c
StaticRoutes(Tests): Fix blank line
alagoutte 18f6140
Confirm(Static Routes): fix typo
alagoutte 72403b2
StaticRoutes: fix typo
alagoutte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,251 @@ | ||
# | ||
# Copyright 2020, Alexis La Goutte <alexis dot lagoutte at gmail dot com> | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
function Add-ArubaCXStaticRoutes { | ||
|
||
<# | ||
.SYNOPSIS | ||
Add Aruba CX Static Route | ||
|
||
.DESCRIPTION | ||
Add Static Route (address_family, prefix, static_nexthops, type) | ||
|
||
.EXAMPLE | ||
Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 192.0.2.0 -prefix_ip4_mask 24 -type forward | ||
|
||
Add Static Route type forward for network 192.0.2.0/24 (on default vrf) | ||
|
||
.EXAMPLE | ||
Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 192.0.2.0 -prefix_ip4_mask 24 -type blackhole -vrf MyVrf | ||
|
||
Add Static Route type blackhole for network 192.0.2.0/24 on MyVRF | ||
|
||
.EXAMPLE | ||
Get-ArubaCXVrf MyVRF | Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 192.0.2.0 -prefix_ip4_mask 24 -type reject | ||
|
||
Add Static Route type reject for network 192.0.2.0/24 on MyVRF (using pipeline) | ||
#> | ||
Param( | ||
[Parameter (Mandatory = $false, ValueFromPipeline = $true)] | ||
[ValidateScript( { Confirm-ArubaCXVrfs $_ })] | ||
[psobject]$vrf_pp, | ||
[Parameter(Mandatory = $false)] | ||
[string]$vrf = "default", | ||
[Parameter (Mandatory = $true)] | ||
[ValidateSet('ipv4', IgnoreCase = $false)] | ||
[string]$address_family = "ipv4", | ||
[Parameter (Mandatory = $true)] | ||
[ipaddress]$prefix_ip4, | ||
[Parameter (Mandatory = $true)] | ||
[ValidateRange(0, 32)] | ||
[int]$prefix_ip4_mask, | ||
[Parameter (Mandatory = $true)] | ||
[ValidateSet('forward', 'reject', 'blackhole')] | ||
[string]$type, | ||
[Parameter (Mandatory = $False)] | ||
[ValidateNotNullOrEmpty()] | ||
[PSObject]$connection = $DefaultArubaCXConnection | ||
) | ||
|
||
Begin { | ||
} | ||
|
||
Process { | ||
|
||
#get vrf name from vrf_pp ps object (based by pipeline) | ||
if ($vrf_pp) { | ||
$vrf = $vrf_pp.name | ||
} | ||
|
||
if ( -not ($prefix_ip4.AddressFamily -eq "InterNetwork" )) { | ||
Throw "You need to specify a IPv4 Address" | ||
} | ||
$prefix = $prefix_ip4.ToString() + "/" + $prefix_ip4_mask | ||
|
||
$uri = "system/vrfs/$vrf/static_routes" | ||
|
||
$_sr = new-Object -TypeName PSObject | ||
|
||
$_sr | add-member -name "address_family" -membertype NoteProperty -Value $address_family | ||
|
||
$_sr | add-member -name "prefix" -membertype NoteProperty -Value $prefix | ||
|
||
$_sr | add-member -name "type" -membertype NoteProperty -Value $type | ||
|
||
$_sr | add-member -name "vrf" -membertype NoteProperty -Value ("/rest/" + $($connection.version) + "/system/vrfs/" + $vrf) | ||
|
||
$response = Invoke-ArubaCXRestMethod -uri $uri -method 'POST' -body $_sr -connection $connection | ||
$response | ||
|
||
Get-ArubaCXStaticRoutes -vrf $vrf -prefix $prefix -connection $connection | ||
} | ||
|
||
End { | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a blank line ? |
||
|
||
function Get-ArubaCXStaticRoutes { | ||
|
||
<# | ||
.SYNOPSIS | ||
Get list of all Aruba CX Routes | ||
|
||
.DESCRIPTION | ||
Get list of all Aruba CX Static Route (address_family, prefix, static_nexthops, type) | ||
|
||
.EXAMPLE | ||
Get-ArubaCXStaticRoutes | ||
|
||
Get list of all Static Routes information (address_family, prefix, static_nexthops, type) | ||
|
||
.EXAMPLE | ||
Get-ArubaCXStaticRoutes -prefix 192.0.2.0/24 | ||
|
||
Get Static Route information of prefix 192.0.2.0/24 | ||
|
||
.EXAMPLE | ||
Get-ArubaCXVrfs -vrf MyVRF | Get-ArubaCXStaticRoutes | ||
|
||
Get Static Route information from VRF named MyVRF (using pipeline) | ||
|
||
.EXAMPLE | ||
Get-ArubaCXStaticRoutes -vrf MyVRF | ||
|
||
Get Static Route information from VRF named MyVRF | ||
#> | ||
|
||
[CmdletBinding(DefaultParametersetname = "Default")] | ||
Param( | ||
[Parameter (Mandatory = $false, ParameterSetName = "prefix", position = "1")] | ||
[string]$prefix, | ||
[Parameter (Mandatory = $false, ValueFromPipeline = $true)] | ||
[ValidateScript( { Confirm-ArubaCXVrfs $_ })] | ||
[psobject]$vrf_pp, | ||
[Parameter(Mandatory = $false)] | ||
[string]$vrf = "default", | ||
[Parameter(Mandatory = $false)] | ||
[ValidateRange(1, 4)] | ||
[Int]$depth, | ||
[Parameter(Mandatory = $false)] | ||
[ValidateSet("configuration", "status", "statistics", "writable")] | ||
[String]$selector, | ||
[Parameter(Mandatory = $false)] | ||
[String[]]$attributes, | ||
[Parameter(Mandatory = $false)] | ||
[switch]$vsx_peer, | ||
[Parameter (Mandatory = $False)] | ||
[ValidateNotNullOrEmpty()] | ||
[PSObject]$connection = $DefaultArubaCXConnection | ||
) | ||
|
||
Begin { | ||
} | ||
|
||
Process { | ||
|
||
#get vrf name from vrf_pp ps object (based by pipeline) | ||
if ($vrf_pp) { | ||
$vrf = $vrf_pp.name | ||
} | ||
|
||
$invokeParams = @{ } | ||
if ( $PsBoundParameters.ContainsKey('depth') ) { | ||
$invokeParams.add( 'depth', $depth ) | ||
} | ||
if ( $PsBoundParameters.ContainsKey('selector') ) { | ||
$invokeParams.add( 'selector', $selector ) | ||
} | ||
if ( $PsBoundParameters.ContainsKey('attributes') ) { | ||
$invokeParams.add( 'attributes', $attributes ) | ||
} | ||
if ( $PsBoundParameters.ContainsKey('vsx_peer') ) { | ||
$invokeParams.add( 'vsx_peer', $true ) | ||
} | ||
|
||
$uri = "system/vrfs/$vrf/static_routes" | ||
|
||
# you can directly filter by prefix | ||
if ( $PsBoundParameters.ContainsKey('prefix') ) { | ||
#replace / by %2F | ||
$prefix = $prefix -replace '/', '%2F' | ||
$uri += "/$prefix" | ||
} | ||
|
||
$response = Invoke-ArubaCXRestMethod -uri $uri -method 'GET' -connection $connection @invokeParams | ||
|
||
#Add vrf parameter when use prefix (more easy to remove and also for get vrf source...) | ||
if ( $PsBoundParameters.ContainsKey('prefix') ) { | ||
$response | add-member -name "vrf" -membertype NoteProperty -Value $vrf | ||
} | ||
|
||
$response | ||
} | ||
|
||
End { | ||
} | ||
} | ||
|
||
function Remove-ArubaCXStaticRoutes { | ||
|
||
<# | ||
.SYNOPSIS | ||
Remove a Static Route on Aruba CX Switch | ||
|
||
.DESCRIPTION | ||
Remove a Static Route on Aruba CX Switch | ||
|
||
.EXAMPLE | ||
$sr = Get-ArubaCXStaticRoutes -prefix 192.0.2.0/24 | ||
PS C:\>$sr | Remove-ArubaCXStaticRoutes | ||
|
||
Remove Static Route with prefix 192.0.2.0/24 (on default vrf) | ||
|
||
.EXAMPLE | ||
Remove-ArubaCXStaticRoutes -prefix 192.0.2.0/24 -confirm:$false -vrf MyVRF | ||
|
||
Remove Static Route 192.0.2.0/24 on MyVRF with no confirmation | ||
#> | ||
|
||
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'high')] | ||
Param( | ||
[Parameter (Mandatory = $true, ParameterSetName = "prefix")] | ||
[string]$prefix, | ||
[Parameter (Mandatory = $true, ValueFromPipeline = $true, Position = 1, ParameterSetName = "route")] | ||
[ValidateScript( { Confirm-ArubaCXStaticRoutes $_ })] | ||
[psobject]$sr, | ||
[Parameter(Mandatory = $true, ParameterSetName = "prefix")] | ||
[string]$vrf, | ||
[Parameter (Mandatory = $False)] | ||
[ValidateNotNullOrEmpty()] | ||
[PSObject]$connection = $DefaultArubaCXConnection | ||
) | ||
|
||
Begin { | ||
} | ||
|
||
Process { | ||
|
||
#get prefix and vrf from static route ps object | ||
if ($sr) { | ||
$prefix = $sr.prefix | ||
$vrf = $sr.vrf | ||
} | ||
|
||
#replace / by %2F | ||
$uri_prefix = $prefix -replace '/', '%2F' | ||
|
||
$uri = "system/vrfs/$vrf/static_routes/$uri_prefix" | ||
|
||
if ($PSCmdlet.ShouldProcess("Static Route (VRF: ${vrf})", "Remove ${prefix}")) { | ||
Write-Progress -activity "Remove Static Route" | ||
Invoke-ArubaCXRestMethod -method "DELETE" -uri $uri -connection $connection | ||
Write-Progress -activity "Remove Static Route" -completed | ||
} | ||
} | ||
|
||
End { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo an => a