From 8101407da0f8979644ef09bc98b45556112d95b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Moreau?= Date: Wed, 17 Jun 2020 17:52:02 +0200 Subject: [PATCH 1/4] Add Copy configuration function --- PowerArubaCX/Public/Configuration.ps1 | 48 +++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 PowerArubaCX/Public/Configuration.ps1 diff --git a/PowerArubaCX/Public/Configuration.ps1 b/PowerArubaCX/Public/Configuration.ps1 new file mode 100644 index 0000000..9c559c0 --- /dev/null +++ b/PowerArubaCX/Public/Configuration.ps1 @@ -0,0 +1,48 @@ +function Get-ArubaCXConfiguration { + + <# + .SYNOPSIS + Get Aruba CX running or startup-configuration + + .DESCRIPTION + Get the startup-config or running-config and copy it to a remote location + + .EXAMPLE + Get-ArubaCXConfiguration -local running -remote sftp://192.0.2.1/backups_switchs/arubacx/ -type cli -vrf mgmt + + Get the running-config and copy it to the remote location 192.0.2.1/backups_switchs/arubacx using sftp, in cli format via thr mgmt vrf + #> + + Param( + [Parameter(Mandatory = $true)] + [ValidateSet("running","startup")] + [string]$local, + [Parameter(Mandatory = $false)] + [string]$remote, + [Parameter(Mandatory = $false)] + [ValidateSet("cli","json")] + [string]$type, + [Parameter(Mandatory = $false)] + [string]$vrf, + [Parameter (Mandatory = $False)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection = $DefaultArubaCXConnection + ) + + Begin { + } + + Process { + + $remote = $remote.Replace(":","%3A") + $remote = $remote.Replace("/","%2F") + + $uri = "fullconfigs/${local}-config/?to=${remote}&type=${type}&vrf=${vrf}" + + $response = Invoke-ArubaCXRestMethod -uri $uri -method 'GET' -connection $connection + $response + } + + End { + } +} \ No newline at end of file From d5171fb8f815b8e182eccb0dabf548bd2a7c2824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Moreau?= Date: Wed, 17 Jun 2020 18:00:42 +0200 Subject: [PATCH 2/4] FIx whitespace --- PowerArubaCX/Public/Configuration.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/PowerArubaCX/Public/Configuration.ps1 b/PowerArubaCX/Public/Configuration.ps1 index 9c559c0..79cdd09 100644 --- a/PowerArubaCX/Public/Configuration.ps1 +++ b/PowerArubaCX/Public/Configuration.ps1 @@ -15,12 +15,12 @@ function Get-ArubaCXConfiguration { Param( [Parameter(Mandatory = $true)] - [ValidateSet("running","startup")] + [ValidateSet("running", "startup")] [string]$local, [Parameter(Mandatory = $false)] [string]$remote, [Parameter(Mandatory = $false)] - [ValidateSet("cli","json")] + [ValidateSet("cli", "json")] [string]$type, [Parameter(Mandatory = $false)] [string]$vrf, @@ -34,12 +34,12 @@ function Get-ArubaCXConfiguration { Process { - $remote = $remote.Replace(":","%3A") - $remote = $remote.Replace("/","%2F") + $remote = $remote.Replace(":", "%3A") + $remote = $remote.Replace("/", "%2F") $uri = "fullconfigs/${local}-config/?to=${remote}&type=${type}&vrf=${vrf}" - $response = Invoke-ArubaCXRestMethod -uri $uri -method 'GET' -connection $connection + $response = Invoke-ArubaCXRestMethod -uri $uri -method 'GET' -connection $connection $response } From 69e1a393329e14177c95391e9c95803a2dbc3bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Moreau?= Date: Fri, 19 Jun 2020 11:14:54 +0200 Subject: [PATCH 3/4] Add the retrieve function to get configuration --- PowerArubaCX/Public/Configuration.ps1 | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/PowerArubaCX/Public/Configuration.ps1 b/PowerArubaCX/Public/Configuration.ps1 index 79cdd09..2fddf71 100644 --- a/PowerArubaCX/Public/Configuration.ps1 +++ b/PowerArubaCX/Public/Configuration.ps1 @@ -36,6 +36,7 @@ function Get-ArubaCXConfiguration { $remote = $remote.Replace(":", "%3A") $remote = $remote.Replace("/", "%2F") + $remote = $remote.Replace("@", "%40") $uri = "fullconfigs/${local}-config/?to=${remote}&type=${type}&vrf=${vrf}" @@ -43,6 +44,45 @@ function Get-ArubaCXConfiguration { $response } + End { + } +} + +function Get-ArubaCXConfigurationName { + + <# + .SYNOPSIS + Get Aruba CX running or startup-configuration by the name + + .DESCRIPTION + Get the startup-config or running-config + + .EXAMPLE + Get-ArubaCXConfigurationName -name running + + Get the running-config + #> + + Param( + [Parameter(Mandatory = $true)] + [ValidateSet("running", "startup")] + [string]$name, + [Parameter (Mandatory = $False)] + [ValidateNotNullOrEmpty()] + [PSObject]$connection = $DefaultArubaCXConnection + ) + + Begin { + } + + Process { + + $uri = "fullconfigs/${name}-config" + + $response = Invoke-ArubaCXRestMethod -uri $uri -method 'GET' -connection $connection + $response + } + End { } } \ No newline at end of file From d3d2ecf6f61e457f77d8b8ec71cabfdaaa67f977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Moreau?= Date: Wed, 24 Jun 2020 16:26:11 +0200 Subject: [PATCH 4/4] Add check case sensitivity --- PowerArubaCX/Public/Configuration.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PowerArubaCX/Public/Configuration.ps1 b/PowerArubaCX/Public/Configuration.ps1 index 2fddf71..b880bc5 100644 --- a/PowerArubaCX/Public/Configuration.ps1 +++ b/PowerArubaCX/Public/Configuration.ps1 @@ -65,7 +65,7 @@ function Get-ArubaCXConfigurationName { Param( [Parameter(Mandatory = $true)] - [ValidateSet("running", "startup")] + [ValidateSet("running", "startup", IgnoreCase = $true)] [string]$name, [Parameter (Mandatory = $False)] [ValidateNotNullOrEmpty()] @@ -77,6 +77,7 @@ function Get-ArubaCXConfigurationName { Process { + $name = $name.ToLower() $uri = "fullconfigs/${name}-config" $response = Invoke-ArubaCXRestMethod -uri $uri -method 'GET' -connection $connection