-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add Get-ArubaCXNeighbors (ARP) information #74
Open
alagoutte
wants to merge
14
commits into
PowerAruba:master
Choose a base branch
from
alagoutte:mac_and_arp
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
994f505
Neighbors(ARP): Add Get-ArubaCXNeighbors for get ARP table
alagoutte c432757
Neighbors (ARP): Add pipeline support
alagoutte c05c22f
Neighbors(ARP): Update Synopis, description and .EXAMPLE
alagoutte 1c65ad4
Neighbors(ARP): Add Tests
alagoutte e710648
MACs: Add Get-ArubaCXMACs for get MAC Address Table
alagoutte ae2d55a
ConvertTo(MacAddressTable): Add ConvertTo tools for convert Aruba CX …
alagoutte ab5161f
ConvertTo(-ArubaCXARPTable): Add ConvertTo tools for convert Aruba CX…
alagoutte b90338b
MACs: fix typo (vrf => vlan)
alagoutte 4f804a0
MACs: Add Tests
alagoutte 2642d81
MACs: Add vlan and vlan_pp parameter mutual exclustive
alagoutte 2787894
Neighbors: add vrf and vrf_pp parameters mutual exclusive
alagoutte f047247
ARPTable(ConvertTo): Fix display of table...
alagoutte 1ac5adc
ARPTable(ConvertTo): add display also of vrf name
alagoutte e4d2723
ConvertTo(MacAddressTable): speed up with no copy modemac...
alagoutte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# | ||
# Copyright 2024, Alexis La Goutte <alexis dot lagoutte at gmail dot com> | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
function ConvertTo-ArubaCXMacAddressTable { | ||
|
||
<# | ||
.SYNOPSIS | ||
ConvertTo Aruba CX Mac Address Table | ||
|
||
.DESCRIPTION | ||
Convert ArubaCX Macs Address Table to more easy array (with mac, vlan and port) | ||
|
||
|
||
.EXAMPLE | ||
Get-ArubaCXMacs -depth 2 | ConvertTo-ArubaCXMacAddressTable | ||
|
||
Convert ArubaCX Macs to MAC Address Table (mac, vlan and port) | ||
#> | ||
|
||
Param( | ||
[Parameter(Mandatory = $true, position = 1, ValueFromPipeline = $true)] | ||
[PSObject]$mac | ||
) | ||
|
||
Begin { | ||
} | ||
|
||
Process { | ||
$table = @() | ||
#Get list of vlan name | ||
$list_mac_vlan_name = $mac.psobject.properties.name | ||
|
||
foreach ($mac_vlan_name in $list_mac_vlan_name) { | ||
$list_mac = $mac.$mac_vlan_name | ||
$list_mac_name = $list_mac.psobject.properties.name | ||
|
||
#get List of modemac (Dynamic + MAC @) | ||
foreach ($mac_name in $list_mac_name) { | ||
$table += [pscustomobject]@{ | ||
"mac" = $list_mac.$mac_name.mac_addr | ||
"vlan" = $mac_vlan_name | ||
"port" = $list_mac.$mac_name.port.psobject.properties.name | ||
} | ||
} | ||
} | ||
|
||
$table | ||
} | ||
|
||
End { | ||
} | ||
|
||
} | ||
|
||
function ConvertTo-ArubaCXARPTable { | ||
|
||
<# | ||
.SYNOPSIS | ||
ConvertTo Aruba CX ARP Table | ||
|
||
.DESCRIPTION | ||
Convert ArubaCX ARP Table to more easy array (with mac, IP, vlan and port) | ||
|
||
.EXAMPLE | ||
Get-ArubaCXNeighbors -depth 2 | ConvertTo-ArubaCXARPTable | ||
|
||
Convert ArubaCX Neighbors to ARP Table (mac, IP? vlan and port) | ||
#> | ||
|
||
Param( | ||
[Parameter(Mandatory = $true, position = 1, ValueFromPipeline = $true)] | ||
[PSObject]$arp | ||
) | ||
|
||
Begin { | ||
} | ||
|
||
Process { | ||
$table = @() | ||
|
||
#Get list of vrf name | ||
$list_arp_vrf_name = $arp.psobject.properties.name | ||
|
||
foreach ($arp_vrf_name in $list_arp_vrf_name) { | ||
$list_arp = $arp.$arp_vrf_name | ||
|
||
#get List of arp name (IP + Vlan...) | ||
$list_arp_name = $list_arp.psobject.properties.name | ||
|
||
foreach ($arp_name in $list_arp_name) { | ||
$ipvlan = $arp.$arp_vrf_name.$arp_name | ||
$table += [pscustomobject]@{ | ||
"ip_address" = $ipvlan.ip_address | ||
"mac" = $ipvlan.mac | ||
"vlan" = $ipvlan.port.psobject.properties.name | ||
"port" = $ipvlan.phy_port.psobject.properties.name | ||
"vrf" = $arp_vrf_name | ||
} | ||
} | ||
} | ||
$table | ||
} | ||
|
||
End { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# | ||
# Copyright 2021, Alexis La Goutte <alexis dot lagoutte at gmail dot com> | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
function Get-ArubaCXMACs { | ||
|
||
|
||
<# | ||
.SYNOPSIS | ||
Get list of MACs (MAC Address Table) | ||
|
||
.DESCRIPTION | ||
Get list of MACs (Mac Address, type, vlan...) | ||
|
||
.EXAMPLE | ||
Get-ArubaCXMACs | ||
|
||
Get Neighbors (MAC Address Table) information on all Vlans | ||
|
||
.EXAMPLE | ||
Get-ArubaCXMACs -vlan MyVlan | ||
|
||
Get Neighbors (MAC Address Table) information on vlan MyVlan | ||
|
||
.EXAMPLE | ||
Get-ArubaCXVlans MyVlan | Get-ArubaCXMACs | ||
|
||
Get Neighbors (MAC Address Table) information on vlan MyVlan (using pipeline) | ||
|
||
#> | ||
|
||
[CmdletBinding(DefaultParametersetname = "Default")] | ||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "")] | ||
Param( | ||
[Parameter (Mandatory = $false, ValueFromPipeline = $true, ParameterSetName = "vlan")] | ||
[ValidateScript( { Confirm-ArubaCXVlans $_ })] | ||
[psobject]$vlan_pp, | ||
[Parameter(Mandatory = $false, position = 1, ParameterSetName = "id")] | ||
[String]$vlan = "*", | ||
[Parameter(Mandatory = $false)] | ||
[ValidateRange(1, 4)] | ||
[Int]$depth, | ||
[Parameter(Mandatory = $false)] | ||
[ValidateSet("configuration", "status", "statistics", "writable")] | ||
[String]$selector, | ||
[Parameter(Mandatory = $false)] | ||
[String[]]$attributes, | ||
[Parameter(Mandatory = $false)] | ||
[switch]$vsx_peer, | ||
[Parameter (Mandatory = $False)] | ||
[ValidateNotNullOrEmpty()] | ||
[PSObject]$connection = $DefaultArubaCXConnection | ||
) | ||
|
||
Begin { | ||
} | ||
|
||
Process { | ||
|
||
#get vlan id from vlan_pp ps object (passed by pipeline) | ||
if ($vlan_pp) { | ||
$vlan = $vlan_pp.id | ||
} | ||
|
||
$invokeParams = @{ } | ||
if ( $PsBoundParameters.ContainsKey('depth') ) { | ||
$invokeParams.add( 'depth', $depth ) | ||
} | ||
if ( $PsBoundParameters.ContainsKey('selector') ) { | ||
$invokeParams.add( 'selector', $selector ) | ||
} | ||
if ( $PsBoundParameters.ContainsKey('attributes') ) { | ||
$invokeParams.add( 'attributes', $attributes ) | ||
} | ||
if ( $PsBoundParameters.ContainsKey('vsx_peer') ) { | ||
$invokeParams.add( 'vsx_peer', $true ) | ||
} | ||
|
||
$uri = "system/vlans/$vlan/macs" | ||
|
||
$response = Invoke-ArubaCXRestMethod -uri $uri -method 'GET' -connection $connection @invokeParams | ||
$response | ||
} | ||
|
||
End { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# | ||
# Copyright 2021, Alexis La Goutte <alexis dot lagoutte at gmail dot com> | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
function Get-ArubaCXNeighbors { | ||
|
||
|
||
<# | ||
.SYNOPSIS | ||
Get list of Neighbors (ARP Table) | ||
|
||
.DESCRIPTION | ||
Get list of Neighbors (Mac Address, IP Address, type, vlan...) | ||
|
||
.EXAMPLE | ||
Get-ArubaCXNeighbors | ||
|
||
Get Neighbors (ARP Table) information on all VRF | ||
|
||
.EXAMPLE | ||
Get-ArubaCXNeighbors -vrf MyVRF | ||
|
||
Get Neighbors (ARP Table) information on vrf MyVRF | ||
|
||
.EXAMPLE | ||
Get-ArubaCXVrfs MyVRF | Get-ArubaCXNeighbors | ||
|
||
Get Neighbors (ARP Table) information on vrf MyVRF (using pipeline) | ||
|
||
#> | ||
|
||
[CmdletBinding(DefaultParametersetname = "Default")] | ||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "")] | ||
Param( | ||
[Parameter (Mandatory = $false, ValueFromPipeline = $true, ParameterSetName = "vrf_pp")] | ||
[ValidateScript( { Confirm-ArubaCXVrfs $_ })] | ||
[psobject]$vrf_pp, | ||
[Parameter(Mandatory = $false, position = 1, ParameterSetName = "vrf")] | ||
[String]$vrf = "*", | ||
[Parameter(Mandatory = $false)] | ||
[ValidateRange(1, 4)] | ||
[Int]$depth, | ||
[Parameter(Mandatory = $false)] | ||
[ValidateSet("configuration", "status", "statistics", "writable")] | ||
[String]$selector, | ||
[Parameter(Mandatory = $false)] | ||
[String[]]$attributes, | ||
[Parameter(Mandatory = $false)] | ||
[switch]$vsx_peer, | ||
[Parameter (Mandatory = $False)] | ||
[ValidateNotNullOrEmpty()] | ||
[PSObject]$connection = $DefaultArubaCXConnection | ||
) | ||
|
||
Begin { | ||
} | ||
|
||
Process { | ||
|
||
#get vrf name from vrf_pp ps object (passed by pipeline) | ||
if ($vrf_pp) { | ||
$vrf = $vrf_pp.name | ||
} | ||
|
||
$invokeParams = @{ } | ||
if ( $PsBoundParameters.ContainsKey('depth') ) { | ||
$invokeParams.add( 'depth', $depth ) | ||
} | ||
if ( $PsBoundParameters.ContainsKey('selector') ) { | ||
$invokeParams.add( 'selector', $selector ) | ||
} | ||
if ( $PsBoundParameters.ContainsKey('attributes') ) { | ||
$invokeParams.add( 'attributes', $attributes ) | ||
} | ||
if ( $PsBoundParameters.ContainsKey('vsx_peer') ) { | ||
$invokeParams.add( 'vsx_peer', $true ) | ||
} | ||
|
||
$uri = "system/vrfs/$vrf/neighbors" | ||
|
||
$response = Invoke-ArubaCXRestMethod -uri $uri -method 'GET' -connection $connection @invokeParams | ||
$response | ||
} | ||
|
||
End { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# | ||
# Copyright 2020, Alexis La Goutte <alexis dot lagoutte at gmail dot com> | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
. ../common.ps1 | ||
|
||
BeforeAll { | ||
Connect-ArubaCX @invokeParams | ||
} | ||
|
||
#Only Basic check because no neighbor... (need to add some peer switch) | ||
Describe "Get (Vlan) Macs (Mac Address Table)" { | ||
|
||
BeforeAll { | ||
Add-ArubaCXVlans -id $pester_vlan -name pester_vlan | ||
} | ||
|
||
It "Get MACs not throw an error" { | ||
{ | ||
Get-ArubaCXMACs | ||
} | Should -Not -Throw | ||
} | ||
|
||
It "Get MACs with a vlan ($pester_vlan) Does not throw an error" { | ||
{ | ||
Get-ArubaCXMACs -vlan $pester_vlan | ||
} | Should -Not -Throw | ||
} | ||
|
||
It "Get MACs with a pipeline vlan ($pester_vlan) Does not throw an error" { | ||
{ | ||
Get-ArubaCXVlans -id $pester_vlan | Get-ArubaCXMACs | ||
} | Should -Not -Throw | ||
} | ||
|
||
Context "Depth" { | ||
|
||
It "Get Neighbor with depth equal 1" { | ||
{ | ||
Get-ArubaCXMACs -depth 1 | ||
} | Should -Not -Throw | ||
} | ||
|
||
It "Get MACs with depth equal 2" { | ||
{ | ||
Get-ArubaCXMACs -depth 2 | ||
} | Should -Not -Throw | ||
} | ||
|
||
It "Get MACs with depth equal 3" { | ||
{ | ||
Get-ArubaCXMACs -depth 3 | ||
} | Should -Not -Throw | ||
} | ||
|
||
It "Get MACs with depth equal 4" { | ||
{ | ||
Get-ArubaCXMACs -depth 4 | ||
} | Should -Not -Throw | ||
} | ||
|
||
} | ||
|
||
AfterAll { | ||
Get-ArubaCXVlans -id $pester_vlan | Remove-ArubaCXVlans -confirm:$false | ||
#Reverse CheckPoint ? | ||
} | ||
} | ||
|
||
AfterAll { | ||
Disconnect-ArubaCX -confirm:$false | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mutual exclusive... ?