From a8257f47abdd29e8c5724f5e7e9966033b10accf Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Mon, 27 May 2024 11:21:16 +0200 Subject: [PATCH 1/8] DHCPRelay: Add Get-ArubaCXDHCPRelay --- PowerArubaCX/Public/DHCPRelay.ps1 | 77 +++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 PowerArubaCX/Public/DHCPRelay.ps1 diff --git a/PowerArubaCX/Public/DHCPRelay.ps1 b/PowerArubaCX/Public/DHCPRelay.ps1 new file mode 100644 index 0000000..63797f0 --- /dev/null +++ b/PowerArubaCX/Public/DHCPRelay.ps1 @@ -0,0 +1,77 @@ +# +# Copyright 2020, Alexis La Goutte +# +# SPDX-License-Identifier: Apache-2.0 +# + + +function Get-ArubaCXDHCPRelay { + + <# + .SYNOPSIS + Get list of all Aruba CX DHCP Relay + + .DESCRIPTION + Get list of all Aruba CX DHCP Relay + + .EXAMPLE + Get-ArubaCXDHCPRelay + + Get list of all DHCP Relay (IP, port, vrf...) + + #> + + [CmdletBinding(DefaultParametersetname = "Default")] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "")] + Param( + [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 { + + + $invokeParams = @{ } + if ( $PsBoundParameters.ContainsKey('depth') ) { + $invokeParams.add( 'depth', $depth ) + } + if ( $PsBoundParameters.ContainsKey('selector') ) { + #You need to specify a vlan for use writable selector (it is not possible to use on collections...) + if ($PSCmdlet.ParameterSetName -eq "Default" -and $selector -eq "writable") { + Throw "You need to specify a vlan (id or name) to use writable 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/dhcp_relays" + + $response = Invoke-ArubaCXRestMethod -uri $uri -method 'GET' -connection $connection @invokeParams + + $response + + } + + End { + } +} + From 12bd87132d80fe2c8699d52a15b55cfbf1e25301 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Mon, 27 May 2024 11:35:37 +0200 Subject: [PATCH 2/8] DHCPRelay: Add filter by port (interface) and vrf For example : Get-ArubaCXDHCPRelay -port vlan1 --- PowerArubaCX/Public/DHCPRelay.ps1 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/PowerArubaCX/Public/DHCPRelay.ps1 b/PowerArubaCX/Public/DHCPRelay.ps1 index 63797f0..5fef3a7 100644 --- a/PowerArubaCX/Public/DHCPRelay.ps1 +++ b/PowerArubaCX/Public/DHCPRelay.ps1 @@ -19,11 +19,24 @@ function Get-ArubaCXDHCPRelay { Get list of all DHCP Relay (IP, port, vrf...) + .EXAMPLE + Get-ArubaCXDHCPRelay -port vlan1 + + Get vlan with with port (interface) vlan 1 (and vrf default) + + .EXAMPLE + Get-ArubaCXDHCPRelay -port vlan2 -vrf MyVrf + + Get vlan with with port (interface) vlan 2 (and vrf MyVRF) #> [CmdletBinding(DefaultParametersetname = "Default")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "")] Param( + [Parameter (Mandatory = $false)] + [string]$port, + [Parameter (Mandatory = $false)] + [string]$vrf = 'default', [Parameter(Mandatory = $false)] [ValidateRange(1, 4)] [Int]$depth, @@ -65,6 +78,10 @@ function Get-ArubaCXDHCPRelay { $uri = "system/dhcp_relays" + if ($PsBoundParameters.ContainsKey('port')) { + $uri += "/$vrf,$port" + } + $response = Invoke-ArubaCXRestMethod -uri $uri -method 'GET' -connection $connection @invokeParams $response From ac3962fff999f5119efd741a862958886aade341 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Mon, 27 May 2024 13:02:55 +0200 Subject: [PATCH 3/8] DHCPRelay: Add Add-ArubaCXDHCPRelay for configure DHCP Relay --- PowerArubaCX/Public/DHCPRelay.ps1 | 62 +++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/PowerArubaCX/Public/DHCPRelay.ps1 b/PowerArubaCX/Public/DHCPRelay.ps1 index 5fef3a7..c71dcd4 100644 --- a/PowerArubaCX/Public/DHCPRelay.ps1 +++ b/PowerArubaCX/Public/DHCPRelay.ps1 @@ -4,6 +4,68 @@ # SPDX-License-Identifier: Apache-2.0 # +function Add-ArubaCXDHCPRelay { + + <# + .SYNOPSIS + Add Aruba CX DHCP Relay + + .DESCRIPTION + Add DHCP Relay (IP, port, vrf...) + + .EXAMPLE + Add-ArubaCXDHCPRelay -port vlan1 -ipv4_ucast_server 192.2.0.1 + + Add IP DHCP relay 192.2.0.1 on port(interface) vlan1 with default vrf + + .EXAMPLE + Add-ArubaCXDHCPRelay -port vlan2 -ipv4_ucast_server 192.2.0.1, 192.2.0.2 -vrf MyVRF + + Add IP DHCP relay 192.2.0.1, 192.2.0.2 on port(interface) vlan2 with default MyVRF + #> + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "")] + Param( + [Parameter (Mandatory = $true)] + [string]$port, + [Parameter (Mandatory = $false)] + [string]$vrf = "default", + [Parameter (Mandatory = $true)] + [string[]]$ipv4_ucast_server, + [Parameter (Mandatory = $False)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection = $DefaultArubaCXConnection + ) + + Begin { + } + + Process { + + $uri = "system/dhcp_relays" + + $_dhcprelay = new-Object -TypeName PSObject + + $_vrf = New-Object -TypeName PSObject + $vrf_uri = "/rest/" + $($connection.api_version) + "/system/vrfs/" + $vrf + $_vrf | Add-Member -name $vrf -membertype NoteProperty -Value $vrf_uri + $_dhcprelay | Add-Member -name "vrf" -membertype NoteProperty -Value $_vrf + + $_port = New-Object -TypeName PSObject + $port_uri = "/rest/" + $($connection.api_version) + "/system/interfaces/" + $port + $_port | Add-Member -name $port -membertype NoteProperty -Value $port_uri + $_dhcprelay | Add-Member -name "port" -membertype NoteProperty -Value $_port + + $_dhcprelay | Add-Member -name "ipv4_ucast_server" -membertype NoteProperty -Value @($ipv4_ucast_server) + + $response = Invoke-ArubaCXRestMethod -uri $uri -method 'POST' -body $_dhcprelay -connection $connection + $response + + Get-ArubaCXDHCPRelay -port $port -vrf $vrf -connection $connection + } + + End { + } +} function Get-ArubaCXDHCPRelay { From 38ba873c4fe8f453fd8543bc88acb9d8b4b5ec39 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Mon, 27 May 2024 13:19:06 +0200 Subject: [PATCH 4/8] DHCPRelay: Add Confirm DHCP Relay --- PowerArubaCX/Private/Confirm.ps1 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/PowerArubaCX/Private/Confirm.ps1 b/PowerArubaCX/Private/Confirm.ps1 index a514d44..b95c22a 100644 --- a/PowerArubaCX/Private/Confirm.ps1 +++ b/PowerArubaCX/Private/Confirm.ps1 @@ -4,6 +4,27 @@ # SPDX-License-Identifier: Apache-2.0 # +function Confirm-ArubaCXDHCPRelay { + + Param ( + [Parameter (Mandatory = $true)] + [object]$argument + ) + #Check if it looks like an DHCP Relay element + + if ( -not ( $argument | get-member -name port -Membertype Properties)) { + throw "Element specified does not contain a port property." + } + if ( -not ( $argument | get-member -name vrf -Membertype Properties)) { + throw "Element specified does not contain a vrf property." + } + if ( -not ( $argument | get-member -name ipv4_ucast_server -Membertype Properties)) { + throw "Element specified does not contain an ipv4_ucast_server property." + } + $true + +} + function Confirm-ArubaCXInterfaces { [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "")] From e0d09508449526823429ce7d21a0bd4755f5b179 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Mon, 27 May 2024 13:26:41 +0200 Subject: [PATCH 5/8] DHCPRelay: Add Remove-ArubaCXDHCPRelay --- PowerArubaCX/Public/DHCPRelay.ps1 | 60 +++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/PowerArubaCX/Public/DHCPRelay.ps1 b/PowerArubaCX/Public/DHCPRelay.ps1 index c71dcd4..f7c9508 100644 --- a/PowerArubaCX/Public/DHCPRelay.ps1 +++ b/PowerArubaCX/Public/DHCPRelay.ps1 @@ -154,3 +154,63 @@ function Get-ArubaCXDHCPRelay { } } +function Remove-ArubaCXDHCPRelay { + + <# + .SYNOPSIS + Remove a DHCP Relay on Aruba CX Switch + + .DESCRIPTION + Remove a DHCP Relay on Aruba CX Switch + + .EXAMPLE + $dhcprelay = Get-ArubaCXDHCPRelay -port vlan1 + PS C:\>$dhcprelay | Remove-ArubaCXDHCPRelay + + Remove DHCP Relay configured on port/interface vlan1 + + .EXAMPLE + Remove-ArubaCXDHCPRelay -port vlan1 -vrf myVRF -confirm:$false + + Remove DHCP Relay with port vlan1 and vrf myVRF with no confirmation + #> + + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'high')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "")] + Param( + [Parameter (Mandatory = $true, ParameterSetName = "portvrf")] + [string]$port, + [Parameter (Mandatory = $false, ParameterSetName = "portvrf")] + [string]$vrf = "default", + [Parameter (Mandatory = $true, ValueFromPipeline = $true, Position = 1, ParameterSetName = "dhcprelay")] + [ValidateScript( { Confirm-ArubaCXDHCPRelay $_ })] + [psobject]$dhcprelay, + [Parameter (Mandatory = $False)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection = $DefaultArubaCXConnection + ) + + Begin { + } + + Process { + + #get dhcprelay vrf/port from dhcprelay ps object + if ($dhcprelay) { + #Get the name of properties... + $port = $dhcprelay.port.psobject.properties.name + $vrf = $dhcprelay.vrf.psobject.properties.name + } + + $uri = "system/dhcp_relays/${vrf},${port}" + + if ($PSCmdlet.ShouldProcess("DHCP Relay", "Remove DHCP Relay ${port} on ${vrf}")) { + Write-Progress -activity "Remove DHCP Relay" + Invoke-ArubaCXRestMethod -method "DELETE" -uri $uri -connection $connection + Write-Progress -activity "Remove DHCP Relay" -completed + } + } + + End { + } +} \ No newline at end of file From 96dea7104cb6acb67f507caab4ae08e5fa9d588c Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Mon, 27 May 2024 14:01:23 +0200 Subject: [PATCH 6/8] DHCPRelay: Add Set-ArubaCXDHCPRelay for configure ipv4_ucast_server (DHCP Helper...) --- PowerArubaCX/Public/DHCPRelay.ps1 | 77 +++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/PowerArubaCX/Public/DHCPRelay.ps1 b/PowerArubaCX/Public/DHCPRelay.ps1 index f7c9508..30cf479 100644 --- a/PowerArubaCX/Public/DHCPRelay.ps1 +++ b/PowerArubaCX/Public/DHCPRelay.ps1 @@ -154,6 +154,83 @@ function Get-ArubaCXDHCPRelay { } } +function Set-ArubaCXDHCPRelay { + + <# + .SYNOPSIS + Configure Aruba CX DHCP Rleay + + .DESCRIPTION + Configure DHCP Relay (ipv4_ucast_server) + + .EXAMPLE + Get-ArubaCXDHCPRelay -port vlan1 | Set-ArubaCXDHCPRelay -ipv4_ucast_server 192.2.0.3 + + Change the ipv4_ucast_server (192.2.0.3) on DHCP Relay vlan1 (vrf default) + + .EXAMPLE + Get-ArubaCXDHCPRelay -port vlan1 | Set-ArubaCXDHCPRelay -ipv4_ucast_server 192.2.0.3, 192.2.0.4 + + Change the ipv4_ucast_server (192.2.0.3, 192.2.0.4) on DHCP Relay vlan2 and vrf myVRF + + #> + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'medium')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "")] + Param( + [Parameter (Mandatory = $true, ParameterSetName = "portvrf")] + [string]$port, + [Parameter (Mandatory = $false, ParameterSetName = "portvrf")] + [string]$vrf = "default", + [Parameter (Mandatory = $true, ValueFromPipeline = $true, Position = 1, ParameterSetName = "dhcprelay")] + [ValidateScript( { Confirm-ArubaCXDHCPRelay $_ })] + [psobject]$dhcprelay, + [Parameter (Mandatory = $false)] + [string[]]$ipv4_ucast_server, + [Parameter (Mandatory = $false)] + [switch]$use_pipeline, + [Parameter (Mandatory = $False)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection = $DefaultArubaCXConnection + ) + + Begin { + } + + Process { + + #get dhcprelay vrf/port from dhcprelay ps object + if ($dhcprelay) { + #Get the name of properties... + $port = $dhcprelay.port.psobject.properties.name + $vrf = $dhcprelay.vrf.psobject.properties.name + } + + $uri = "system/dhcp_relays/${vrf},${port}" + + if ($use_pipeline) { + $_dhcprelay = $dhcprelay + } + else { + $_dhcprelay = Get-ArubaCXDHCPRelay -port $port -vrf $vrf -selector writable -connection $connection + } + + if ( $PsBoundParameters.ContainsKey('ipv4_ucast_server') ) { + $_dhcprelay.ipv4_ucast_server = @($ipv4_ucast_server) + } + + if ($PSCmdlet.ShouldProcess("DHCP Relay", "Configure DHCP Relay ${port} on ${vrf}")) { + $response = Invoke-ArubaCXRestMethod -uri $uri -method 'PUT' -body $_dhcprelay -connection $connection + $response + } + + Get-ArubaCXDHCRelay -port $port -vrf $vrf -connection $connection + } + + End { + } +} + + function Remove-ArubaCXDHCPRelay { <# From 1b7ade9e492870e41f43bd4294f5633a4250f26c Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Mon, 27 May 2024 14:11:37 +0200 Subject: [PATCH 7/8] DHCPRelay: fix msising parametersetname for get --- PowerArubaCX/Public/DHCPRelay.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PowerArubaCX/Public/DHCPRelay.ps1 b/PowerArubaCX/Public/DHCPRelay.ps1 index 30cf479..aa203d8 100644 --- a/PowerArubaCX/Public/DHCPRelay.ps1 +++ b/PowerArubaCX/Public/DHCPRelay.ps1 @@ -95,9 +95,9 @@ function Get-ArubaCXDHCPRelay { [CmdletBinding(DefaultParametersetname = "Default")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "")] Param( - [Parameter (Mandatory = $false)] + [Parameter (Mandatory = $false, ParameterSetName = "vrfport")] [string]$port, - [Parameter (Mandatory = $false)] + [Parameter (Mandatory = $false, ParameterSetName = "vrfport")] [string]$vrf = 'default', [Parameter(Mandatory = $false)] [ValidateRange(1, 4)] From f9b5ff47f6170509e0102a6fa4b73d2d94707b92 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Mon, 27 May 2024 14:11:59 +0200 Subject: [PATCH 8/8] DHCPRelay: fix typo for get on set --- PowerArubaCX/Public/DHCPRelay.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerArubaCX/Public/DHCPRelay.ps1 b/PowerArubaCX/Public/DHCPRelay.ps1 index aa203d8..a0a28b9 100644 --- a/PowerArubaCX/Public/DHCPRelay.ps1 +++ b/PowerArubaCX/Public/DHCPRelay.ps1 @@ -223,7 +223,7 @@ function Set-ArubaCXDHCPRelay { $response } - Get-ArubaCXDHCRelay -port $port -vrf $vrf -connection $connection + Get-ArubaCXDHCPRelay -port $port -vrf $vrf -connection $connection } End {