diff --git a/PowerArubaSW/Public/VSF.ps1 b/PowerArubaSW/Public/VSF.ps1 new file mode 100644 index 0000000..e023f7c --- /dev/null +++ b/PowerArubaSW/Public/VSF.ps1 @@ -0,0 +1,197 @@ +# +# 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. + #> + + Param( + [Parameter (Mandatory=$False)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection=$DefaultArubaSWConnection + ) + + Begin { + } + + Process { + + $uri = "rest/v4/stacking/vsf/disable" + + $response = invoke-ArubaSWWebRequest -method "POST" -uri $uri -body " " -connection $connection + + $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, + [Parameter (Mandatory=$False)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection=$DefaultArubaSWConnection + ) + + Begin { + } + + Process { + + $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 -uri $uri -connection $connection + + $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, + [Parameter (Mandatory=$False)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection=$DefaultArubaSWConnection + ) + + Begin { + } + + Process { + + $uri = "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 -uri $uri -connection $connection + + $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, + [Parameter (Mandatory=$False)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection=$DefaultArubaSWConnection + ) + + Begin { + } + + Process { + + $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 -uri $uri -connection $connection + + $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..5e5a6cc --- /dev/null +++ b/PowerArubaSW/Public/VSFConfig.ps1 @@ -0,0 +1,255 @@ +# +# 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. + #> + + Param( + [Parameter (Mandatory=$False)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection=$DefaultArubaSWConnection + ) + + Begin { + } + + Process { + + $uri = "rest/v4/stacking/vsf/global_config" + + $response = invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection + + $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]$mad_ip, + [Parameter (Mandatory=$false)] + [string]$mad_community, + [Parameter (Mandatory=$false)] + [string]$oobm_mad, + [Parameter (Mandatory=$false)] + [object]$lldp_mad, + [Parameter (Mandatory=$false)] + [switch]$lldp_mad_enable, + [Parameter (Mandatory=$False)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection=$DefaultArubaSWConnection + ) + + Begin { + } + + Process { + + $uri = "rest/v4/stacking/vsf/global_config" + + $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') ) + { + 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('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 + } + + 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_mad" -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" -uri $uri -body $vsf -connection $connection + + $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. + #> + + Param( + [Parameter (Mandatory=$False)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection=$DefaultArubaSWConnection + ) + + Begin { + } + + Process { + + $uri = "rest/v4/stacking/vsf/members" + + $response = invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection + + $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 255 -member_id 2 + Set the vsf member 2 with priority 255 on the switch. + #> + + Param( + [Parameter (Mandatory=$true)] + [ValidateRange (1,4)] + [int]$member_id, + [Parameter (Mandatory=$true)] + [ValidateRange (1,255)] + [int]$priority, + [Parameter (Mandatory=$False)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection=$DefaultArubaSWConnection + ) + + Begin { + } + + Process { + + $uri = "rest/v4/stacking/vsf/members/${member_id}" + + $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 "PUT" -body $vsf -uri $uri -connection $connection + + $run = $response | convertfrom-json + + $run + } + + End { + } +} \ No newline at end of file diff --git a/Tests/integration/VSF.Tests.ps1 b/Tests/integration/VSF.Tests.ps1 new file mode 100644 index 0000000..62c43f2 --- /dev/null +++ b/Tests/integration/VSF.Tests.ps1 @@ -0,0 +1,58 @@ +# +# 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:$false + $vsf = Get-ArubaSWVsfGlobalConfig + $vsf.domain_id | Should be "2" + $vsf.is_lldp_mad_enabled | Should be "False" + 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 + $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 + } +} + +Disconnect-ArubaSW -noconfirm \ No newline at end of file