From 9ce05673493fff4ca6d16edf75fe699056a77bd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Moreau?= Date: Fri, 21 Sep 2018 10:05:03 +0200 Subject: [PATCH 1/8] Add Function VSF --- PowerArubaSW/Public/VSF.ps1 | 182 ++++++++++++++++++++++++++ PowerArubaSW/Public/VSFConfig.ps1 | 208 ++++++++++++++++++++++++++++++ 2 files changed, 390 insertions(+) create mode 100644 PowerArubaSW/Public/VSF.ps1 create mode 100644 PowerArubaSW/Public/VSFConfig.ps1 diff --git a/PowerArubaSW/Public/VSF.ps1 b/PowerArubaSW/Public/VSF.ps1 new file mode 100644 index 0000000..820e514 --- /dev/null +++ b/PowerArubaSW/Public/VSF.ps1 @@ -0,0 +1,182 @@ +# +# Copyright 2018, Alexis La Goutte +# Copyright 2018, C�dric Moreau +# +# SPDX-License-Identifier: Apache-2.0 +# + +function Set-ArubaSWVsfDisable { + + <# + .SYNOPSIS + Set Vsf Disable on ArubaOS Switch. + + .DESCRIPTION + Set Vsf Disable on ArubaOS Switch. + + .EXAMPLE + Set-ArubaSWVsfDisable + Set the vsf disable on the switch. + #> + + Begin { + } + + Process { + + $url = "rest/v4/stacking/vsf/disable" + + $response = invoke-ArubaSWWebRequest -method "POST" -url $url + + $run = $response | convertfrom-json + + $run + } + + End { + } +} + +function Set-ArubaSWVsfEnable { + + <# + .SYNOPSIS + Set Vsf enable on ArubaOS Switch. + + .DESCRIPTION + Set Vsf enable on ArubaOS Switch. + + .EXAMPLE + Set-ArubaSWVsfEnable -domain_id 1 + Set the vsf enable on the switch with the domain id 1. + #> + + Param( + [Parameter (Mandatory=$true)] + [ValidateRange (1,4294967295)] + [int]$domain_id + ) + + Begin { + } + + Process { + + $url = "rest/v4/stacking/vsf/enable" + + $vsf = new-Object -TypeName PSObject + + $vsf | add-member -name "domain_id" -membertype NoteProperty -Value $domain_id + + $response = invoke-ArubaSWWebRequest -method "POST" -body $vsf -url $url + + $run = $response | convertfrom-json + + $run + } + + End { + } +} + +function Remove-ArubaSWVsfMember { + + <# + .SYNOPSIS + Remove the vsf member on ArubaOS Switch. + + .DESCRIPTION + Remove the vsf member with the member id and reboot or shutdown the member on ArubaOS Switch. + The parameter -action has two different value : reboot to reboot the switch, or shutdown to shutdown the switch. + + .EXAMPLE + Remove-ArubaSWVsfMember -member 1 -action reboot + Remove the vsf member on the switch with the member id 1 and reboot it. + #> + + Param( + [Parameter (Mandatory=$true)] + [ValidateRange (1,4)] + [int]$member, + [Parameter (Mandatory=$true)] + [ValidateSet ("reboot", "shutdown")] + [string]$action + ) + + Begin { + } + + Process { + + $url = "rest/v4/stacking/vsf/member/remove" + + $vsf = new-Object -TypeName PSObject + + if ( $PsBoundParameters.ContainsKey('reboot') ) + { + switch( $action ) { + reboot { + $action_status = $true + } + shudown { + $action_status = $false + } + } + + $vsf | add-member -name "reboot" -membertype NoteProperty -Value $action_status + } + + $vsf | add-member -name "member_id" -membertype NoteProperty -Value $member + + $response = invoke-ArubaSWWebRequest -method "POST" -body $vsf -url $url + + $run = $response | convertfrom-json + + $run + } + + End { + } +} + +function Send-ArubaSWVsfShutdown { + + <# + .SYNOPSIS + Shutdown the vsf member on ArubaOS Switch. + + .DESCRIPTION + Shutdown the vsf member with the member id on ArubaOS Switch. + + .EXAMPLE + Send-ArubaSWVsfShutdown -member 1 + Shutdown the vsf member on the switch with the member id 1. + #> + + Param( + [Parameter (Mandatory=$true)] + [ValidateRange (1,4)] + [int]$member + ) + + Begin { + } + + Process { + + $url = "rest/v4/stacking/vsf/member/shutdown" + + $vsf = new-Object -TypeName PSObject + + $vsf | add-member -name "member_id" -membertype NoteProperty -Value $member + + $response = invoke-ArubaSWWebRequest -method "POST" -body $vsf -url $url + + $run = $response | convertfrom-json + + $run + } + + End { + } +} \ No newline at end of file diff --git a/PowerArubaSW/Public/VSFConfig.ps1 b/PowerArubaSW/Public/VSFConfig.ps1 new file mode 100644 index 0000000..dd4c595 --- /dev/null +++ b/PowerArubaSW/Public/VSFConfig.ps1 @@ -0,0 +1,208 @@ +# +# Copyright 2018, Alexis La Goutte +# Copyright 2018, Cédric Moreau +# +# SPDX-License-Identifier: Apache-2.0 +# + +function Get-ArubaSWVsfGlobalConfig { + + <# + .SYNOPSIS + Get Vsf global configuration on ArubaOS Switch. + + .DESCRIPTION + Get all the vsf global configuration on ArubaOS Switch. + + .EXAMPLE + Get-ArubaSWVsfGlobalConfig + Get the vsf global configuration on the switch. + #> + + Begin { + } + + Process { + + $url = "rest/v4/stacking/vsf/global_config" + + $response = invoke-ArubaSWWebRequest -method "GET" -url $url + + $run = $response | convertfrom-json + + $run + } + + End { + } +} + +function Set-ArubaSWVsfGlobalConfig { + + <# + .SYNOPSIS + Set Vsf global configuration on ArubaOS Switch. + + .DESCRIPTION + Set all the vsf global configuration on ArubaOS Switch. + + .EXAMPLE + Set-ArubaSWVsfGlobalConfig + Set the vsf global configuration on the switch. + #> + + Param( + [Parameter (Mandatory=$true)] + [ValidateRange (1,4294967295)] + [int]$domain_id, + [Parameter (Mandatory=$false)] + [ValidateSet ("1", "10", "40", "auto")] + [string]$port_speed, + [Parameter (Mandatory=$false)] + [ValidateRange (1,4094)] + [int]$mad_vlan, + [Parameter (Mandatory=$false)] + [string]$oobm_mad, + [Parameter (Mandatory=$false)] + [int]$lldp_mad, + [Parameter (Mandatory=$false)] + [ValidateSet ("True", "False")] + [string]$lldp_mad_enable + ) + + Begin { + } + + Process { + + $url = "rest/v4/stacking/vsf/global_config" + + $vsf = new-Object -TypeName PSObject + + $vsf | add-member -name "domain_id" -membertype NoteProperty -Value $domain_id + + if ( $PsBoundParameters.ContainsKey('port_speed') ) + { + switch( $port_speed ) { + 1 { + $port_speed = "PS_1G" + } + 10 { + $port_speed = "PS_10G" + } + 40 { + $port_speed = "PS_40G" + } + auto { + $port_speed = "PS_AUTO" + } + } + $vsf | add-member -name "port_speed" -membertype NoteProperty -Value $port_speed + } + + if ( $PsBoundParameters.ContainsKey('mad_vlan') ) + { + $vsf | add-member -name "mad_vlan" -membertype NoteProperty -Value $mad_vlan + } + + if ( $PsBoundParameters.ContainsKey('oobm_mad') ) + { + switch( $oobm_mad ) { + ON { + $oobm_mad = $true + } + OFF { + $oobm_mad = $false + } + } + $vsf | add-member -name "is_oobm_mad_enabled" -membertype NoteProperty -Value $oobm_mad + } + $response = invoke-ArubaSWWebRequest -method "PUT" -url $url + + $run = $response | convertfrom-json + + $run + } + + End { + } +} + +function Get-ArubaSWVsfMembers { + + <# + .SYNOPSIS + Get Vsf members on ArubaOS Switch. + + .DESCRIPTION + Get all the vsf members on ArubaOS Switch. + + .EXAMPLE + Get-ArubaSWVsfMembers + Get the vsf members on the switch. + #> + + Begin { + } + + Process { + + $url = "rest/v4/stacking/vsf/members" + + $response = invoke-ArubaSWWebRequest -method "GET" -url $url + + $run = $response | convertfrom-json + + $run + } + + End { + } +} + +function Set-ArubaSWVsfMember { + + <# + .SYNOPSIS + Set Vsf member on ArubaOS Switch. + + .DESCRIPTION + Set the vsf member on ArubaOS Switch. + + .EXAMPLE + Set-ArubaSWVsfMember -priority -member_id + Set the vsf member on the switch. + #> + + Param( + [Parameter (Mandatory=$true)] + [ValidateRange (1,4)] + [int]$member_id, + [Parameter (Mandatory=$true)] + [ValidateRange (1,255)] + [string]$priority + ) + + Begin { + } + + Process { + + $url = "rest/v4/stacking/vsf/members" + + $vsf = new-Object -TypeName PSObject + + $vsf | add-member -name "member_id" -membertype NoteProperty -Value $member_id + + $vsf | add-member -name "priority" -membertype NoteProperty -Value $priority + + $response = invoke-ArubaSWWebRequest -method "POST" -body $vsf -url $url + + $run = $response | convertfrom-json + + $run + } + + End { + } +} \ No newline at end of file From 1ef063e0ba43980862132141da1605c9ee3a9dc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Moreau?= Date: Fri, 22 Feb 2019 15:03:58 +0100 Subject: [PATCH 2/8] Add test for VSF --- Tests/integration/VSF.Tests.ps1 | 57 +++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Tests/integration/VSF.Tests.ps1 diff --git a/Tests/integration/VSF.Tests.ps1 b/Tests/integration/VSF.Tests.ps1 new file mode 100644 index 0000000..f6d4a92 --- /dev/null +++ b/Tests/integration/VSF.Tests.ps1 @@ -0,0 +1,57 @@ +# +# Copyright 2019, Alexis La Goutte +# Copyright 2019, Cédric Moreau +# +# SPDX-License-Identifier: Apache-2.0 +# +..\common.ps1 + +Describe "Get VSF global config" { + It "Get ArubaSWVsfGlobalConfig Does not throw an error" { + { + Get-ArubaSWVsfGlobalConfig + } | Should Not Throw + } + + It "Get-ArubaSWVsfGlobalConfig" { + $vsf = Get-ArubaSWVsfGlobalConfig + $vsf | Should not be $NULL + } +} + +Describe "Set-ArubaSWVsfGlobalConfig" { + It "Change VSF global config value" { + $default = Get-ArubaSWVsfGlobalConfig + Set-ArubaSWVsfGlobalConfig -domain_id 2 -lldp_mad_enable True + $vsf = Get-ArubaSWVsfGlobalConfig + $vsf.domain_id | Should be "2" + $vsf.is_lldp_mad_enabled | Should be "True" + Set-ArubaSWVsfGlobalConfig -domain_id $default.domain_id -lldp_mad_enable $default.is_lldp_mad_enabled + } +} + +Describe "Get VSF members" { + It "Get ArubaSWVsfGlobalConfig Does not throw an error" { + { + Get-ArubaSWVsfMembers + } | Should Not Throw + } + + It "Get-ArubaSWVsfMembers" { + $vsfmem = Get-ArubaSWVsfMembers + $vsfmem | Should not be $NULL + } +} + +Describe "Set-ArubaSWVsfMember" { + It "Change VSF member value" { + $default = Get-ArubaSWVsfMembers + Set-ArubaSWVsfMember -member_id 1 -priority 255 + $vsfme = Get-ArubaSWVsfMembers | Where-Object member_id -eq 1 + $vsfme.member_id | Should be "1" + $vsfme.priority | Should be "255" + Set-ArubaSWVsfMember -domain_id $default.domain_id -lldp_mad_enable $default.is_lldp_mad_enabled + } +} + +Disconnect-ArubaSW -noconfirm \ No newline at end of file From da5c9f7434464305f324541aaa3e545708bb2119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Moreau?= Date: Fri, 22 Feb 2019 17:19:59 +0100 Subject: [PATCH 3/8] Fix for disable vsf --- PowerArubaSW/Public/VSF.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerArubaSW/Public/VSF.ps1 b/PowerArubaSW/Public/VSF.ps1 index 820e514..ed215f9 100644 --- a/PowerArubaSW/Public/VSF.ps1 +++ b/PowerArubaSW/Public/VSF.ps1 @@ -26,7 +26,7 @@ function Set-ArubaSWVsfDisable { $url = "rest/v4/stacking/vsf/disable" - $response = invoke-ArubaSWWebRequest -method "POST" -url $url + $response = invoke-ArubaSWWebRequest -method "POST" -url $url -body " " $run = $response | convertfrom-json From 7e87e07d31e32d951532ea26b70dd313cee8cffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Moreau?= Date: Mon, 1 Apr 2019 15:33:12 +0200 Subject: [PATCH 4/8] fix a typo --- Tests/integration/VSF.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/integration/VSF.Tests.ps1 b/Tests/integration/VSF.Tests.ps1 index f6d4a92..229622e 100644 --- a/Tests/integration/VSF.Tests.ps1 +++ b/Tests/integration/VSF.Tests.ps1 @@ -4,7 +4,7 @@ # # SPDX-License-Identifier: Apache-2.0 # -..\common.ps1 +. ..\common.ps1 Describe "Get VSF global config" { It "Get ArubaSWVsfGlobalConfig Does not throw an error" { From 1b949d30de901dcbf74a4c1af093487661ba8767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Moreau?= Date: Fri, 5 Apr 2019 17:08:37 +0200 Subject: [PATCH 5/8] Fix some major issues --- PowerArubaSW/Public/VSFConfig.ps1 | 47 +++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/PowerArubaSW/Public/VSFConfig.ps1 b/PowerArubaSW/Public/VSFConfig.ps1 index dd4c595..8f07752 100644 --- a/PowerArubaSW/Public/VSFConfig.ps1 +++ b/PowerArubaSW/Public/VSFConfig.ps1 @@ -62,12 +62,15 @@ function Set-ArubaSWVsfGlobalConfig { [ValidateRange (1,4094)] [int]$mad_vlan, [Parameter (Mandatory=$false)] + [string]$mad_ip, + [Parameter (Mandatory=$false)] + [string]$mad_community, + [Parameter (Mandatory=$false)] [string]$oobm_mad, [Parameter (Mandatory=$false)] - [int]$lldp_mad, + [object]$lldp_mad, [Parameter (Mandatory=$false)] - [ValidateSet ("True", "False")] - [string]$lldp_mad_enable + [switch]$lldp_mad_enable ) Begin { @@ -79,6 +82,10 @@ function Set-ArubaSWVsfGlobalConfig { $vsf = new-Object -TypeName PSObject + $ip = New-Object -TypeName PSObject + + $mad = New-Object -TypeName PSObject + $vsf | add-member -name "domain_id" -membertype NoteProperty -Value $domain_id if ( $PsBoundParameters.ContainsKey('port_speed') ) @@ -100,11 +107,6 @@ function Set-ArubaSWVsfGlobalConfig { $vsf | add-member -name "port_speed" -membertype NoteProperty -Value $port_speed } - if ( $PsBoundParameters.ContainsKey('mad_vlan') ) - { - $vsf | add-member -name "mad_vlan" -membertype NoteProperty -Value $mad_vlan - } - if ( $PsBoundParameters.ContainsKey('oobm_mad') ) { switch( $oobm_mad ) { @@ -117,7 +119,34 @@ function Set-ArubaSWVsfGlobalConfig { } $vsf | add-member -name "is_oobm_mad_enabled" -membertype NoteProperty -Value $oobm_mad } - $response = invoke-ArubaSWWebRequest -method "PUT" -url $url + + if ( $PsBoundParameters.ContainsKey('lldp_mad_enable') ) { + if ( $lldp_mad_enable ) { + $vsf | add-member -name "is_lldp_mad_enabled" -membertype NoteProperty -Value $True + } else { + $vsf | add-member -name "is_lldp_mad_enabled" -membertype NoteProperty -Value $false + } + } + + if ($PsBoundParameters.ContainsKey('mad_ip')) + { + $ip | add-member -name "version" -MemberType NoteProperty -Value "IAV_IP_V4" + + $ip | add-member -name "octets" -MemberType NoteProperty -Value $mad_ip + + $mad | add-member -name "mad_ip" -MemberType NoteProperty -Value $ip + + $mad | add-member -name "community_name" -MemberType NoteProperty -Value $mad_community + + $vsf | add-member -name "lldp_vlan" -membertype NoteProperty -Value $mad + } + + if ( $PsBoundParameters.ContainsKey('mad_vlan') ) + { + $vsf | add-member -name "mad_vlan" -membertype NoteProperty -Value $mad_vlan + } + + $response = invoke-ArubaSWWebRequest -method "PUT" -url $url -body $vsf $run = $response | convertfrom-json From 9bde58d9d07175c78cff06377b24d5e3b9821f97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Moreau?= Date: Wed, 9 Oct 2019 14:17:25 +0200 Subject: [PATCH 6/8] Change Url to Uri and add support of multiconnections --- PowerArubaSW/Public/VSF.ps1 | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/PowerArubaSW/Public/VSF.ps1 b/PowerArubaSW/Public/VSF.ps1 index ed215f9..e023f7c 100644 --- a/PowerArubaSW/Public/VSF.ps1 +++ b/PowerArubaSW/Public/VSF.ps1 @@ -19,14 +19,20 @@ function Set-ArubaSWVsfDisable { Set the vsf disable on the switch. #> + Param( + [Parameter (Mandatory=$False)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection=$DefaultArubaSWConnection + ) + Begin { } Process { - $url = "rest/v4/stacking/vsf/disable" + $uri = "rest/v4/stacking/vsf/disable" - $response = invoke-ArubaSWWebRequest -method "POST" -url $url -body " " + $response = invoke-ArubaSWWebRequest -method "POST" -uri $uri -body " " -connection $connection $run = $response | convertfrom-json @@ -54,7 +60,10 @@ function Set-ArubaSWVsfEnable { Param( [Parameter (Mandatory=$true)] [ValidateRange (1,4294967295)] - [int]$domain_id + [int]$domain_id, + [Parameter (Mandatory=$False)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection=$DefaultArubaSWConnection ) Begin { @@ -62,13 +71,13 @@ function Set-ArubaSWVsfEnable { Process { - $url = "rest/v4/stacking/vsf/enable" + $uri = "rest/v4/stacking/vsf/enable" $vsf = new-Object -TypeName PSObject $vsf | add-member -name "domain_id" -membertype NoteProperty -Value $domain_id - $response = invoke-ArubaSWWebRequest -method "POST" -body $vsf -url $url + $response = invoke-ArubaSWWebRequest -method "POST" -body $vsf -uri $uri -connection $connection $run = $response | convertfrom-json @@ -100,7 +109,10 @@ function Remove-ArubaSWVsfMember { [int]$member, [Parameter (Mandatory=$true)] [ValidateSet ("reboot", "shutdown")] - [string]$action + [string]$action, + [Parameter (Mandatory=$False)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection=$DefaultArubaSWConnection ) Begin { @@ -108,7 +120,7 @@ function Remove-ArubaSWVsfMember { Process { - $url = "rest/v4/stacking/vsf/member/remove" + $uri = "rest/v4/stacking/vsf/member/remove" $vsf = new-Object -TypeName PSObject @@ -128,7 +140,7 @@ function Remove-ArubaSWVsfMember { $vsf | add-member -name "member_id" -membertype NoteProperty -Value $member - $response = invoke-ArubaSWWebRequest -method "POST" -body $vsf -url $url + $response = invoke-ArubaSWWebRequest -method "POST" -body $vsf -uri $uri -connection $connection $run = $response | convertfrom-json @@ -156,7 +168,10 @@ function Send-ArubaSWVsfShutdown { Param( [Parameter (Mandatory=$true)] [ValidateRange (1,4)] - [int]$member + [int]$member, + [Parameter (Mandatory=$False)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection=$DefaultArubaSWConnection ) Begin { @@ -164,13 +179,13 @@ function Send-ArubaSWVsfShutdown { Process { - $url = "rest/v4/stacking/vsf/member/shutdown" + $uri = "rest/v4/stacking/vsf/member/shutdown" $vsf = new-Object -TypeName PSObject $vsf | add-member -name "member_id" -membertype NoteProperty -Value $member - $response = invoke-ArubaSWWebRequest -method "POST" -body $vsf -url $url + $response = invoke-ArubaSWWebRequest -method "POST" -body $vsf -uri $uri -connection $connection $run = $response | convertfrom-json From 58f8a089d4e1d6f036eac89fa0c9828badaa4565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Moreau?= Date: Thu, 10 Oct 2019 09:49:26 +0200 Subject: [PATCH 7/8] Add support of multiconnection on VsfConfig and change url to uri --- PowerArubaSW/Public/VSFConfig.ps1 | 38 +++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/PowerArubaSW/Public/VSFConfig.ps1 b/PowerArubaSW/Public/VSFConfig.ps1 index 8f07752..25867ba 100644 --- a/PowerArubaSW/Public/VSFConfig.ps1 +++ b/PowerArubaSW/Public/VSFConfig.ps1 @@ -19,14 +19,20 @@ function Get-ArubaSWVsfGlobalConfig { Get the vsf global configuration on the switch. #> + Param( + [Parameter (Mandatory=$False)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection=$DefaultArubaSWConnection + ) + Begin { } Process { - $url = "rest/v4/stacking/vsf/global_config" + $uri = "rest/v4/stacking/vsf/global_config" - $response = invoke-ArubaSWWebRequest -method "GET" -url $url + $response = invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection $run = $response | convertfrom-json @@ -70,7 +76,10 @@ function Set-ArubaSWVsfGlobalConfig { [Parameter (Mandatory=$false)] [object]$lldp_mad, [Parameter (Mandatory=$false)] - [switch]$lldp_mad_enable + [switch]$lldp_mad_enable, + [Parameter (Mandatory=$False)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection=$DefaultArubaSWConnection ) Begin { @@ -78,7 +87,7 @@ function Set-ArubaSWVsfGlobalConfig { Process { - $url = "rest/v4/stacking/vsf/global_config" + $uri = "rest/v4/stacking/vsf/global_config" $vsf = new-Object -TypeName PSObject @@ -146,7 +155,7 @@ function Set-ArubaSWVsfGlobalConfig { $vsf | add-member -name "mad_vlan" -membertype NoteProperty -Value $mad_vlan } - $response = invoke-ArubaSWWebRequest -method "PUT" -url $url -body $vsf + $response = invoke-ArubaSWWebRequest -method "PUT" -uri $uri -body $vsf -connection $connection $run = $response | convertfrom-json @@ -171,14 +180,20 @@ function Get-ArubaSWVsfMembers { Get the vsf members on the switch. #> + Param( + [Parameter (Mandatory=$False)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection=$DefaultArubaSWConnection + ) + Begin { } Process { - $url = "rest/v4/stacking/vsf/members" + $uri = "rest/v4/stacking/vsf/members" - $response = invoke-ArubaSWWebRequest -method "GET" -url $url + $response = invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection $run = $response | convertfrom-json @@ -209,7 +224,10 @@ function Set-ArubaSWVsfMember { [int]$member_id, [Parameter (Mandatory=$true)] [ValidateRange (1,255)] - [string]$priority + [string]$priority, + [Parameter (Mandatory=$False)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection=$DefaultArubaSWConnection ) Begin { @@ -217,7 +235,7 @@ function Set-ArubaSWVsfMember { Process { - $url = "rest/v4/stacking/vsf/members" + $uri = "rest/v4/stacking/vsf/members" $vsf = new-Object -TypeName PSObject @@ -225,7 +243,7 @@ function Set-ArubaSWVsfMember { $vsf | add-member -name "priority" -membertype NoteProperty -Value $priority - $response = invoke-ArubaSWWebRequest -method "POST" -body $vsf -url $url + $response = invoke-ArubaSWWebRequest -method "POST" -body $vsf -uri $uri -connection $connection $run = $response | convertfrom-json From eca2f3c94d3f8cc851f47eb0c4a344261129ee01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Moreau?= Date: Thu, 10 Oct 2019 10:42:25 +0200 Subject: [PATCH 8/8] Fix some errors in tests and function, now set-arubaswvsfmember works normally --- PowerArubaSW/Public/VSFConfig.ps1 | 14 +++++++------- Tests/integration/VSF.Tests.ps1 | 13 +++++++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/PowerArubaSW/Public/VSFConfig.ps1 b/PowerArubaSW/Public/VSFConfig.ps1 index 25867ba..5e5a6cc 100644 --- a/PowerArubaSW/Public/VSFConfig.ps1 +++ b/PowerArubaSW/Public/VSFConfig.ps1 @@ -131,7 +131,7 @@ function Set-ArubaSWVsfGlobalConfig { if ( $PsBoundParameters.ContainsKey('lldp_mad_enable') ) { if ( $lldp_mad_enable ) { - $vsf | add-member -name "is_lldp_mad_enabled" -membertype NoteProperty -Value $True + $vsf | add-member -name "is_lldp_mad_enabled" -membertype NoteProperty -Value $true } else { $vsf | add-member -name "is_lldp_mad_enabled" -membertype NoteProperty -Value $false } @@ -147,7 +147,7 @@ function Set-ArubaSWVsfGlobalConfig { $mad | add-member -name "community_name" -MemberType NoteProperty -Value $mad_community - $vsf | add-member -name "lldp_vlan" -membertype NoteProperty -Value $mad + $vsf | add-member -name "lldp_mad" -membertype NoteProperty -Value $mad } if ( $PsBoundParameters.ContainsKey('mad_vlan') ) @@ -214,8 +214,8 @@ function Set-ArubaSWVsfMember { Set the vsf member on ArubaOS Switch. .EXAMPLE - Set-ArubaSWVsfMember -priority -member_id - Set the vsf member on the switch. + Set-ArubaSWVsfMember -priority 255 -member_id 2 + Set the vsf member 2 with priority 255 on the switch. #> Param( @@ -224,7 +224,7 @@ function Set-ArubaSWVsfMember { [int]$member_id, [Parameter (Mandatory=$true)] [ValidateRange (1,255)] - [string]$priority, + [int]$priority, [Parameter (Mandatory=$False)] [ValidateNotNullOrEmpty()] [PSObject]$connection=$DefaultArubaSWConnection @@ -235,7 +235,7 @@ function Set-ArubaSWVsfMember { Process { - $uri = "rest/v4/stacking/vsf/members" + $uri = "rest/v4/stacking/vsf/members/${member_id}" $vsf = new-Object -TypeName PSObject @@ -243,7 +243,7 @@ function Set-ArubaSWVsfMember { $vsf | add-member -name "priority" -membertype NoteProperty -Value $priority - $response = invoke-ArubaSWWebRequest -method "POST" -body $vsf -uri $uri -connection $connection + $response = invoke-ArubaSWWebRequest -method "PUT" -body $vsf -uri $uri -connection $connection $run = $response | convertfrom-json diff --git a/Tests/integration/VSF.Tests.ps1 b/Tests/integration/VSF.Tests.ps1 index 229622e..62c43f2 100644 --- a/Tests/integration/VSF.Tests.ps1 +++ b/Tests/integration/VSF.Tests.ps1 @@ -22,10 +22,10 @@ Describe "Get VSF global config" { Describe "Set-ArubaSWVsfGlobalConfig" { It "Change VSF global config value" { $default = Get-ArubaSWVsfGlobalConfig - Set-ArubaSWVsfGlobalConfig -domain_id 2 -lldp_mad_enable True + Set-ArubaSWVsfGlobalConfig -domain_id 2 -lldp_mad_enable:$false $vsf = Get-ArubaSWVsfGlobalConfig $vsf.domain_id | Should be "2" - $vsf.is_lldp_mad_enabled | Should be "True" + $vsf.is_lldp_mad_enabled | Should be "False" Set-ArubaSWVsfGlobalConfig -domain_id $default.domain_id -lldp_mad_enable $default.is_lldp_mad_enabled } } @@ -47,10 +47,11 @@ Describe "Set-ArubaSWVsfMember" { It "Change VSF member value" { $default = Get-ArubaSWVsfMembers Set-ArubaSWVsfMember -member_id 1 -priority 255 - $vsfme = Get-ArubaSWVsfMembers | Where-Object member_id -eq 1 - $vsfme.member_id | Should be "1" - $vsfme.priority | Should be "255" - Set-ArubaSWVsfMember -domain_id $default.domain_id -lldp_mad_enable $default.is_lldp_mad_enabled + $vsf = Get-ArubaSWVsfMembers + $vsfmember = $vsf.vsf_member_element | Where-Object member_id -eq 1 + $vsfmember.member_id | Should be "1" + $vsfmember.priority | Should be "255" + Set-ArubaSWVsfMember -member_id $default.vsf_member_element.member_id -priority $default.vsf_member_element.priority } }