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

NetworkDevice (NAD): Allow SNMP parameters #76

Merged
merged 4 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions PowerArubaCP/Public/NetworkDevice.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ function Add-ArubaCPNetworkDevice {

Add Network Device SW5 with hashtable attribute (Location) from vendor Aruba

.EXAMPLE
Add-ArubaCPNetworkDevice -name SW6 -ip_address 192.0.2.6 -radius_secret MySecurePassword -vendor Cisco -snmp_version V2C -community_string CommString

Add Network Device SW6 with a snmp-read community string from vendor Cisco

#>

Param(
Expand All @@ -53,6 +58,11 @@ function Add-ArubaCPNetworkDevice {
[Parameter (Mandatory = $true)]
[string]$radius_secret,
[Parameter (Mandatory = $false)]
[ValidateSet('v1', 'v2c')]
[string]$snmp_version,
[Parameter (Mandatory = $false)]
[string]$community_string,
[Parameter (Mandatory = $false)]
[string]$tacacs_secret,
[Parameter (Mandatory = $true)]
[string]$vendor_name,
Expand Down Expand Up @@ -124,6 +134,19 @@ function Add-ArubaCPNetworkDevice {
$_nad | add-member -name "attributes" -membertype NoteProperty -Value $attributes
}

if ($PsBoundParameters.ContainsKey('snmp_version')) {
# Check if snmp_version is provided, and if so, make community_string mandatory
if (-not $PsBoundParameters.ContainsKey('community_string')) {
throw "If snmp_version is specified, community_string is mandatory."
}
$snmp_read = @{
snmp_version = $snmp_version.ToUpper()
community_string = $community_string
zone_name = "default"
}
$_nad | add-member -name "snmp_read" -membertype NoteProperty -Value $snmp_read
}

$nad = invoke-ArubaCPRestMethod -method "POST" -body $_nad -uri $uri -connection $connection
$nad
}
Expand Down Expand Up @@ -273,6 +296,12 @@ function Set-ArubaCPNetworkDevice {

Set Vendor Name to Cisco and (re)configure TACACS Secret of NAD-PowerArubaCP

.EXAMPLE
$nad = Get-ArubaCPNetworkDevice -name NAD-PowerArubaCP
PS > $nad | Set-ArubaCPNetworkDevice -snmp_version V2C -community_string MyComm

Set SNMP version and community string of NAD-PowerArubaCP

.EXAMPLE
$nad = Get-ArubaCPNetworkDevice -name NAD-PowerArubaCP
PS > $nad | Set-ArubaCPNetworkDevice -coa_capable -coa_port 5000
Expand All @@ -297,6 +326,11 @@ function Set-ArubaCPNetworkDevice {
[Parameter (Mandatory = $false)]
[string]$radius_secret,
[Parameter (Mandatory = $false)]
[ValidateSet('v1', 'v2c')]
[string]$snmp_version,
alagoutte marked this conversation as resolved.
Show resolved Hide resolved
[Parameter (Mandatory = $false)]
[string]$community_string,
[Parameter (Mandatory = $false)]
[string]$tacacs_secret,
[Parameter (Mandatory = $false)]
[string]$vendor_name,
Expand Down Expand Up @@ -345,6 +379,20 @@ function Set-ArubaCPNetworkDevice {
$_nad | add-member -name "radius_secret" -membertype NoteProperty -Value $radius_secret
}

if ($PsBoundParameters.ContainsKey('snmp_version')) {
alagoutte marked this conversation as resolved.
Show resolved Hide resolved
# Check if snmp_version is provided, and if so, make community_string mandatory
if (-not $PsBoundParameters.ContainsKey('community_string')) {
throw "If snmp_version is specified, community_string is mandatory."
}
$snmp_read = @{
snmp_version = $snmp_version.ToUpper()
community_string = $community_string
zone_name = "default"
}
$_nad | add-member -name "snmp_read" -membertype NoteProperty -Value $snmp_read
}


if ( $PsBoundParameters.ContainsKey('tacacs_secret') ) {
$_nad | add-member -name "tacacs_secret" -membertype NoteProperty -Value $tacacs_secret
}
Expand Down
54 changes: 54 additions & 0 deletions Tests/integration/NetworkDevice.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,60 @@ Describe "Remove Network Device" {

}

Describe "Add Network Device" {

It "Add Network Device with snmp v2c" {
Add-ArubaCPNetworkDevice -name pester_SW6 -ip_address 192.0.2.6 -radius_secret MySecurePassword -vendor Cisco -snmp_version v2c -community_string myString
$nad = Get-ArubaCPNetworkDevice -name pester_SW6
$nad.name | Should -Be "pester_SW6"
$nad.ip_address | Should -Be "192.0.2.6"
$nad.vendor_name | Should -Be "Cisco"
$nad.snmp_read.snmp_version | Should -Be "v2c"
$nad.snmp_read.zone_name | Should -Be "default"
# community_string is always empty
}

It "Add Network Device with snmp v1" {
Add-ArubaCPNetworkDevice -name pester_SW6 -ip_address 192.0.2.6 -radius_secret MySecurePassword -vendor Cisco -snmp_version v1 -community_string myString
$nad = Get-ArubaCPNetworkDevice -name pester_SW6
$nad.name | Should -Be "pester_SW6"
$nad.ip_address | Should -Be "192.0.2.6"
$nad.vendor_name | Should -Be "Cisco"
$nad.snmp_read.snmp_version | Should -Be "v1"
$nad.snmp_read.zone_name | Should -Be "default"
# community_string is always empty
}

It "Add Network Device with snmp v2c then change it to v1" {
Add-ArubaCPNetworkDevice -name pester_SW6 -ip_address 192.0.2.6 -radius_secret MySecurePassword -vendor Cisco -snmp_version v2c -community_string myString
Get-ArubaCPNetworkDevice -name pester_SW6 | Set-ArubaCPNetworkDevice -snmp_version v1 -community_string myString
$nad = Get-ArubaCPNetworkDevice -name pester_SW6
$nad.name | Should -Be "pester_SW6"
$nad.ip_address | Should -Be "192.0.2.6"
$nad.vendor_name | Should -Be "Cisco"
$nad.snmp_read.snmp_version | Should -Be "v1"
$nad.snmp_read.zone_name | Should -Be "default"
# community_string is always empty
}

It "Add Network Device with snmp v1 then change it to v2c" {
Add-ArubaCPNetworkDevice -name pester_SW6 -ip_address 192.0.2.6 -radius_secret MySecurePassword -vendor Cisco -snmp_version v1 -community_string myString
Get-ArubaCPNetworkDevice -name pester_SW6 | Set-ArubaCPNetworkDevice -snmp_version v2c -community_string myString
$nad = Get-ArubaCPNetworkDevice -name pester_SW6
$nad.name | Should -Be "pester_SW6"
$nad.ip_address | Should -Be "192.0.2.6"
$nad.vendor_name | Should -Be "Cisco"
$nad.snmp_read.snmp_version | Should -Be "v2c"
$nad.snmp_read.zone_name | Should -Be "default"
# community_string is always empty
}

AfterEach {
Get-ArubaCPNetworkDevice -name pester_SW6 | Remove-ArubaCPNetworkDevice -confirm:$false
}

}

AfterAll {
Disconnect-ArubaCP -confirm:$false
}