diff --git a/PowerArubaCX/Private/ConvertTo.ps1 b/PowerArubaCX/Private/ConvertTo.ps1 new file mode 100644 index 0000000..c44a123 --- /dev/null +++ b/PowerArubaCX/Private/ConvertTo.ps1 @@ -0,0 +1,110 @@ +# +# Copyright 2024, Alexis La Goutte +# +# 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 { + } + +} \ No newline at end of file diff --git a/PowerArubaCX/Public/Macs.ps1 b/PowerArubaCX/Public/Macs.ps1 new file mode 100644 index 0000000..e62ba41 --- /dev/null +++ b/PowerArubaCX/Public/Macs.ps1 @@ -0,0 +1,88 @@ +# +# Copyright 2021, Alexis La Goutte +# +# 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 { + } +} \ No newline at end of file diff --git a/PowerArubaCX/Public/Neighbors.ps1 b/PowerArubaCX/Public/Neighbors.ps1 new file mode 100644 index 0000000..f99278a --- /dev/null +++ b/PowerArubaCX/Public/Neighbors.ps1 @@ -0,0 +1,88 @@ +# +# Copyright 2021, Alexis La Goutte +# +# 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 { + } +} \ No newline at end of file diff --git a/Tests/integration/Macs.Tests.ps1 b/Tests/integration/Macs.Tests.ps1 new file mode 100644 index 0000000..16bfd4c --- /dev/null +++ b/Tests/integration/Macs.Tests.ps1 @@ -0,0 +1,73 @@ +# +# Copyright 2020, Alexis La Goutte +# +# 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 +} \ No newline at end of file diff --git a/Tests/integration/Neighbors.Tests.ps1 b/Tests/integration/Neighbors.Tests.ps1 new file mode 100644 index 0000000..617ac34 --- /dev/null +++ b/Tests/integration/Neighbors.Tests.ps1 @@ -0,0 +1,73 @@ +# +# Copyright 2020, Alexis La Goutte +# +# 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 (Vrf) Neighbors (ARP Table)" { + + BeforeAll { + Add-ArubaCXVrfs -name $pester_vrf + } + + It "Get Neighbors not throw an error" { + { + Get-ArubaCXNeighbors + } | Should -Not -Throw + } + + It "Get Neighbors with a vrf ($pester_vrf) Does not throw an error" { + { + Get-ArubaCXNeighbors -vrf $pester_vrf + } | Should -Not -Throw + } + + It "Get Neighbors with a pipeline vrf ($pester_vrf) Does not throw an error" { + { + Get-ArubaCXVrfs $pester_vrf | Get-ArubaCXNeighbors + } | Should -Not -Throw + } + + Context "Depth" { + + It "Get Neighbor with depth equal 1" { + { + Get-ArubaCXNeighbors -depth 1 + } | Should -Not -Throw + } + + It "Get Neighbors with depth equal 2" { + { + Get-ArubaCXNeighbors -depth 2 + } | Should -Not -Throw + } + + It "Get Neighbors with depth equal 3" { + { + Get-ArubaCXNeighbors -depth 3 + } | Should -Not -Throw + } + + It "Get Neighbors with depth equal 4" { + { + Get-ArubaCXNeighbors -depth 4 + } | Should -Not -Throw + } + + } + + AfterAll { + Get-ArubaCXVrfs -name $pester_vrf | Remove-ArubaCXVrfs -confirm:$false + #Reverse CheckPoint ? + } +} + +AfterAll { + Disconnect-ArubaCX -confirm:$false +} \ No newline at end of file