From be7680033637dde65e9b8bf40ddc1c36237fed30 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Thu, 2 Apr 2020 07:15:03 +0200 Subject: [PATCH 01/23] StaticRoutes : Add Get-ArubaCXStaticRoutes for get Static Routes Information (address_family, prefix, static_nexthops, type) --- PowerArubaCX/Public/StaticRoutes.ps1 | 89 ++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 PowerArubaCX/Public/StaticRoutes.ps1 diff --git a/PowerArubaCX/Public/StaticRoutes.ps1 b/PowerArubaCX/Public/StaticRoutes.ps1 new file mode 100644 index 0000000..7ad81a9 --- /dev/null +++ b/PowerArubaCX/Public/StaticRoutes.ps1 @@ -0,0 +1,89 @@ +# +# Copyright 2020, Alexis La Goutte +# +# SPDX-License-Identifier: Apache-2.0 +# + +function Get-ArubaCXStaticRoutes { + + <# + .SYNOPSIS + Get list of all Aruba CX Route + + .DESCRIPTION + Get list of all Aruba CX Static Rout (address_family, prefix, static_nexthops, type) + + .EXAMPLE + Get-ArubaCXStaticRoutes + + Get list of all Static Route 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 + #> + + [CmdletBinding(DefaultParametersetname = "Default")] + Param( + [Parameter (Mandatory = $false, ParameterSetName = "prefix", position = "1")] + [string]$prefix, + [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)] + [string]$vrf = "default", + [Parameter(Mandatory = $false)] + [switch]$vsx_peer, + [Parameter (Mandatory = $False)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection = $DefaultArubaCXConnection + ) + + Begin { + } + + Process { + + + $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 id parameter when use writable type selector + if ( $PsBoundParameters.ContainsKey('selector') -and $PsBoundParameters.ContainsKey('prefix') -and $selector -eq "writable" ) { + $response | add-member -name "prefix" -membertype NoteProperty -Value $prefix + } + + $response + } + + End { + } +} \ No newline at end of file From 3f11d503bcd9e437c1a5758b50bc3f5be9c61cd7 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Thu, 2 Apr 2020 07:25:13 +0200 Subject: [PATCH 02/23] StaticRoutes: Add pipeline support for vrf and add also some example --- PowerArubaCX/Public/StaticRoutes.ps1 | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/PowerArubaCX/Public/StaticRoutes.ps1 b/PowerArubaCX/Public/StaticRoutes.ps1 index 7ad81a9..9690dcd 100644 --- a/PowerArubaCX/Public/StaticRoutes.ps1 +++ b/PowerArubaCX/Public/StaticRoutes.ps1 @@ -22,12 +22,27 @@ function Get-ArubaCXStaticRoutes { 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, @@ -37,8 +52,6 @@ function Get-ArubaCXStaticRoutes { [Parameter(Mandatory = $false)] [String[]]$attributes, [Parameter(Mandatory = $false)] - [string]$vrf = "default", - [Parameter(Mandatory = $false)] [switch]$vsx_peer, [Parameter (Mandatory = $False)] [ValidateNotNullOrEmpty()] @@ -50,6 +63,10 @@ function Get-ArubaCXStaticRoutes { Process { + #get vrf name from vrf_pp ps object (based by pipeline) + if ($vrf_pp) { + $vrf = $vrf_pp.name + } $invokeParams = @{ } if ( $PsBoundParameters.ContainsKey('depth') ) { From 87f9d3c1d883f87fcc85db5320c44f28388fafa2 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Thu, 2 Apr 2020 07:31:02 +0200 Subject: [PATCH 03/23] Confirm: Add Confirm-ArubaCXStaticRoutes for check if it is a SR object Needed for remove function --- PowerArubaCX/Private/Confirm.ps1 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/PowerArubaCX/Private/Confirm.ps1 b/PowerArubaCX/Private/Confirm.ps1 index 29d3f23..7fd5ff1 100644 --- a/PowerArubaCX/Private/Confirm.ps1 +++ b/PowerArubaCX/Private/Confirm.ps1 @@ -30,6 +30,31 @@ function Confirm-ArubaCXInterfaces { $true } + +function Confirm-ArubaCXStaticRoutes { + + Param ( + [Parameter (Mandatory = $true)] + [object]$argument + ) + #Check if it looks like an Static Routes element + + if ( -not ( $argument | get-member -name address_ipv4 -Membertype Properties)) { + throw "Element specified does not contain a address_ipv4 property." + } + if ( -not ( $argument | get-member -name prefix -Membertype Properties)) { + throw "Element specified does not contain an prefix property." + } + if ( -not ( $argument | get-member -name static_nexthops -Membertype Properties)) { + throw "Element specified does not contain a static_nexthops property." + } + if ( -not ( $argument | get-member -name type -Membertype Properties)) { + throw "Element specified does not contain a type property." + } + $true + +} + function Confirm-ArubaCXSystem { Param ( From 26e521c0ea5e49bbb1218503e38141e837d44240 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Tue, 7 Apr 2020 07:07:14 +0200 Subject: [PATCH 04/23] StaticRoutes: Add Add-ArubaCXStaticRoutes for add Static Route (Don't work for the moment.. get a 500 Error...) --- PowerArubaCX/Public/StaticRoutes.ps1 | 84 ++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/PowerArubaCX/Public/StaticRoutes.ps1 b/PowerArubaCX/Public/StaticRoutes.ps1 index 9690dcd..6cc240f 100644 --- a/PowerArubaCX/Public/StaticRoutes.ps1 +++ b/PowerArubaCX/Public/StaticRoutes.ps1 @@ -4,6 +4,90 @@ # SPDX-License-Identifier: Apache-2.0 # +function Add-ArubaCXStaticRoutes { + + <# + .SYNOPSIS + Add Aruba CX Static 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 rject + + 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 + #replace / by %2F + $prefix = $prefix -replace '/', '%2F' + + $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 $vrf + + $response = Invoke-ArubaCXRestMethod -uri $uri -method 'POST' -body $_sr -connection $connection + $response + + Get-ArubaCXStaticRoutes -vrf $vrf -prefix $prefix -connection $connection + } + + End { + } +} function Get-ArubaCXStaticRoutes { <# From 9c3ae26612b0c704ac3f1d53a255ff1bacbf65e4 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Wed, 8 Apr 2020 09:29:21 +0200 Subject: [PATCH 05/23] Confirm: Fix typo for Confirm-ArubaCXStaticRoutes address_ipv4 => address_family --- PowerArubaCX/Private/Confirm.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PowerArubaCX/Private/Confirm.ps1 b/PowerArubaCX/Private/Confirm.ps1 index 7fd5ff1..060c89a 100644 --- a/PowerArubaCX/Private/Confirm.ps1 +++ b/PowerArubaCX/Private/Confirm.ps1 @@ -39,8 +39,8 @@ function Confirm-ArubaCXStaticRoutes { ) #Check if it looks like an Static Routes element - if ( -not ( $argument | get-member -name address_ipv4 -Membertype Properties)) { - throw "Element specified does not contain a address_ipv4 property." + if ( -not ( $argument | get-member -name address_family -Membertype Properties)) { + throw "Element specified does not contain a address_family property." } if ( -not ( $argument | get-member -name prefix -Membertype Properties)) { throw "Element specified does not contain an prefix property." From 1f0f3377f0ec3971275586ff44065931b933431d Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Wed, 8 Apr 2020 09:57:19 +0200 Subject: [PATCH 06/23] StaticRoutes: Add Remove-ArubaCXStaticRoutes for remove a Static Route need to specify the vRF... --- PowerArubaCX/Public/StaticRoutes.ps1 | 61 ++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/PowerArubaCX/Public/StaticRoutes.ps1 b/PowerArubaCX/Public/StaticRoutes.ps1 index 6cc240f..1889b7c 100644 --- a/PowerArubaCX/Public/StaticRoutes.ps1 +++ b/PowerArubaCX/Public/StaticRoutes.ps1 @@ -185,6 +185,67 @@ function Get-ArubaCXStaticRoutes { $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 -vrf default + + Remove Static Route with prefix 192.0.2.0/24 + + .EXAMPLE + Remove-ArubaCXStaticRoutes -prefix 192.0.2.0/24 -confirm:$false -vrf MyVRF + + Remove Static Route 192.0.2.0/24 with no confirmation + #> + + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'high')] + Param( + [Parameter (Mandatory = $true, ParameterSetName = "name")] + [string]$prefix, + [Parameter (Mandatory = $true, ValueFromPipeline = $true, Position = 1, ParameterSetName = "route")] + [ValidateScript( { Confirm-ArubaCXStaticRoutes $_ })] + [psobject]$sr, + [Parameter(Mandatory = $true)] + [string]$vrf, + [Parameter (Mandatory = $False)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection = $DefaultArubaCXConnection + ) + + Begin { + } + + Process { + + #get prefix from static route ps object + if ($sr) { + $prefix = $sr.prefix + } + + #replace / by %2F + $prefix2 = $prefix -replace '/', '%2F' + + $uri = "system/vrfs/$vrf/static_routes/$prefix2" + + if ($PSCmdlet.ShouldProcess("Static Route", "Remove Static Route ${prefix}")) { + Write-Progress -activity "Remove Static Route" + Invoke-ArubaCXRestMethod -method "DELETE" -uri $uri -connection $connection + Write-Progress -activity "Remove Static Route" -completed + } + } + End { } } \ No newline at end of file From 28095ccda785e856aa839de77e9544de6b2362a5 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Thu, 9 Apr 2020 08:55:17 +0200 Subject: [PATCH 07/23] StaticRoutes(Add): Fix add Static Routes, need to set the full URI for vrf --- PowerArubaCX/Public/StaticRoutes.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerArubaCX/Public/StaticRoutes.ps1 b/PowerArubaCX/Public/StaticRoutes.ps1 index 1889b7c..28b7758 100644 --- a/PowerArubaCX/Public/StaticRoutes.ps1 +++ b/PowerArubaCX/Public/StaticRoutes.ps1 @@ -77,7 +77,7 @@ function Add-ArubaCXStaticRoutes { $_sr | add-member -name "type" -membertype NoteProperty -Value $type - $_sr | add-member -name "vrf" -membertype NoteProperty -Value $vrf + $_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 From c0726e7cff4167c045f6b15d0348a67db2347a68 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Thu, 9 Apr 2020 08:56:10 +0200 Subject: [PATCH 08/23] StaticRoutes(Add): Don't need to replace / on prefix when add static route --- PowerArubaCX/Public/StaticRoutes.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/PowerArubaCX/Public/StaticRoutes.ps1 b/PowerArubaCX/Public/StaticRoutes.ps1 index 28b7758..b881d3a 100644 --- a/PowerArubaCX/Public/StaticRoutes.ps1 +++ b/PowerArubaCX/Public/StaticRoutes.ps1 @@ -64,8 +64,6 @@ function Add-ArubaCXStaticRoutes { Throw "You need to specify a IPv4 Address" } $prefix = $prefix_ip4.ToString() + "/" + $prefix_ip4_mask - #replace / by %2F - $prefix = $prefix -replace '/', '%2F' $uri = "system/vrfs/$vrf/static_routes" From 33d89768448a04def497e41cbf3075a6e8b57a19 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Sun, 12 Apr 2020 19:34:34 +0200 Subject: [PATCH 09/23] Connection(Tests): Add Static Routes to Multi Connection tests --- Tests/integration/Connection.Tests.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Tests/integration/Connection.Tests.ps1 b/Tests/integration/Connection.Tests.ps1 index 185718c..cb41fc0 100644 --- a/Tests/integration/Connection.Tests.ps1 +++ b/Tests/integration/Connection.Tests.ps1 @@ -66,6 +66,9 @@ Describe "Connect to a switch (using multi connection)" { It "Use Multi connection for call Get Vrfs" { { Get-ArubaCXVrfs -connection $cx } | Should Not throw } + It "Use Multi connection for call Get Static Routes" { + { Get-ArubaCXStaticRoutes -connection $cx } | Should Not throw + } } It "Disconnect to a switch (Multi connection)" { From 42a733a2c79fd959c771ccb2b5e420489f4f0146 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Sun, 12 Apr 2020 19:59:21 +0200 Subject: [PATCH 10/23] StaticRoutes(Tests): Add Tests for Add/Get/Remove Static Routes Need to enhance vrf part (for add and remove) --- Tests/common.ps1 | 3 + Tests/integration/StaticRoutes.ps1 | 188 +++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+) create mode 100644 Tests/integration/StaticRoutes.ps1 diff --git a/Tests/common.ps1 b/Tests/common.ps1 index 98da328..2bee3ff 100644 --- a/Tests/common.ps1 +++ b/Tests/common.ps1 @@ -10,6 +10,9 @@ $script:pester_vlan = 85 #vlan id for Vlan test $script:pester_vlan2 = 86 #vlan id for Vlan test (for affect a second vlan to interface) $script:pester_interface = "1/1/1" #interface id for test... $script:pester_vrf = "pester_vrf" #interface id for test... +$script:pester_sr_ip4 = "192.0.2.0" # Network for Static Route +$script:pester_sr_mask = "24" # Netmask for Static Route +$script:pester_sr = $pester_sr_ip4 + "/" + $pester_sr_mask . ../credential.ps1 #TODO: Add check if no ipaddress/login/password info... diff --git a/Tests/integration/StaticRoutes.ps1 b/Tests/integration/StaticRoutes.ps1 new file mode 100644 index 0000000..5adfd63 --- /dev/null +++ b/Tests/integration/StaticRoutes.ps1 @@ -0,0 +1,188 @@ +# +# Copyright 2020, Alexis La Goutte +# +# SPDX-License-Identifier: Apache-2.0 +# +. ../common.ps1 + +Describe "Get Static Route" { + BeforeALL { + #Add a blackhole static route on vrf default + Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type blackhole + } + + It "Get Static Route Does not throw an error" { + { + Get-ArubaCXStaticRoutes + } | Should Not Throw + } + + It "Get ALL Static Route" { + $sr = Get-ArubaCXStaticRoutes + $sr.count | Should -Not -Be $NULL + } + + It "Get Static Route ($pester_sr)" { + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr + $sr.prefix | Should -Be $pester_sr + } + + It "Get Static Route ($pester_sr) and confirm (via Confirm-ArubaCXStaticRoutes)" { + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr + Confirm-ArubaCXStaticRoutes ($sr) | Should -Be $true + } + + #Get with attribute, depth... + Context "Selector" { + + It "Get Static Route with selector equal configuration" { + { + Get-ArubaCXStaticRoutes -selector configuration + } | Should Not Throw + } + + It "Get Static Route with selector equal statistics" { + { + Get-ArubaCXStaticRoutes -selector statistics + } | Should Not Throw + } + + It "Get Static Route with selector equal status" { + { + Get-ArubaCXStaticRoutes -selector status + } | Should Not Throw + } + + It "Get Static Route with selector equal writable" { + { + Get-ArubaCXStaticRoutes -selector writable + } | Should Not Throw + } + } + + Context "Depth" { + + It "Get Static Route with depth equal 1" { + { + Get-ArubaCXStaticRoutes -depth 1 + } | Should Not Throw + } + + It "Get Static Route with depth equal 2" { + { + Get-ArubaCXStaticRoutes -depth 2 + } | Should Not Throw + } + + It "Get Static Route with depth equal 3" { + { + Get-ArubaCXStaticRoutes -depth 3 + } | Should Not Throw + } + + It "Get Static Route with depth equal 4" { + { + Get-ArubaCXStaticRoutes -depth 4 + } | Should Not Throw + } + } + + Context "Attribute" { + + It "Get Static Route with one attribute (prefix)" { + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr -attribute prefix + @($sr).count | Should -be 1 + $sr.prefix | Should -Not -BeNullOrEmpty + } + + It "Get Static Route with two attributes (prefix, type)" { + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr -attribute prefix, type + @($sr).count | Should -be 1 + $sr.prefix | Should -Not -BeNullOrEmpty + $sr.type | Should -Not -BeNullOrEmpty + } + + } + + Context "Search" { + It "Search Static Route by name ($pester_sr)" { + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr + @($sr).count | Should -be 1 + $sr.prefix | Should -Be $pester_sr + } + + } + + AfterAll { + Get-ArubaCXStaticRoutes -prefix $pester_sr | Remove-ArubaCXStaticRoutes -vrf default -confirm:$false + #Reverse CheckPoint ? + } +} + +Describe "Add Static Route" { + + AfterEach { + Get-ArubaCXStaticRoutes -prefix $pester_sr | Remove-ArubaCXStaticRoutes -vrf default -confirm:$false + #Reverse CheckPoint ? + } + + It "Add Static Route $pester_sr (type forward)" { + Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type forward + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr + $sr.prefix | Should -Be $pester_sr + $sr.address_family | Should -Be "ipv4" + $sr.type | Should -Be "forward" + #$sr.vrf | Should -Be "default" + } + + It "Add Static Route $pester_sr (type reject)" { + Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type reject + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr + $sr.prefix | Should -Be $pester_sr + $sr.address_family | Should -Be "ipv4" + $sr.type | Should -Be "reject" + #$sr.vrf | Should -Be "default" + } + + It "Add Static Route $pester_sr (type blackhole)" { + Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type blackhole + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr + $sr.prefix | Should -Be $pester_sr + $sr.address_family | Should -Be "ipv4" + $sr.type | Should -Be "blackhole" + #$sr.vrf | Should -Be "default" + } + + #It "Add Static Route $pester_sr (type forward on $pester_vrf VRF)" { + # Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type forward -vrf $pester_vrf + # $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr + # $sr.prefix | Should -Be $pester_sr + # $sr.address_family | Should -Be "ipv4" + # $sr.type | Should -Be "blackhole" + # $sr.vrf | Should -Be $pester_vrf + #} +} + +Describe "Remove Static Route" { + + BeforeEach { + #Always add Static Route $pester_sr... + Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type blackhole + } + + It "Remove Static Route $pester_sr by prefix" { + Remove-ArubaCXStaticRoutes -prefix $pester_sr -vrf default -confirm:$false + $sr = Get-ArubaCXStaticRoutes + $sr.$pester_sr | Should -Be $NULL + } + + It "Remove Static Route $pester_sr by pipeline" { + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr + $sr | Remove-ArubaCXStaticRoutes -vrf default -confirm:$false + $sr = Get-ArubaCXStaticRoutes + $sr.$pester_sr | Should -Be $NULL + } + +} + +Disconnect-ArubaCX -confirm:$false \ No newline at end of file From bed972f60fbe292a72417a275308c3c2205e679c Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Sun, 12 Apr 2020 21:18:24 +0200 Subject: [PATCH 11/23] StaticRoutes: Fix typo (rject -> reject) --- PowerArubaCX/Public/StaticRoutes.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerArubaCX/Public/StaticRoutes.ps1 b/PowerArubaCX/Public/StaticRoutes.ps1 index b881d3a..b359f83 100644 --- a/PowerArubaCX/Public/StaticRoutes.ps1 +++ b/PowerArubaCX/Public/StaticRoutes.ps1 @@ -24,7 +24,7 @@ function Add-ArubaCXStaticRoutes { 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 rject + 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) #> From c491e2e8076d9e14310ee1c85179cc086cf9d75a Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Sun, 12 Apr 2020 21:21:12 +0200 Subject: [PATCH 12/23] StaticRoutes: Add vrf when use Get-ArubaCXStaticRoutes with prefix parameter more easy for remove after and also display ! --- PowerArubaCX/Public/StaticRoutes.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PowerArubaCX/Public/StaticRoutes.ps1 b/PowerArubaCX/Public/StaticRoutes.ps1 index b359f83..717ba0b 100644 --- a/PowerArubaCX/Public/StaticRoutes.ps1 +++ b/PowerArubaCX/Public/StaticRoutes.ps1 @@ -175,9 +175,9 @@ function Get-ArubaCXStaticRoutes { $response = Invoke-ArubaCXRestMethod -uri $uri -method 'GET' -connection $connection @invokeParams - #Add id parameter when use writable type selector - if ( $PsBoundParameters.ContainsKey('selector') -and $PsBoundParameters.ContainsKey('prefix') -and $selector -eq "writable" ) { - $response | add-member -name "prefix" -membertype NoteProperty -Value $prefix + #Add vref 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 From 31ca21cba9c23abb3711705caed91cd73ca270ea Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Sun, 12 Apr 2020 21:22:35 +0200 Subject: [PATCH 13/23] Confirm(StaticRoutes): Add check of vrf attributes --- PowerArubaCX/Private/Confirm.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/PowerArubaCX/Private/Confirm.ps1 b/PowerArubaCX/Private/Confirm.ps1 index 060c89a..1c1be1c 100644 --- a/PowerArubaCX/Private/Confirm.ps1 +++ b/PowerArubaCX/Private/Confirm.ps1 @@ -51,6 +51,9 @@ function Confirm-ArubaCXStaticRoutes { if ( -not ( $argument | get-member -name type -Membertype Properties)) { throw "Element specified does not contain a type property." } + if ( -not ( $argument | get-member -name vrf -Membertype Properties)) { + throw "Element specified does not contain a vrf property." + } $true } From a3c5fd4ef82c0abe2b169de7fdfc45d26c24b153 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Sun, 12 Apr 2020 21:25:46 +0200 Subject: [PATCH 14/23] StaticRoutes: Get vrf info from SR ps object when using pipeline --- PowerArubaCX/Public/StaticRoutes.ps1 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/PowerArubaCX/Public/StaticRoutes.ps1 b/PowerArubaCX/Public/StaticRoutes.ps1 index 717ba0b..f0ee663 100644 --- a/PowerArubaCX/Public/StaticRoutes.ps1 +++ b/PowerArubaCX/Public/StaticRoutes.ps1 @@ -210,12 +210,12 @@ function Remove-ArubaCXStaticRoutes { [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'high')] Param( - [Parameter (Mandatory = $true, ParameterSetName = "name")] + [Parameter (Mandatory = $true, ParameterSetName = "prefix")] [string]$prefix, [Parameter (Mandatory = $true, ValueFromPipeline = $true, Position = 1, ParameterSetName = "route")] [ValidateScript( { Confirm-ArubaCXStaticRoutes $_ })] [psobject]$sr, - [Parameter(Mandatory = $true)] + [Parameter(Mandatory = $true, ParameterSetName = "prefix")] [string]$vrf, [Parameter (Mandatory = $False)] [ValidateNotNullOrEmpty()] @@ -227,9 +227,10 @@ function Remove-ArubaCXStaticRoutes { Process { - #get prefix from static route ps object + #get prefix and vrf from static route ps object if ($sr) { $prefix = $sr.prefix + $vrf = $sr.vrf } #replace / by %2F @@ -237,7 +238,7 @@ function Remove-ArubaCXStaticRoutes { $uri = "system/vrfs/$vrf/static_routes/$prefix2" - if ($PSCmdlet.ShouldProcess("Static Route", "Remove Static Route ${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 From a4401eba35d7f96c512ba54db684381d7582b4e1 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Sun, 12 Apr 2020 21:26:39 +0200 Subject: [PATCH 15/23] StaticRoutes(Tests): rename for add Tests to filename --- Tests/integration/{StaticRoutes.ps1 => StaticRoutes.Tests.ps1} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Tests/integration/{StaticRoutes.ps1 => StaticRoutes.Tests.ps1} (100%) diff --git a/Tests/integration/StaticRoutes.ps1 b/Tests/integration/StaticRoutes.Tests.ps1 similarity index 100% rename from Tests/integration/StaticRoutes.ps1 rename to Tests/integration/StaticRoutes.Tests.ps1 From 3db2cf30c0eeabf8648dedabccee6be1e7de32df Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Sun, 12 Apr 2020 21:42:23 +0200 Subject: [PATCH 16/23] StaticRoutes(Tests): add first part of VRF support for Tests Static Routes But fail for remove... (need to add Context for VRF...) --- Tests/integration/StaticRoutes.Tests.ps1 | 38 +++++++++++++++--------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/Tests/integration/StaticRoutes.Tests.ps1 b/Tests/integration/StaticRoutes.Tests.ps1 index 5adfd63..3d40cb0 100644 --- a/Tests/integration/StaticRoutes.Tests.ps1 +++ b/Tests/integration/StaticRoutes.Tests.ps1 @@ -114,15 +114,21 @@ Describe "Get Static Route" { } AfterAll { - Get-ArubaCXStaticRoutes -prefix $pester_sr | Remove-ArubaCXStaticRoutes -vrf default -confirm:$false + Get-ArubaCXStaticRoutes -prefix $pester_sr | Remove-ArubaCXStaticRoutes -confirm:$false #Reverse CheckPoint ? } } Describe "Add Static Route" { + BeforeAll { + #Add Vrf + Add-ArubaCXVrfs -name $pester_vrf + + } + AfterEach { - Get-ArubaCXStaticRoutes -prefix $pester_sr | Remove-ArubaCXStaticRoutes -vrf default -confirm:$false + Get-ArubaCXStaticRoutes -prefix $pester_sr | Remove-ArubaCXStaticRoutes -confirm:$false #Reverse CheckPoint ? } @@ -132,7 +138,7 @@ Describe "Add Static Route" { $sr.prefix | Should -Be $pester_sr $sr.address_family | Should -Be "ipv4" $sr.type | Should -Be "forward" - #$sr.vrf | Should -Be "default" + $sr.vrf | Should -Be "default" } It "Add Static Route $pester_sr (type reject)" { @@ -141,7 +147,7 @@ Describe "Add Static Route" { $sr.prefix | Should -Be $pester_sr $sr.address_family | Should -Be "ipv4" $sr.type | Should -Be "reject" - #$sr.vrf | Should -Be "default" + $sr.vrf | Should -Be "default" } It "Add Static Route $pester_sr (type blackhole)" { @@ -150,17 +156,21 @@ Describe "Add Static Route" { $sr.prefix | Should -Be $pester_sr $sr.address_family | Should -Be "ipv4" $sr.type | Should -Be "blackhole" - #$sr.vrf | Should -Be "default" + $sr.vrf | Should -Be "default" } - #It "Add Static Route $pester_sr (type forward on $pester_vrf VRF)" { - # Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type forward -vrf $pester_vrf - # $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr - # $sr.prefix | Should -Be $pester_sr - # $sr.address_family | Should -Be "ipv4" - # $sr.type | Should -Be "blackhole" - # $sr.vrf | Should -Be $pester_vrf - #} + It "Add Static Route $pester_sr (type forward on $pester_vrf VRF)" { + Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type forward -vrf $pester_vrf + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr + $sr.prefix | Should -Be $pester_sr + $sr.address_family | Should -Be "ipv4" + $sr.type | Should -Be "forward" + $sr.vrf | Should -Be $pester_vrf + } + + AfterAll { + Get-ArubaCXVrfs -name $pester_vrf | Remove-ArubaCXVrfs -confirm:$false + } } Describe "Remove Static Route" { @@ -178,7 +188,7 @@ Describe "Remove Static Route" { It "Remove Static Route $pester_sr by pipeline" { $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr - $sr | Remove-ArubaCXStaticRoutes -vrf default -confirm:$false + $sr | Remove-ArubaCXStaticRoutes -confirm:$false $sr = Get-ArubaCXStaticRoutes $sr.$pester_sr | Should -Be $NULL } From 7bd8865f26ddadef746cb9bca66efb1cb7935435 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Fri, 17 Apr 2020 14:44:29 +0200 Subject: [PATCH 17/23] StaticRoutes: Add Tests with a different VRF (for Get) --- Tests/integration/StaticRoutes.Tests.ps1 | 274 ++++++++++++++++------- 1 file changed, 199 insertions(+), 75 deletions(-) diff --git a/Tests/integration/StaticRoutes.Tests.ps1 b/Tests/integration/StaticRoutes.Tests.ps1 index 3d40cb0..b7918e4 100644 --- a/Tests/integration/StaticRoutes.Tests.ps1 +++ b/Tests/integration/StaticRoutes.Tests.ps1 @@ -6,117 +6,241 @@ . ../common.ps1 Describe "Get Static Route" { - BeforeALL { - #Add a blackhole static route on vrf default - Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type blackhole - } - It "Get Static Route Does not throw an error" { - { - Get-ArubaCXStaticRoutes - } | Should Not Throw - } - It "Get ALL Static Route" { - $sr = Get-ArubaCXStaticRoutes - $sr.count | Should -Not -Be $NULL - } + Context "Get Static Route on VRF: default" { + BeforeAll { + #Add a blackhole static route on vrf default + Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type blackhole + } - It "Get Static Route ($pester_sr)" { - $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr - $sr.prefix | Should -Be $pester_sr - } + It "Get Static Route Does not throw an error" { + { + Get-ArubaCXStaticRoutes + } | Should Not Throw + } - It "Get Static Route ($pester_sr) and confirm (via Confirm-ArubaCXStaticRoutes)" { - $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr - Confirm-ArubaCXStaticRoutes ($sr) | Should -Be $true - } + It "Get ALL Static Route" { + $sr = Get-ArubaCXStaticRoutes + $sr.count | Should -Not -Be $NULL + } - #Get with attribute, depth... - Context "Selector" { + It "Get Static Route ($pester_sr)" { + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr + $sr.prefix | Should -Be $pester_sr + } - It "Get Static Route with selector equal configuration" { - { - Get-ArubaCXStaticRoutes -selector configuration - } | Should Not Throw + It "Get Static Route ($pester_sr) and confirm (via Confirm-ArubaCXStaticRoutes)" { + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr + Confirm-ArubaCXStaticRoutes ($sr) | Should -Be $true } - It "Get Static Route with selector equal statistics" { - { - Get-ArubaCXStaticRoutes -selector statistics - } | Should Not Throw + #Get with attribute, depth... + Context "Selector" { + + It "Get Static Route with selector equal configuration" { + { + Get-ArubaCXStaticRoutes -selector configuration + } | Should Not Throw + } + + It "Get Static Route with selector equal statistics" { + { + Get-ArubaCXStaticRoutes -selector statistics + } | Should Not Throw + } + + It "Get Static Route with selector equal status" { + { + Get-ArubaCXStaticRoutes -selector status + } | Should Not Throw + } + + It "Get Static Route with selector equal writable" { + { + Get-ArubaCXStaticRoutes -selector writable + } | Should Not Throw + } } - It "Get Static Route with selector equal status" { - { - Get-ArubaCXStaticRoutes -selector status - } | Should Not Throw + Context "Depth" { + + It "Get Static Route with depth equal 1" { + { + Get-ArubaCXStaticRoutes -depth 1 + } | Should Not Throw + } + + It "Get Static Route with depth equal 2" { + { + Get-ArubaCXStaticRoutes -depth 2 + } | Should Not Throw + } + + It "Get Static Route with depth equal 3" { + { + Get-ArubaCXStaticRoutes -depth 3 + } | Should Not Throw + } + + It "Get Static Route with depth equal 4" { + { + Get-ArubaCXStaticRoutes -depth 4 + } | Should Not Throw + } } - It "Get Static Route with selector equal writable" { - { - Get-ArubaCXStaticRoutes -selector writable - } | Should Not Throw + Context "Attribute" { + + It "Get Static Route with one attribute (prefix)" { + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr -attribute prefix + @($sr).count | Should -be 1 + $sr.prefix | Should -Not -BeNullOrEmpty + } + + It "Get Static Route with two attributes (prefix, type)" { + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr -attribute prefix, type + @($sr).count | Should -be 1 + $sr.prefix | Should -Not -BeNullOrEmpty + $sr.type | Should -Not -BeNullOrEmpty + } + + } + + Context "Search" { + It "Search Static Route by name ($pester_sr)" { + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr + @($sr).count | Should -be 1 + $sr.prefix | Should -Be $pester_sr + } + + } + AfterAll { + Get-ArubaCXStaticRoutes -prefix $pester_sr | Remove-ArubaCXStaticRoutes -confirm:$false } } - Context "Depth" { + Context "Get Static Route on VRF: $pester_vrf" { + BeforeALL { + #Add Vrf + Add-ArubaCXVrfs -name $pester_vrf + #Add a reject static route on vrf $pester_vrf + Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type reject -vrf $pester_vrf + } - It "Get Static Route with depth equal 1" { + It "Get Static Route Does not throw an error" { { - Get-ArubaCXStaticRoutes -depth 1 + Get-ArubaCXStaticRoutes -vrf $pester_vrf } | Should Not Throw } - It "Get Static Route with depth equal 2" { - { - Get-ArubaCXStaticRoutes -depth 2 - } | Should Not Throw + It "Get ALL Static Route" { + $sr = Get-ArubaCXStaticRoutes -vrf $pester_vrf + $sr.count | Should -Not -Be $NULL } - It "Get Static Route with depth equal 3" { - { - Get-ArubaCXStaticRoutes -depth 3 - } | Should Not Throw + It "Get Static Route ($pester_sr)" { + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr -vrf $pester_vrf + $sr.prefix | Should -Be $pester_sr + $sr.vrf | should -Be $pester_vrf } - It "Get Static Route with depth equal 4" { - { - Get-ArubaCXStaticRoutes -depth 4 - } | Should Not Throw + It "Get Static Route ($pester_sr) and confirm (via Confirm-ArubaCXStaticRoutes)" { + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr -vrf $pester_vrf + Confirm-ArubaCXStaticRoutes ($sr) | Should -Be $true } - } - Context "Attribute" { + #Get with attribute, depth... + Context "Selector" { + + It "Get Static Route with selector equal configuration" { + { + Get-ArubaCXStaticRoutes -selector configuration -vrf $pester_vrf + } | Should Not Throw + } + + It "Get Static Route with selector equal statistics" { + { + Get-ArubaCXStaticRoutes -selector statistics -vrf $pester_vrf + } | Should Not Throw + } + + It "Get Static Route with selector equal status" { + { + Get-ArubaCXStaticRoutes -selector status -vrf $pester_vrf + } | Should Not Throw + } + + It "Get Static Route with selector equal writable" { + { + Get-ArubaCXStaticRoutes -selector writable -vrf $pester_vrf + } | Should Not Throw + } + } - It "Get Static Route with one attribute (prefix)" { - $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr -attribute prefix - @($sr).count | Should -be 1 - $sr.prefix | Should -Not -BeNullOrEmpty + Context "Depth" { + + It "Get Static Route with depth equal 1" { + { + Get-ArubaCXStaticRoutes -depth 1 -vrf $pester_vrf + } | Should Not Throw + } + + It "Get Static Route with depth equal 2" { + { + Get-ArubaCXStaticRoutes -depth 2 -vrf $pester_vrf + } | Should Not Throw + } + + It "Get Static Route with depth equal 3" { + { + Get-ArubaCXStaticRoutes -depth 3 -vrf $pester_vrf + } | Should Not Throw + } + + It "Get Static Route with depth equal 4" { + { + Get-ArubaCXStaticRoutes -depth 4 -vrf $pester_vrf + } | Should Not Throw + } } - It "Get Static Route with two attributes (prefix, type)" { - $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr -attribute prefix, type - @($sr).count | Should -be 1 - $sr.prefix | Should -Not -BeNullOrEmpty - $sr.type | Should -Not -BeNullOrEmpty + Context "Attribute" { + + It "Get Static Route with one attribute (prefix)" { + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr -vrf $pester_vrf -attribute prefix + @($sr).count | Should -be 1 + $sr.prefix | Should -Not -BeNullOrEmpty + $sr.vrf | Should -Be $pester_vrf + } + + It "Get Static Route with two attributes (prefix, type)" { + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr -vrf $pester_vrf -attribute prefix, type + @($sr).count | Should -be 1 + $sr.prefix | Should -Not -BeNullOrEmpty + $sr.type | Should -Not -BeNullOrEmpty + $sr.vrf | Should -Be $pester_vrf + } + } - } + Context "Search" { + It "Search Static Route by name ($pester_sr)" { + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr -vrf $pester_vrf + @($sr).count | Should -be 1 + $sr.prefix | Should -Be $pester_sr + $sr.vrf | Should -Be $pester_vrf + } - Context "Search" { - It "Search Static Route by name ($pester_sr)" { - $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr - @($sr).count | Should -be 1 - $sr.prefix | Should -Be $pester_sr } + AfterAll { + Get-ArubaCXStaticRoutes -prefix $pester_sr -vrf $pester_vrf | Remove-ArubaCXStaticRoutes -confirm:$false + Get-ArubaCXVrfs -name $pester_vrf | Remove-ArubaCXVrfs -confirm:$false + } } - AfterAll { - Get-ArubaCXStaticRoutes -prefix $pester_sr | Remove-ArubaCXStaticRoutes -confirm:$false - #Reverse CheckPoint ? - } + } Describe "Add Static Route" { From 83e8b2467c991c75e4d2d6b0ab9f73c97c0e83e5 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Fri, 17 Apr 2020 15:06:31 +0200 Subject: [PATCH 18/23] StaticRoutes: Add Tests with a different VRF (for Add) --- Tests/integration/StaticRoutes.Tests.ps1 | 109 ++++++++++++++--------- 1 file changed, 68 insertions(+), 41 deletions(-) diff --git a/Tests/integration/StaticRoutes.Tests.ps1 b/Tests/integration/StaticRoutes.Tests.ps1 index b7918e4..3b8f276 100644 --- a/Tests/integration/StaticRoutes.Tests.ps1 +++ b/Tests/integration/StaticRoutes.Tests.ps1 @@ -245,55 +245,82 @@ Describe "Get Static Route" { Describe "Add Static Route" { - BeforeAll { - #Add Vrf - Add-ArubaCXVrfs -name $pester_vrf - } - AfterEach { - Get-ArubaCXStaticRoutes -prefix $pester_sr | Remove-ArubaCXStaticRoutes -confirm:$false - #Reverse CheckPoint ? - } + Context "Add Static Route on VRF: default" { - It "Add Static Route $pester_sr (type forward)" { - Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type forward - $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr - $sr.prefix | Should -Be $pester_sr - $sr.address_family | Should -Be "ipv4" - $sr.type | Should -Be "forward" - $sr.vrf | Should -Be "default" - } + AfterEach { + Get-ArubaCXStaticRoutes -prefix $pester_sr | Remove-ArubaCXStaticRoutes -confirm:$false + } - It "Add Static Route $pester_sr (type reject)" { - Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type reject - $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr - $sr.prefix | Should -Be $pester_sr - $sr.address_family | Should -Be "ipv4" - $sr.type | Should -Be "reject" - $sr.vrf | Should -Be "default" - } + It "Add Static Route $pester_sr (type forward)" { + Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type forward + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr + $sr.prefix | Should -Be $pester_sr + $sr.address_family | Should -Be "ipv4" + $sr.type | Should -Be "forward" + $sr.vrf | Should -Be "default" + } - It "Add Static Route $pester_sr (type blackhole)" { - Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type blackhole - $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr - $sr.prefix | Should -Be $pester_sr - $sr.address_family | Should -Be "ipv4" - $sr.type | Should -Be "blackhole" - $sr.vrf | Should -Be "default" - } + It "Add Static Route $pester_sr (type reject)" { + Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type reject + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr + $sr.prefix | Should -Be $pester_sr + $sr.address_family | Should -Be "ipv4" + $sr.type | Should -Be "reject" + $sr.vrf | Should -Be "default" + } - It "Add Static Route $pester_sr (type forward on $pester_vrf VRF)" { - Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type forward -vrf $pester_vrf - $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr - $sr.prefix | Should -Be $pester_sr - $sr.address_family | Should -Be "ipv4" - $sr.type | Should -Be "forward" - $sr.vrf | Should -Be $pester_vrf + It "Add Static Route $pester_sr (type blackhole)" { + Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type blackhole + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr + $sr.prefix | Should -Be $pester_sr + $sr.address_family | Should -Be "ipv4" + $sr.type | Should -Be "blackhole" + $sr.vrf | Should -Be "default" + } } - AfterAll { - Get-ArubaCXVrfs -name $pester_vrf | Remove-ArubaCXVrfs -confirm:$false + Context "Add Static Route on VRF: $pester_vrf" { + BeforeAll { + #Add Vrf + Add-ArubaCXVrfs -name $pester_vrf + } + + AfterEach { + Get-ArubaCXStaticRoutes -prefix $pester_sr -vrf $pester_vrf | Remove-ArubaCXStaticRoutes -confirm:$false + } + + It "Add Static Route $pester_sr (type forward)" { + Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type forward -vrf $pester_vrf + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr -vrf $pester_vrf + $sr.prefix | Should -Be $pester_sr + $sr.address_family | Should -Be "ipv4" + $sr.type | Should -Be "forward" + $sr.vrf | Should -Be $pester_vrf + } + + It "Add Static Route $pester_sr (type reject)" { + Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type reject -vrf $pester_vrf + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr -vrf $pester_vrf + $sr.prefix | Should -Be $pester_sr + $sr.address_family | Should -Be "ipv4" + $sr.type | Should -Be "reject" + $sr.vrf | Should -Be $pester_vrf + } + + It "Add Static Route $pester_sr (type blackhole)" { + Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type blackhole -vrf $pester_vrf + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr -vrf $pester_vrf + $sr.prefix | Should -Be $pester_sr + $sr.address_family | Should -Be "ipv4" + $sr.type | Should -Be "blackhole" + $sr.vrf | Should -Be $pester_vrf + } + + AfterAll { + Get-ArubaCXVrfs -name $pester_vrf | Remove-ArubaCXVrfs -confirm:$false + } } } From 59e78504a12855392ccc8e10f2bfa7ffa53b3982 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Fri, 17 Apr 2020 15:11:57 +0200 Subject: [PATCH 19/23] StaticRoutes: Add Tests with a different VRF (for Remove) --- Tests/integration/StaticRoutes.Tests.ps1 | 57 ++++++++++++++++++------ 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/Tests/integration/StaticRoutes.Tests.ps1 b/Tests/integration/StaticRoutes.Tests.ps1 index 3b8f276..46841a3 100644 --- a/Tests/integration/StaticRoutes.Tests.ps1 +++ b/Tests/integration/StaticRoutes.Tests.ps1 @@ -326,24 +326,53 @@ Describe "Add Static Route" { Describe "Remove Static Route" { - BeforeEach { - #Always add Static Route $pester_sr... - Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type blackhole - } + Context "Add Static Route on VRF: default" { + BeforeEach { + #Always add Static Route $pester_sr... + Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type blackhole + } - It "Remove Static Route $pester_sr by prefix" { - Remove-ArubaCXStaticRoutes -prefix $pester_sr -vrf default -confirm:$false - $sr = Get-ArubaCXStaticRoutes - $sr.$pester_sr | Should -Be $NULL - } + It "Remove Static Route $pester_sr by prefix" { + Remove-ArubaCXStaticRoutes -prefix $pester_sr -vrf default -confirm:$false + $sr = Get-ArubaCXStaticRoutes + $sr.$pester_sr | Should -Be $NULL + } - It "Remove Static Route $pester_sr by pipeline" { - $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr - $sr | Remove-ArubaCXStaticRoutes -confirm:$false - $sr = Get-ArubaCXStaticRoutes - $sr.$pester_sr | Should -Be $NULL + It "Remove Static Route $pester_sr by pipeline" { + $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr + $sr | Remove-ArubaCXStaticRoutes -confirm:$false + $sr = Get-ArubaCXStaticRoutes + $sr.$pester_sr | Should -Be $NULL + } } + Context "Add Static Route on VRF: $pester_vrf" { + BeforeAll { + #Add Vrf + Add-ArubaCXVrfs -name $pester_vrf + } + BeforeEach { + #Always add Static Route $pester_sr... + Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type blackhole -vrf $pester_vrf + } + + It "Remove Static Route $pester_sr by prefix" { + Remove-ArubaCXStaticRoutes -prefix $pester_sr -vrf $pester_vrf -confirm:$false + $sr = Get-ArubaCXStaticRoutes -vrf $pester_vrf + $sr.$pester_sr | Should -Be $NULL + } + + It "Remove Static Route $pester_sr by pipeline" { + $sr = Get-ArubaCXStaticRoutes -vrf $pester_vrf -prefix $pester_sr + $sr | Remove-ArubaCXStaticRoutes -confirm:$false + $sr = Get-ArubaCXStaticRoutes -vrf $pester_vrf + $sr.$pester_sr | Should -Be $NULL + } + AfterAll { + #Remove vrf + Get-ArubaCXVrfs -name $pester_vrf | Remove-ArubaCXVrfs -confirm:$false + } + } } Disconnect-ArubaCX -confirm:$false \ No newline at end of file From 7a4440cc73dbe129e4fafba9fa36d7543c2363f8 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Fri, 17 Apr 2020 15:14:23 +0200 Subject: [PATCH 20/23] StaticRoutes: Enhance Example for remove and also use better variable for prefix URI (replace / by %2F) --- PowerArubaCX/Public/StaticRoutes.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/PowerArubaCX/Public/StaticRoutes.ps1 b/PowerArubaCX/Public/StaticRoutes.ps1 index f0ee663..97b3708 100644 --- a/PowerArubaCX/Public/StaticRoutes.ps1 +++ b/PowerArubaCX/Public/StaticRoutes.ps1 @@ -198,14 +198,14 @@ function Remove-ArubaCXStaticRoutes { .EXAMPLE $sr = Get-ArubaCXStaticRoutes -prefix 192.0.2.0/24 - PS C:\>$sr | Remove-ArubaCXStaticRoutes -vrf default + PS C:\>$sr | Remove-ArubaCXStaticRoutes - Remove Static Route with prefix 192.0.2.0/24 + 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 with no confirmation + Remove Static Route 192.0.2.0/24 on MyVRF with no confirmation #> [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'high')] @@ -234,9 +234,9 @@ function Remove-ArubaCXStaticRoutes { } #replace / by %2F - $prefix2 = $prefix -replace '/', '%2F' + $uri_prefix = $prefix -replace '/', '%2F' - $uri = "system/vrfs/$vrf/static_routes/$prefix2" + $uri = "system/vrfs/$vrf/static_routes/$uri_prefix" if ($PSCmdlet.ShouldProcess("Static Route (VRF: ${vrf})", "Remove ${prefix}")) { Write-Progress -activity "Remove Static Route" From f37258cbf308d1b23508115b8764377b5bea9e65 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Sun, 19 Apr 2020 08:13:38 +0200 Subject: [PATCH 21/23] StaticRoutes(Tests): Fix blank line reported by Cedric --- Tests/integration/StaticRoutes.Tests.ps1 | 25 ++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/Tests/integration/StaticRoutes.Tests.ps1 b/Tests/integration/StaticRoutes.Tests.ps1 index 46841a3..37e6e7e 100644 --- a/Tests/integration/StaticRoutes.Tests.ps1 +++ b/Tests/integration/StaticRoutes.Tests.ps1 @@ -7,8 +7,8 @@ Describe "Get Static Route" { - Context "Get Static Route on VRF: default" { + BeforeAll { #Add a blackhole static route on vrf default Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type blackhole @@ -108,6 +108,7 @@ Describe "Get Static Route" { } Context "Search" { + It "Search Static Route by name ($pester_sr)" { $sr = Get-ArubaCXStaticRoutes -prefix $pester_sr @($sr).count | Should -be 1 @@ -115,13 +116,15 @@ Describe "Get Static Route" { } } + AfterAll { Get-ArubaCXStaticRoutes -prefix $pester_sr | Remove-ArubaCXStaticRoutes -confirm:$false } } Context "Get Static Route on VRF: $pester_vrf" { - BeforeALL { + + BeforeAll { #Add Vrf Add-ArubaCXVrfs -name $pester_vrf #Add a reject static route on vrf $pester_vrf @@ -203,6 +206,7 @@ Describe "Get Static Route" { Get-ArubaCXStaticRoutes -depth 4 -vrf $pester_vrf } | Should Not Throw } + } Context "Attribute" { @@ -231,13 +235,13 @@ Describe "Get Static Route" { $sr.prefix | Should -Be $pester_sr $sr.vrf | Should -Be $pester_vrf } - } + AfterAll { Get-ArubaCXStaticRoutes -prefix $pester_sr -vrf $pester_vrf | Remove-ArubaCXStaticRoutes -confirm:$false - Get-ArubaCXVrfs -name $pester_vrf | Remove-ArubaCXVrfs -confirm:$false } + } @@ -245,8 +249,6 @@ Describe "Get Static Route" { Describe "Add Static Route" { - - Context "Add Static Route on VRF: default" { AfterEach { @@ -279,9 +281,11 @@ Describe "Add Static Route" { $sr.type | Should -Be "blackhole" $sr.vrf | Should -Be "default" } + } Context "Add Static Route on VRF: $pester_vrf" { + BeforeAll { #Add Vrf Add-ArubaCXVrfs -name $pester_vrf @@ -321,12 +325,15 @@ Describe "Add Static Route" { AfterAll { Get-ArubaCXVrfs -name $pester_vrf | Remove-ArubaCXVrfs -confirm:$false } + } + } Describe "Remove Static Route" { Context "Add Static Route on VRF: default" { + BeforeEach { #Always add Static Route $pester_sr... Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type blackhole @@ -344,13 +351,16 @@ Describe "Remove Static Route" { $sr = Get-ArubaCXStaticRoutes $sr.$pester_sr | Should -Be $NULL } + } Context "Add Static Route on VRF: $pester_vrf" { + BeforeAll { #Add Vrf Add-ArubaCXVrfs -name $pester_vrf } + BeforeEach { #Always add Static Route $pester_sr... Add-ArubaCXStaticRoutes -address_family ipv4 -prefix_ip4 $pester_sr_ip4 -prefix_ip4_mask $pester_sr_mask -type blackhole -vrf $pester_vrf @@ -368,11 +378,14 @@ Describe "Remove Static Route" { $sr = Get-ArubaCXStaticRoutes -vrf $pester_vrf $sr.$pester_sr | Should -Be $NULL } + AfterAll { #Remove vrf Get-ArubaCXVrfs -name $pester_vrf | Remove-ArubaCXVrfs -confirm:$false } + } + } Disconnect-ArubaCX -confirm:$false \ No newline at end of file From 18f61401741b94445c5b7c2409501301f64a2a1b Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Sun, 19 Apr 2020 08:14:59 +0200 Subject: [PATCH 22/23] Confirm(Static Routes): fix typo reported by Cedric --- PowerArubaCX/Private/Confirm.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PowerArubaCX/Private/Confirm.ps1 b/PowerArubaCX/Private/Confirm.ps1 index 1c1be1c..779b4ef 100644 --- a/PowerArubaCX/Private/Confirm.ps1 +++ b/PowerArubaCX/Private/Confirm.ps1 @@ -40,10 +40,10 @@ function Confirm-ArubaCXStaticRoutes { #Check if it looks like an Static Routes element if ( -not ( $argument | get-member -name address_family -Membertype Properties)) { - throw "Element specified does not contain a address_family property." + throw "Element specified does not contain an address_family property." } if ( -not ( $argument | get-member -name prefix -Membertype Properties)) { - throw "Element specified does not contain an prefix property." + throw "Element specified does not contain a prefix property." } if ( -not ( $argument | get-member -name static_nexthops -Membertype Properties)) { throw "Element specified does not contain a static_nexthops property." From 72403b2269f461154805d9fe536b719f87f540fd Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Sun, 19 Apr 2020 08:16:52 +0200 Subject: [PATCH 23/23] StaticRoutes: fix typo reported by Cedric --- PowerArubaCX/Public/StaticRoutes.ps1 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/PowerArubaCX/Public/StaticRoutes.ps1 b/PowerArubaCX/Public/StaticRoutes.ps1 index 97b3708..06c894c 100644 --- a/PowerArubaCX/Public/StaticRoutes.ps1 +++ b/PowerArubaCX/Public/StaticRoutes.ps1 @@ -8,7 +8,7 @@ function Add-ArubaCXStaticRoutes { <# .SYNOPSIS - Add Aruba CX Static Static Route + Add Aruba CX Static Route .DESCRIPTION Add Static Route (address_family, prefix, static_nexthops, type) @@ -86,19 +86,20 @@ function Add-ArubaCXStaticRoutes { End { } } + function Get-ArubaCXStaticRoutes { <# .SYNOPSIS - Get list of all Aruba CX Route + Get list of all Aruba CX Routes .DESCRIPTION - Get list of all Aruba CX Static Rout (address_family, prefix, static_nexthops, type) + Get list of all Aruba CX Static Route (address_family, prefix, static_nexthops, type) .EXAMPLE Get-ArubaCXStaticRoutes - Get list of all Static Route information (address_family, prefix, static_nexthops, type) + Get list of all Static Routes information (address_family, prefix, static_nexthops, type) .EXAMPLE Get-ArubaCXStaticRoutes -prefix 192.0.2.0/24 @@ -175,7 +176,7 @@ function Get-ArubaCXStaticRoutes { $response = Invoke-ArubaCXRestMethod -uri $uri -method 'GET' -connection $connection @invokeParams - #Add vref parameter when use prefix (more easy to remove and also for get vrf source...) + #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 }