Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated code, tests to use api version v10.08 instead of v1 (v10.04) … #63

Merged
merged 7 commits into from
Sep 11, 2023
4 changes: 2 additions & 2 deletions PowerArubaCX/Private/RestMethod.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ function Invoke-ArubaCXRestMethod {
Invoke-RestMethod with ArubaCX connection for get rest/vX/system with display only attributes hostname and dns_servers

.EXAMPLE
Invoke-ArubaCXRestMethod -method "get" -uri "rest/v10.04/system" -noapiversion
Invoke-ArubaCXRestMethod -method "get" -uri "rest/v10.08/system" -noapiversion

Invoke-RestMethod with ArubaCX connection for get rest/v10.04/system (need to specify full uri with rest/vX)
Invoke-RestMethod with ArubaCX connection for get rest/v10.08/system (need to specify full uri with rest/vX)
#>

[CmdletBinding(DefaultParametersetname = "default")]
Expand Down
24 changes: 15 additions & 9 deletions PowerArubaCX/Public/Connection.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,34 @@ function Connect-ArubaCX {
}
}

$postParams = @{username = $Credential.username; password = $Credential.GetNetworkCredential().Password }
$url = "https://${Server}:${Port}/rest/v1/login"
$url = "https://${Server}:${Port}/rest"
try {
Invoke-RestMethod $url -Method POST -Body $postParams -SessionVariable arubacx @invokeParams | Out-Null
if ("Desktop" -eq $PSVersionTable.PsEdition) {
$rest = Invoke-RestMethod $url -Method "get" @invokeParams
}
else {
$rest = Invoke-RestMethod $url -Method "get" @invokeParams -SkipCertificateCheck
}
}
catch {
Show-ArubaCXException $_
throw "Unable to connect"
throw "Unsupported release Need to use ArubaCX >= 10.06"
}
$api_version = $rest.latest.version

$url = "https://${Server}:${Port}/rest"
$postParams = @{username = $Credential.username; password = $Credential.GetNetworkCredential().Password }
$url = "https://${Server}:${Port}/rest/${api_version}/login"
try {
$rest = Invoke-RestMethod $url -Method "get" -WebSession $arubacx @invokeParams
Invoke-RestMethod $url -Method POST -Body $postParams -SessionVariable arubacx @invokeParams | Out-Null
}
catch {
throw "Unsupported release Need to use ArubaCX >= 10.04"
Show-ArubaCXException $_
throw "Unable to connect"
}

$connection.server = $server
$connection.session = $arubacx
$connection.invokeParams = $invokeParams
$connection.api_version = $rest.latest.version
$connection.api_version = $api_version
$current_version = (Get-ArubaCXFirmware -connection $connection).current_version.split(".")
$connection.version = [version]"$($current_version[1]).$($current_version[2]).$($current_version[3])"
$connection.platform_name = (Get-ArubaCXSystem -attributes platform_name -connection $connection).platform_name
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ There is some extra feature

More functionality will be added later.

Tested with ArubaCX 8400 and 832x, 6x00 (using >= 10.04.xx firmware) on Windows/Linux/macOS
Tested with ArubaCX 8400 and 832x, 6x00 (using >= 10.06.xx firmware) on Windows/Linux/macOS

# Usage

Expand All @@ -38,8 +38,8 @@ For example, you can manage Vlans with the following commands:

# Requirements

- Powershell 6 (Core) or 5 (If possible get the latest version)
- An ArubaCX Switch (with firmware >= 10.04.xx) and REST API enable
- Powershell 7 (Core) or 5 (If possible get the latest version)
- An ArubaCX Switch (with firmware >= 10.06.xx) and REST API enable

# Instructions
### Install the module
Expand Down
6 changes: 3 additions & 3 deletions Tests/integration/Connection.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Describe "Connect to a switch (using HTTPS)" {
$DefaultArubaCXConnection.api_version | Should -Not -BeNullOrEmpty
$DefaultArubaCXConnection.version | Should -Not -BeNullOrEmpty
$DefaultArubaCXConnection.version.major | Should -Be "10"
$DefaultArubaCXConnection.version.minor | Should -BeIn (4..11)
$DefaultArubaCXConnection.version.minor | Should -BeIn (6..12)
$DefaultArubaCXConnection.version.revision | Should -Not -BeNullOrEmpty
}
It "Disconnect to a switch (using HTTPS) and check global variable" {
Expand All @@ -42,12 +42,12 @@ Describe "Connect to a switch (using multi connection)" {
$cx.api_version | Should -Not -BeNullOrEmpty
$cx.version | Should -Not -BeNullOrEmpty
$cx.version.major | Should -Be "10"
$cx.version.minor | Should -BeIn (4..11)
$cx.version.minor | Should -BeIn (6..12)
$cx.version.revision | Should -Not -BeNullOrEmpty
}

It "Throw when try to use Invoke-ArubaCPRestMethod and not connected" {
{ Invoke-ArubaCXRestMethod -uri "rest/v1/system" } | Should -Throw "Not Connected. Connect to the Switch with Connect-ArubaCX"
{ Invoke-ArubaCXRestMethod -uri "rest/v10.08/system" } | Should -Throw "Not Connected. Connect to the Switch with Connect-ArubaCX"
}

Context "Use Multi connection for call some (Get) cmdlet (Vlan, System...)" {
Expand Down