diff --git a/PowerArubaSW/Private/Webrequest.ps1 b/PowerArubaSW/Private/Webrequest.ps1 index f05788d..1280756 100644 --- a/PowerArubaSW/Private/Webrequest.ps1 +++ b/PowerArubaSW/Private/Webrequest.ps1 @@ -13,19 +13,29 @@ function Invoke-ArubaSWWebRequest() { Invoke WebRequest with ArubaSW connection variable (IP Address, cookie, port...) .EXAMPLE - Invoke-ArubaSWWebRequest -method "get" -uri "rest/v4/vlan" + Invoke-ArubaSWWebRequest -method "get" -uri "vlan" - Invoke-WebRequest with ArubaSW connection for get rest/v4/vlan + Invoke-WebRequest with ArubaSW connection for get rest/vX/vlan .EXAMPLE - Invoke-ArubaSWWebRequest "rest/v4/system" + Invoke-ArubaSWWebRequest "system" - Invoke-WebRequest with ArubaSW connection for get rest/v4/system uri with default GET method parameter + Invoke-WebRequest with ArubaSW connection for get rest/vX/system uri with default GET method parameter .EXAMPLE - Invoke-ArubaSWWebRequest -method "post" -uri "rest/v4/system" -body $body + Invoke-ArubaSWWebRequest -method "post" -uri "system" -body $body - Invoke-WebRequest with ArubaSW connection for post rest/v4/system uri with $body payload + Invoke-WebRequest with ArubaSW connection for post est/vX/ssystem uri with $body payload + + .EXAMPLE + Invoke-ArubaSWWebRequest -method "get" -uri "system" -api_version 4 + + Invoke-WebRequest with ArubaSW connection for get rest/v4/ssystem uri + + .EXAMPLE + Invoke-ArubaSWWebRequest -method "get" -uri "/rest/v8/system" -api_version 0 + + Invoke-WebRequest with ArubaSW connection for get /rest/v8/system uri #> @@ -36,6 +46,9 @@ function Invoke-ArubaSWWebRequest() { [ValidateSet("GET", "POST", "DELETE", "PUT")] [String]$method = "get", [Parameter(Mandatory = $false)] + [ValidateRange(0, 10)] + [int]$api_version, + [Parameter(Mandatory = $false)] [psobject]$body, [Parameter(Mandatory = $false)] [psobject]$connection @@ -60,12 +73,25 @@ function Invoke-ArubaSWWebRequest() { $sessionvariable = $connection.session if ($httpOnly) { - $fullurl = "http://${Server}:${port}/${uri}" + $fullurl = "http://${Server}:${port}/" } else { - $fullurl = "https://${Server}:${port}/${uri}" + $fullurl = "https://${Server}:${port}/" } + if ( $PsBoundParameters.ContainsKey('api_version') ) { + #Not Equal to 0, we add $api_version (if 0 we don't add rest info..) + if ($api_version -ne "0") { + $fullurl += "rest/v" + $api_version + "/" + } + } + else { + #Get info from connection + $fullurl += "rest/v" + $connection.api_version.cur + "/" + } + + $fullurl += $uri + try { if ($body) { diff --git a/PowerArubaSW/Public/Banner.ps1 b/PowerArubaSW/Public/Banner.ps1 index 59772bf..acc80e3 100644 --- a/PowerArubaSW/Public/Banner.ps1 +++ b/PowerArubaSW/Public/Banner.ps1 @@ -32,7 +32,7 @@ function Get-ArubaSWBanner { Process { - $uri = "rest/v4/banner" + $uri = "banner" $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection @@ -105,7 +105,7 @@ function Set-ArubaSWBanner { } Process { - $uri = "rest/v4/banner" + $uri = "banner" $banner = New-Object -TypeName PSObject diff --git a/PowerArubaSW/Public/CLI.ps1 b/PowerArubaSW/Public/CLI.ps1 index c1e46b0..a0cbba3 100644 --- a/PowerArubaSW/Public/CLI.ps1 +++ b/PowerArubaSW/Public/CLI.ps1 @@ -47,7 +47,7 @@ function Get-ArubaSWCli { Process { - $uri = "rest/v4/cli" + $uri = "cli" $run = New-Object -TypeName PSObject @@ -120,7 +120,7 @@ function Send-ArubaSWCliBatch { $nb = $nb + 1 } - $uri = "rest/v4/cli_batch" + $uri = "cli_batch" $conf = New-Object -TypeName PSObject @@ -167,7 +167,7 @@ function Get-ArubaSWCliBatchStatus { Process { - $uri = "rest/v4/cli_batch/status" + $uri = "cli_batch/status" $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection diff --git a/PowerArubaSW/Public/Connection.ps1 b/PowerArubaSW/Public/Connection.ps1 index 5ade3a1..fb60cd5 100644 --- a/PowerArubaSW/Public/Connection.ps1 +++ b/PowerArubaSW/Public/Connection.ps1 @@ -57,6 +57,11 @@ function Connect-ArubaSW { Connect to an ArubaOS Switch with IP 192.0.2.1 and store connection info to $sw2 variable and don't store connection on global ($DefaultArubaSWConnection) variable + + .EXAMPLE + Connect-ArubaSW -Server 192.0.2.1 -api_version 2 + + Connect to an ArubaOS Switch with IP 192.0.2.1 using v2 API #> Param( @@ -69,8 +74,6 @@ function Connect-ArubaSW { [Parameter(Mandatory = $false)] [PSCredential]$Credentials, [Parameter(Mandatory = $false)] - [switch]$noverbose = $false, - [Parameter(Mandatory = $false)] [switch]$httpOnly = $false, [Parameter(Mandatory = $false)] [switch]$SkipCertificateCheck = $false, @@ -78,6 +81,9 @@ function Connect-ArubaSW { [ValidateRange(1, 65535)] [int]$port, [Parameter(Mandatory = $false)] + [ValidateRange(1, 10)] + [int]$api_version, + [Parameter(Mandatory = $false)] [boolean]$DefaultConnection = $true ) @@ -86,7 +92,8 @@ function Connect-ArubaSW { Process { - $connection = @{server = ""; session = ""; cookie = ""; httpOnly = $false; port = ""; invokeParams = ""; switch_type = "" } + $version = @{min = ""; cur = ""; max = "" } + $connection = @{server = ""; session = ""; cookie = ""; httpOnly = $false; port = ""; invokeParams = ""; switch_type = "" ; api_version = $version ; product_number = "" } #If there is a password (and a user), create a credentials if ($Password) { @@ -115,7 +122,7 @@ function Connect-ArubaSW { $port = 80 } $connection.httpOnly = $true - $uri = "http://${Server}:${port}/rest/v3/login-sessions" + $uri = "http://${Server}:${port}/" } else { if (!$port) { @@ -131,7 +138,15 @@ function Connect-ArubaSW { Set-ArubaSWuntrustedSSL } } - $uri = "https://${Server}:${port}/rest/v3/login-sessions" + $uri = "https://${Server}:${port}/" + } + + if ($PsBoundParameters.ContainsKey('api_version')) { + $uri += "rest/v${api_version}/login-sessions" + } + else { + #By default use v3 API (some 'new' device don't support v1/v2 API...) + $uri += "rest/v3/login-sessions" } try { @@ -155,30 +170,54 @@ function Connect-ArubaSW { Set-Variable -name DefaultArubaSWConnection -value $connection -scope Global } + $restversion = Get-ArubaSWRestversion -connection $connection + #Remove v and .x (.0, 1) + $vers = $restversion.version -replace "v" -replace ".0" -replace ".1" + + $connection.api_version.min = ($vers | Measure-Object -Minimum).Minimum + $connection.api_version.max = ($vers | Measure-Object -Maximum).Maximum + + if ($PsBoundParameters.ContainsKey('api_version')) { + $connection.api_version.cur = $api_version + } + else { + #use by default the high version release supported + $connection.api_version.cur = $connection.api_version.max + } + $switchstatus = Get-ArubaSWSystemStatusSwitch -connection $connection $connection.switch_type = $switchstatus.switch_type - if (-not $noverbose) { - $switchsystem = Get-ArubaSWSystem -connection $connection + if ('ST_STACKED' -eq $switchstatus.switch_type) { + if ( $switchstatus.blades.count -eq "1") { + $connection.product_number = $switchstatus.blades.product_number + } + else { + $connection.product_number = $switchstatus.blades.product_number[0] + } + + } + else { + $connection.product_number = $switchstatus.product_number + } + $switchsystem = Get-ArubaSWSystem -connection $connection - if ($switchstatus.switch_type -eq "ST_STACKED") { - $product_name = $NULL; - foreach ($blades in $switchstatus.blades) { - if ($blades.product_name) { - if ($product_name) { - $product_name += ", " - } - $product_name += $blades.product_name + if ($switchstatus.switch_type -eq "ST_STACKED") { + $product_name = $NULL; + foreach ($blades in $switchstatus.blades) { + if ($blades.product_name) { + if ($product_name) { + $product_name += ", " } + $product_name += $blades.product_name } } - else { - $product_name = $switchstatus.product_name - } - Write-Output "Welcome on $($switchsystem.name) -$product_name" - } + else { + $product_name = $switchstatus.product_name + } + Write-Verbose "Welcome on $($switchsystem.name) -$product_name" #Return connection info $connection @@ -188,6 +227,46 @@ function Connect-ArubaSW { } } +function Set-ArubaSWConnection { + + <# + .SYNOPSIS + Configure Aruba SW connection Setting + + .DESCRIPTION + Configure Aruba SW connection Setting (api_version...) + + .EXAMPLE + Set-ArubaSWConnection -api_version 4 + + Configure default connection api_version to 4 + + #> + + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Low')] + Param( + [Parameter(Mandatory = $false)] + [ValidateRange(1, 10)] + [int]$api_version, + [Parameter(Mandatory = $false)] + [psobject]$connection = $DefaultArubaSWConnection + ) + + Begin { + } + + Process { + + if ($PSCmdlet.ShouldProcess($connection.server, 'Set default api_version on connection')) { + $connection.api_version.cur = $api_version + } + + } + + End { + } +} + function Disconnect-ArubaSW { <# @@ -221,7 +300,7 @@ function Disconnect-ArubaSW { Process { - $uri = "rest/v3/login-sessions" + $uri = "login-sessions" if ($PSCmdlet.ShouldProcess($connection.server, 'Remove Connection')) { $null = Invoke-ArubaSWWebRequest -method "DELETE" -uri $uri -connection $connection diff --git a/PowerArubaSW/Public/DNS.ps1 b/PowerArubaSW/Public/DNS.ps1 index 3b804e0..95b48b6 100644 --- a/PowerArubaSW/Public/DNS.ps1 +++ b/PowerArubaSW/Public/DNS.ps1 @@ -30,7 +30,7 @@ function Get-ArubaSWDns { Process { - $uri = "rest/v4/dns" + $uri = "dns" $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection @@ -90,7 +90,7 @@ function Set-ArubaSWDns { Process { - $uri = "rest/v4/dns" + $uri = "dns" $conf = New-Object -TypeName PSObject @@ -186,7 +186,7 @@ function Remove-ArubaSWDns { $dns | Add-Member -name "dns_config_mode" -membertype NoteProperty -Value "DCM_DISABLED" - $uri = "rest/v4/dns" + $uri = "dns" if ($PSCmdlet.ShouldProcess($connection.server, 'Remove DNS')) { $null = Invoke-ArubaSWWebRequest -method "PUT" -body $dns -uri $uri -connection $connection diff --git a/PowerArubaSW/Public/IPAddress.ps1 b/PowerArubaSW/Public/IPAddress.ps1 index 2f3902a..a46a81c 100644 --- a/PowerArubaSW/Public/IPAddress.ps1 +++ b/PowerArubaSW/Public/IPAddress.ps1 @@ -30,7 +30,7 @@ function Get-ArubaSWIpAddress { Process { - $uri = "rest/v4/ipaddresses" + $uri = "ipaddresses" $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection diff --git a/PowerArubaSW/Public/LACP.ps1 b/PowerArubaSW/Public/LACP.ps1 index 4a32b1e..3ed2a9f 100644 --- a/PowerArubaSW/Public/LACP.ps1 +++ b/PowerArubaSW/Public/LACP.ps1 @@ -30,7 +30,7 @@ function Get-ArubaSWLACP { Process { - $uri = "rest/v4/lacp/port" + $uri = "lacp/port" $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection @@ -84,7 +84,7 @@ function Add-ArubaSWLACP { Process { - $uri = "rest/v4/lacp/port" + $uri = "lacp/port" $lacp = New-Object -TypeName PSObject @@ -149,7 +149,7 @@ function Remove-ArubaSWLACP { $id = $lacp.port_id - $uri = "rest/v4/lacp/port/${id}" + $uri = "lacp/port/${id}" if ($PSCmdlet.ShouldProcess($id, 'Remove LACP')) { $null = Invoke-ArubaSWWebRequest -method "DELETE" -body $lacp -uri $uri -connection $connection diff --git a/PowerArubaSW/Public/LLDP.ps1 b/PowerArubaSW/Public/LLDP.ps1 index 28f1a00..f9609d5 100644 --- a/PowerArubaSW/Public/LLDP.ps1 +++ b/PowerArubaSW/Public/LLDP.ps1 @@ -37,7 +37,7 @@ function Get-ArubaSWLLDPRemote { Process { - $uri = "rest/v4/lldp/remote-device" + $uri = "lldp/remote-device" if ($port_id) { $uri += "/$port_id" @@ -84,7 +84,7 @@ function Get-ArubaSWLLDPGlobalStatus { Process { - $uri = "rest/v4/lldp" + $uri = "lldp" $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection @@ -138,7 +138,7 @@ function Set-ArubaSWLLDPGlobalStatus { Process { - $uri = "rest/v4/lldp" + $uri = "lldp" $conf = New-Object -TypeName PSObject @@ -203,7 +203,7 @@ function Get-ArubaSWLLDPNeighborStats { Process { - $uri = "rest/v4/lldp/stats/device" + $uri = "lldp/stats/device" $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection @@ -248,7 +248,7 @@ function Get-ArubaSWLLDPPortStats { Process { - $uri = "rest/v4/lldp/stats/ports" + $uri = "lldp/stats/ports" $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection diff --git a/PowerArubaSW/Public/Led.ps1 b/PowerArubaSW/Public/Led.ps1 index 5dcc5a9..867e02f 100644 --- a/PowerArubaSW/Public/Led.ps1 +++ b/PowerArubaSW/Public/Led.ps1 @@ -38,7 +38,7 @@ function Get-ArubaSWLed { Process { - $uri = "rest/v4/led_locator_info" + $uri = "led_locator_info" $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection @@ -104,7 +104,7 @@ function Set-ArubaSWLed { Process { - $uri = "rest/v4/locator-led-blink" + $uri = "locator-led-blink" $led = New-Object -TypeName PSObject diff --git a/PowerArubaSW/Public/MacTable.ps1 b/PowerArubaSW/Public/MacTable.ps1 index 4147b01..1bbbf07 100644 --- a/PowerArubaSW/Public/MacTable.ps1 +++ b/PowerArubaSW/Public/MacTable.ps1 @@ -59,16 +59,16 @@ function Get-ArubaSWMacTable { Process { if ($PsBoundParameters.ContainsKey('port_id')) { - $uri = "rest/v4/ports/${port_id}/mac-table" + $uri = "ports/${port_id}/mac-table" } elseif ($PsBoundParameters.ContainsKey('vlan_id')) { - $uri = "rest/v4/vlans/${vlan_id}/mac-table" + $uri = "vlans/${vlan_id}/mac-table" } elseif ($PsBoundParameters.ContainsKey('mac_address')) { - $uri = "rest/v4/mac-table/${mac_address}" + $uri = "mac-table/${mac_address}" } else { - $uri = "rest/v4/mac-table" + $uri = "mac-table" } $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection diff --git a/PowerArubaSW/Public/Modules.ps1 b/PowerArubaSW/Public/Modules.ps1 index a96aab7..9cb40e2 100644 --- a/PowerArubaSW/Public/Modules.ps1 +++ b/PowerArubaSW/Public/Modules.ps1 @@ -30,7 +30,7 @@ function Get-ArubaSWModules { Process { - $uri = "rest/v4/modules" + $uri = "modules" $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection diff --git a/PowerArubaSW/Public/Ping.ps1 b/PowerArubaSW/Public/Ping.ps1 index a6e460a..1762759 100644 --- a/PowerArubaSW/Public/Ping.ps1 +++ b/PowerArubaSW/Public/Ping.ps1 @@ -40,7 +40,7 @@ function Test-ArubaSWPing { Process { - $uri = "rest/v4/ping" + $uri = "ping" $dest = New-Object -TypeName PSObject if ($PsBoundParameters.ContainsKey('ipv4_address')) { diff --git a/PowerArubaSW/Public/Poe.ps1 b/PowerArubaSW/Public/Poe.ps1 index f656ab3..0697846 100644 --- a/PowerArubaSW/Public/Poe.ps1 +++ b/PowerArubaSW/Public/Poe.ps1 @@ -37,10 +37,10 @@ function Get-ArubaSWPoE { Process { - $uri = "rest/v4/poe/ports" + $uri = "poe/ports" if ( $port_id ) { - $uri = "rest/v4/ports/$port_id/poe" + $uri = "ports/$port_id/poe" } $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection @@ -116,7 +116,7 @@ function Set-ArubaSWPoE { if ($port_poe) { $port_id = $port_poe.port_id } - $uri = "rest/v4/ports/${port_id}/poe" + $uri = "ports/${port_id}/poe" $_poe = New-Object -TypeName PSObject @@ -221,10 +221,10 @@ function Get-ArubaSWPoEStats { Process { - $uri = "rest/v4/poe/ports/stats" + $uri = "poe/ports/stats" if ( $port_id ) { - $uri = "rest/v4/ports/$port_id/poe/stats" + $uri = "ports/$port_id/poe/stats" } $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection diff --git a/PowerArubaSW/Public/Port.ps1 b/PowerArubaSW/Public/Port.ps1 index 6e8af8a..8a416f9 100644 --- a/PowerArubaSW/Public/Port.ps1 +++ b/PowerArubaSW/Public/Port.ps1 @@ -37,7 +37,7 @@ function Get-ArubaSWPort { Process { - $uri = "rest/v4/ports" + $uri = "ports" $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection @@ -89,7 +89,7 @@ function Get-ArubaSWPortStatistics { Process { - $uri = "rest/v4/port-statistics" + $uri = "port-statistics" $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection @@ -171,7 +171,7 @@ function Set-ArubaSWPort { $port_id = $port.id } - $uri = "rest/v4/ports/${port_id}" + $uri = "ports/${port_id}" $_port = New-Object -TypeName PSObject diff --git a/PowerArubaSW/Public/RADIUSProfile.ps1 b/PowerArubaSW/Public/RADIUSProfile.ps1 index 1cb935e..521d106 100644 --- a/PowerArubaSW/Public/RADIUSProfile.ps1 +++ b/PowerArubaSW/Public/RADIUSProfile.ps1 @@ -30,7 +30,7 @@ function Get-ArubaSWRadiusProfile { } Process { - $uri = "rest/v4/radius_profile" + $uri = "radius_profile" $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection @@ -100,7 +100,7 @@ function Set-ArubaSWRadiusProfile { Process { - $uri = "rest/v4/radius_profile" + $uri = "radius_profile" $conf = New-Object -TypeName PSObject diff --git a/PowerArubaSW/Public/RADIUSServer.ps1 b/PowerArubaSW/Public/RADIUSServer.ps1 index 9ff4875..3c24779 100644 --- a/PowerArubaSW/Public/RADIUSServer.ps1 +++ b/PowerArubaSW/Public/RADIUSServer.ps1 @@ -49,7 +49,7 @@ function Get-ArubaSWRadiusServer { } Process { - $uri = "rest/v4/radius_servers" + $uri = "radius_servers" $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection @@ -121,7 +121,7 @@ function Add-ArubaSWRadiusServer { Process { - $uri = "rest/v4/radius_servers" + $uri = "radius_servers" $conf = New-Object -TypeName PSObject @@ -241,7 +241,7 @@ function Set-ArubaSWRadiusServer { $id = $id_server.radius_server_id } - $uri = "rest/v4/radius_servers/${id}" + $uri = "radius_servers/${id}" $conf = New-Object -TypeName PSObject @@ -345,7 +345,7 @@ function Remove-ArubaSWRadiusServer { $id = $id_server.radius_server_id } - $uri = "rest/v4/radius_servers/${id}" + $uri = "radius_servers/${id}" if ($PSCmdlet.ShouldProcess($id, 'Remove RADIUS Server')) { $null = Invoke-ArubaSWWebRequest -method "DELETE" -uri $uri -connection $connection diff --git a/PowerArubaSW/Public/RADIUSServerGroup.ps1 b/PowerArubaSW/Public/RADIUSServerGroup.ps1 index 219910d..446d42b 100644 --- a/PowerArubaSW/Public/RADIUSServerGroup.ps1 +++ b/PowerArubaSW/Public/RADIUSServerGroup.ps1 @@ -33,7 +33,7 @@ function Get-ArubaSWRadiusServerGroup { Process { - $uri = "rest/v4/radius/server_group/${server_group_name}" + $uri = "radius/server_group/${server_group_name}" $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection @@ -85,7 +85,7 @@ function Add-ArubaSWRadiusServerGroup { Process { - $uri = "rest/v4/radius/server_group" + $uri = "radius/server_group" $conf = New-Object -TypeName PSObject @@ -174,7 +174,7 @@ function Remove-ArubaSWRadiusServerGroup { $server_group_name = $server_group.server_group_name } - $uri = "rest/v4/radius/server_group/${server_group_name}" + $uri = "radius/server_group/${server_group_name}" if ($PSCmdlet.ShouldProcess($server_group_name, 'Remove RADIUS Server Group')) { $null = Invoke-ArubaSWWebRequest -method "DELETE" -uri $uri -connection $connection diff --git a/PowerArubaSW/Public/RestTimeout.ps1 b/PowerArubaSW/Public/RestTimeout.ps1 index 8cb17e7..cf90b0d 100644 --- a/PowerArubaSW/Public/RestTimeout.ps1 +++ b/PowerArubaSW/Public/RestTimeout.ps1 @@ -29,7 +29,7 @@ function Get-ArubaSWRestSessionTimeout { Process { - $uri = "rest/v4/session-idle-timeout" + $uri = "session-idle-timeout" $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection @@ -78,7 +78,7 @@ function Set-ArubaSWRestSessionTimeout { Process { - $uri = "rest/v4/session-idle-timeout" + $uri = "session-idle-timeout" $time = New-Object -TypeName PSObject diff --git a/PowerArubaSW/Public/RestVersion.ps1 b/PowerArubaSW/Public/RestVersion.ps1 index d4673bd..86f762b 100644 --- a/PowerArubaSW/Public/RestVersion.ps1 +++ b/PowerArubaSW/Public/RestVersion.ps1 @@ -33,7 +33,7 @@ function Get-ArubaSWRestVersion { $uri = "rest/version" - $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection + $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection -api_version 0 ($response.content | ConvertFrom-Json).version_element } diff --git a/PowerArubaSW/Public/STP.ps1 b/PowerArubaSW/Public/STP.ps1 index cff2249..40d2e10 100644 --- a/PowerArubaSW/Public/STP.ps1 +++ b/PowerArubaSW/Public/STP.ps1 @@ -30,7 +30,7 @@ function Get-ArubaSWSTP { Process { - $uri = "rest/v4/stp" + $uri = "stp" $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection @@ -83,7 +83,7 @@ function Set-ArubaSWSTP { Process { - $uri = "rest/v4/stp" + $uri = "stp" $_stp = New-Object -TypeName PSObject @@ -161,7 +161,7 @@ function Get-ArubaSWSTPPort { Process { - $uri = "rest/v4/stp/ports" + $uri = "stp/ports" if ($port) { $uri += "/$port" @@ -240,7 +240,7 @@ function Set-ArubaSWSTPPort { $_stp | Add-Member -name "port_id" -membertype NoteProperty -Value $port - $uri = "rest/v4/stp/ports/${port}" + $uri = "stp/ports/${port}" if ( $PsBoundParameters.ContainsKey('priority') ) { $_stp | Add-Member -name "priority" -membertype NoteProperty -Value $priority diff --git a/PowerArubaSW/Public/System.ps1 b/PowerArubaSW/Public/System.ps1 index 8fabdec..36f848d 100644 --- a/PowerArubaSW/Public/System.ps1 +++ b/PowerArubaSW/Public/System.ps1 @@ -32,7 +32,7 @@ function Get-ArubaSWSystem { Process { - $uri = "rest/v4/system" + $uri = "system" $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection @@ -77,7 +77,7 @@ function Set-ArubaSWSystem { Process { - $uri = "rest/v4/system" + $uri = "system" $system = New-Object -TypeName PSObject @@ -135,7 +135,7 @@ function Get-ArubaSWSystemStatus { Throw "Unable to use this cmdlet, you need to use Get-ArubaSWSystemStatusGlobal" } - $uri = "rest/v4/system/status" + $uri = "system/status" $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection @@ -169,7 +169,7 @@ function Get-ArubaSWSystemStatusSwitch { Process { - $uri = "rest/v4/system/status/switch" + $uri = "system/status/switch" $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection @@ -210,7 +210,7 @@ function Get-ArubaSWSystemStatusGlobal { if ('ST_STANDALONE' -eq $connection.switch_type -or 'ST_CHASSIS' -eq $connection.switch_type) { Throw "Unable to use this cmdlet, you need to use Get-ArubaSWSystemStatus" } - $uri = "rest/v4/system/status/global_info" + $uri = "system/status/global_info" $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection diff --git a/PowerArubaSW/Public/Trunk.ps1 b/PowerArubaSW/Public/Trunk.ps1 index 097e2a3..1c4273b 100644 --- a/PowerArubaSW/Public/Trunk.ps1 +++ b/PowerArubaSW/Public/Trunk.ps1 @@ -30,7 +30,7 @@ function Get-ArubaSWTrunk { Process { - $uri = "rest/v4/trunk/port" + $uri = "trunk/port" $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection @@ -85,7 +85,7 @@ function Add-ArubaSWTrunk { Process { - $uri = "rest/v4/trunk/port" + $uri = "trunk/port" $trunk = New-Object -TypeName PSObject @@ -149,7 +149,7 @@ function Remove-ArubaSWTrunk { $id = $trunk.port_id - $uri = "rest/v4/trunk/port/${id}" + $uri = "trunk/port/${id}" if ($PSCmdlet.ShouldProcess($id, 'Remove Trunk')) { $null = Invoke-ArubaSWWebRequest -method "DELETE" -body $trunk -uri $uri -connection $connection diff --git a/PowerArubaSW/Public/Vlans-Ports.ps1 b/PowerArubaSW/Public/Vlans-Ports.ps1 index a58b949..ee15600 100644 --- a/PowerArubaSW/Public/Vlans-Ports.ps1 +++ b/PowerArubaSW/Public/Vlans-Ports.ps1 @@ -43,7 +43,7 @@ function Add-ArubaSWVlansPorts { Process { - $uri = "rest/v4/vlans-ports" + $uri = "vlans-ports" $vlanports = New-Object -TypeName PSObject @@ -109,7 +109,7 @@ function Get-ArubaSWVlansPorts { Process { - $uri = "rest/v4/vlans-ports" + $uri = "vlans-ports" $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection $vlansports = ($response.Content | ConvertFrom-Json).vlan_port_element @@ -174,7 +174,7 @@ function Set-ArubaSWVlansPorts { $vlan_id = $vlanports.vlan_id $port_id = $vlanports.port_id } - $uri = "rest/v4/vlans-ports/${vlan_id}-${port_id}" + $uri = "vlans-ports/${vlan_id}-${port_id}" $_vlanport = New-Object -TypeName PSObject @@ -245,7 +245,7 @@ function Remove-ArubaSWVlansPorts { $port_id = $vlanport.port_id } - $uri = "rest/v4/vlans-ports/${vlan_id}-${port_id}" + $uri = "vlans-ports/${vlan_id}-${port_id}" if ($PSCmdlet.ShouldProcess("${vlan_id}-${port_id}", 'Configure Vlans Ports')) { $null = Invoke-ArubaSWWebRequest -method "DELETE" -uri $uri -connection $connection diff --git a/PowerArubaSW/Public/Vlans.ps1 b/PowerArubaSW/Public/Vlans.ps1 index c9c942b..66fcaed 100644 --- a/PowerArubaSW/Public/Vlans.ps1 +++ b/PowerArubaSW/Public/Vlans.ps1 @@ -41,7 +41,7 @@ function Add-ArubaSWVlans { Process { - $uri = "rest/v4/vlans" + $uri = "vlans" $vlan = New-Object -TypeName PSObject @@ -135,7 +135,7 @@ function Get-ArubaSWVlans { Process { - $uri = "rest/v4/vlans" + $uri = "vlans" $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection @@ -202,7 +202,7 @@ function Set-ArubaSWVlans { $id = $vlan.vlan_id $oldname = $vlan.name } - $uri = "rest/v4/vlans/${id}" + $uri = "vlans/${id}" $_vlan = New-Object -TypeName PSObject @@ -303,7 +303,7 @@ function Remove-ArubaSWVlans { $id = $vlan.vlan_id } - $uri = "rest/v4/vlans/${id}" + $uri = "vlans/${id}" $target = "Vlan ID {0}" -f $id if ($PSCmdlet.ShouldProcess($target, "Remove VLAN")) { diff --git a/Tests/integration/Connection.Tests.ps1 b/Tests/integration/Connection.Tests.ps1 index d47d7d0..0361f22 100644 --- a/Tests/integration/Connection.Tests.ps1 +++ b/Tests/integration/Connection.Tests.ps1 @@ -7,13 +7,15 @@ Describe "Connect to a switch (using HTTP)" { It "Connect to a switch (using HTTP) and check global variable" { - Connect-ArubaSW $invokeParams.server -Username $invokeParams.Username -password $invokeParams.password -httpOnly -noverbose - $DefaultArubaSWConnection | Should -Not -BeNullOrEmpty + Connect-ArubaSW $invokeParams.server -Username $invokeParams.Username -password $invokeParams.password -api_version 3 -httpOnly $DefaultArubaSWConnection.server | Should -Be $invokeParams.server $DefaultArubaSWConnection.cookie | Should -Not -BeNullOrEmpty $DefaultArubaSWConnection.port | Should -Be "80" $DefaultArubaSWConnection.httpOnly | Should -Be $true $DefaultArubaSWConnection.session | Should -Not -BeNullOrEmpty + $DefaultArubaSWConnection.api_version.min | Should -Not -BeNullOrEmpty + $DefaultArubaSWConnection.api_version.max | Should -Not -BeNullOrEmpty + $DefaultArubaSWConnection.api_version.cur | Should -Be "3" } It "Disconnect to a switch (using HTTP) and check global variable" { Disconnect-ArubaSW -confirm:$false @@ -25,13 +27,16 @@ Describe "Connect to a switch (using HTTP)" { Describe "Connect to a switch (using HTTPS)" { #TODO Try change port => Need AnyCLI It "Connect to a switch (using HTTPS and -SkipCertificateCheck) and check global variable" -Skip:($httpOnly) { - Connect-ArubaSW $invokeParams.server -Username $invokeParams.Username -password $invokeParams.password -SkipCertificateCheck -noverbose + Connect-ArubaSW $invokeParams.server -Username $invokeParams.Username -password $invokeParams.password -api_version 3 -SkipCertificateCheck $DefaultArubaSWConnection | Should -Not -BeNullOrEmpty $DefaultArubaSWConnection.server | Should -Be $invokeParams.server $DefaultArubaSWConnection.cookie | Should -Not -BeNullOrEmpty $DefaultArubaSWConnection.port | Should -Be "443" $DefaultArubaSWConnection.httpOnly | Should -Be $false $DefaultArubaSWConnection.session | Should -Not -BeNullOrEmpty + $DefaultArubaSWConnection.api_version.min | Should -Not -BeNullOrEmpty + $DefaultArubaSWConnection.api_version.max | Should -Not -BeNullOrEmpty + $DefaultArubaSWConnection.api_version.cur | Should -Be "3" } It "Disconnect to a switch (using HTTPS) and check global variable" -Skip:($httpOnly) { Disconnect-ArubaSW -confirm:$false @@ -40,25 +45,33 @@ Describe "Connect to a switch (using HTTPS)" { #This test only work with PowerShell 6 / Core (-SkipCertificateCheck don't change global variable but only Invoke-WebRequest/RestMethod) #This test will -Be fail, if there is valid certificate... It "Connect to a switch (using HTTPS) and check global variable" -Skip:($httpOnly -Or "Desktop" -eq $PSEdition) { - { Connect-ArubaSW $invokeParams.server -Username $invokeParams.Username -password $invokeParams.password -noverbose } | Should -Throw "Unable to connect (certificate)" + { Connect-ArubaSW $invokeParams.server -Username $invokeParams.Username -password $invokeParams.password } | Should -Throw "Unable to connect (certificate)" } } -Describe "Connect to a switch (using multi connection)" { +Describe "Connect to a switch (using multi connection and multi version)" { It "Connect to a switch (using HTTP and store on sw variable)" { - $script:sw = Connect-ArubaSW $invokeParams.server -Username $invokeParams.Username -password $invokeParams.password -httpOnly -noverbose -DefaultConnection:$false + $script:sw = Connect-ArubaSW $invokeParams.server -Username $invokeParams.Username -password $invokeParams.password -api_version 3 -httpOnly -DefaultConnection:$false $DefaultArubaSWConnection | Should -BeNullOrEmpty $sw.server | Should -Be $invokeParams.server $sw.cookie | Should -Not -BeNullOrEmpty $sw.port | Should -Be "80" $sw.httpOnly | Should -Be $true $sw.session | Should -Not -BeNullOrEmpty + $sw.api_version.min | Should -Not -BeNullOrEmpty + $sw.api_version.max | Should -Not -BeNullOrEmpty + $sw.api_version.cur | Should -Be "3" } It "Throw when try to use Invoke-ArubaSWWebRequest and not connected" { { Invoke-ArubaSWWebRequest -uri "rest/v4/vlans" } | Should -Throw "Not Connected. Connect to the Switch with Connect-ArubaSW" } + It "use Set-ArubaSWConnection to change api_version (v4)" { + Set-ArubaSWConnection -api_version 4 -connection $sw + $sw.api_version.cur | Should -Be "4" + } + Context "Use Multi connection for call some (Get) cmdlet (Vlan, System...)" { It "Use Multi connection for call Get vlans" { { Get-ArubaSWVlans -connection $sw } | Should -Not -Throw