From 6b031bc4f67a5e52cc7593062cc46dc9ba8e397c Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Fri, 16 Mar 2018 11:52:39 +0100 Subject: [PATCH] cliSettings: Remove [Get|Set]-NsxcliSettings use Set-NsxEdge for modify cliSettings --- module/Include.ps1 | 2 - module/PowerNSX.psm1 | 176 ------------------------------------------- 2 files changed, 178 deletions(-) diff --git a/module/Include.ps1 b/module/Include.ps1 index ada22a80..f91e50e8 100644 --- a/module/Include.ps1 +++ b/module/Include.ps1 @@ -99,8 +99,6 @@ $FunctionsToExport = @( 'Get-NsxEdgeStatus', 'Enable-NsxEdgeSsh', 'Disable-NsxEdgeSsh', - 'Get-NsxcliSettings', - 'Set-NsxcliSettings', 'Set-NsxEdgeNat', 'Get-NsxEdgeNat', 'Get-NsxEdgeNatRule', diff --git a/module/PowerNSX.psm1 b/module/PowerNSX.psm1 index 0071a295..7cd39ff2 100644 --- a/module/PowerNSX.psm1 +++ b/module/PowerNSX.psm1 @@ -14301,182 +14301,6 @@ function Disable-NsxEdgeSsh { } -function Get-NsxcliSettings { - - <# - .SYNOPSIS - Gets cliSettings (userName, Status, ssh banner...) of a ESG - - .DESCRIPTION - An NSX Edge Service Gateway provides all NSX Edge services such as firewall, - NAT, DHCP, VPN, load balancing, and high availability. Each NSX Edge virtual - appliance can have a total of ten uplink and internal network interfaces and - up to 200 subinterfaces. Multiple external IP addresses can be configured - for load balancer, site‐to‐site VPN, and NAT services. - - The Get-NsxcliSettings cmdlet retreives the cli Settings of the ESG - - .EXAMPLE - Get-NsxEdge Edge01 | Get-NsxcliSettings - - Get current cli Settings - - #> - - param ( - [Parameter (Mandatory=$true,ValueFromPipeline=$true,Position=1)] - [ValidateScript({ ValidateEdge $_ })] - [System.Xml.XmlElement]$Edge - ) - - begin {} - - process { - #We append the Edge-id to the associated config XML to enable pipeline workflows and - #consistent readable output - - $_cliSettings = $Edge.cliSettings.CloneNode($True) - Add-XmlElement -xmlRoot $_cliSettings -xmlElementName "edgeId" -xmlElementText $Edge.Id - $_cliSettings - } - - end {} -} - -function Set-NsxcliSettings { - - <# - .SYNOPSIS - Set cliSettings (userName, Status, ssh banner...) of a ESG - - .DESCRIPTION - An NSX Edge Service Gateway provides all NSX Edge services such as firewall, - NAT, DHCP, VPN, load balancing, and high availability. Each NSX Edge virtual - appliance can have a total of ten uplink and internal network interfaces and - up to 200 subinterfaces. Multiple external IP addresses can be configured - for load balancer, site‐to‐site VPN, and NAT services. - - The Set-NsxcliSettings cmdlet configure the cli Settings of the ESG - it is mandatory to specified the password... - - .EXAMPLE - Get-NsxEdge Edge01 | Get-NsxcliSettings | Set-NsxCliSettings -password Vmware1!Vmware1! - - Change the SSH Password - - .EXAMPLE - Get-NsxEdge Edge01 | Get-NsxcliSettings | Set-NsxCliSettings -password Vmware1!Vmware1! -remoteAccess:$true - - Enable the SSH on ESG (you can use also use Enable-NsxSSHEdgeSSH) - - .EXAMPLE - Get-NsxEdge Edge01 | Get-NsxcliSettings | Set-NsxCliSettings -password Vmware1!Vmware1! -username powernsx - - Set the SSH username to PowerNSX - - .EXAMPLE - Get-NsxEdge Edge01 | Get-NsxcliSettings | Set-NsxCliSettings -password Vmware1!Vmware1! -sshLoginBannerText "My Login Banner" - - Change the SSH Login Banner - - .EXAMPLE - Get-NsxEdge Edge01 | Get-NsxcliSettings | Set-NsxCliSettings -password Vmware1!Vmware1! -passwordExpiry 30 - - Change the SSH Password Expiration to 30 (days) - - #> - - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidDefaultValueSwitchParameter","")] # Cant remove without breaking backward compatibility - param ( - [Parameter (Mandatory=$true,ValueFromPipeline=$true,Position=1)] - [ValidateScript({ ValidateCliSettings $_ })] - [System.Xml.XmlElement]$cliSettings, - [Parameter (Mandatory=$false)] - [ValidateNotNullorEmpty()] - [String]$userName, - [Parameter (Mandatory=$true)] - [ValidateNotNullorEmpty()] - [String]$password, - [Parameter (Mandatory=$false)] - [ValidateNotNullorEmpty()] - [boolean]$remoteAccess, - [Parameter (Mandatory=$false)] - [ValidateNotNullorEmpty()] - [ValidateRange(1,99999)] - [int]$passwordExpiry, - [Parameter (Mandatory=$false)] - [ValidateNotNullorEmpty()] - [string]$sshLoginBannerText, - [Parameter (Mandatory=$False)] - #PowerNSX Connection object - [ValidateNotNullOrEmpty()] - [PSCustomObject]$Connection=$defaultNSXConnection - ) - - begin { } - - process { - #Create private xml element - $_cliSettings = $cliSettings.CloneNode($true) - - #Store the edgeId and remove it from the XML as we need to post it... - $edgeId = $_cliSettings.edgeId - $_cliSettings.RemoveChild( $((Invoke-XPathQuery -QueryMethod SelectSingleNode -Node $_cliSettings -Query 'descendant::edgeId')) ) | out-null - - #Using PSBoundParamters.ContainsKey lets us know if the user called us with a given parameter. - #If the user did not specify a given parameter, we dont want to modify from the existing value. - - if ( $PsBoundParameters.ContainsKey('userName') ) { - if ( invoke-xpathquery -node $_cliSettings -querymethod SelectSingleNode -Query "child::userName" ) { - $_cliSettings.username = $userName - } else { - Add-XmlElement -xmlroot $_cliSettings -xmlElementName "userName" -xmlElementText $userName - } - } - - #You need ALWAYS to specified the password... - if ( invoke-xpathquery -node $_cliSettings -querymethod SelectSingleNode -Query "child::password" ) { - $_cliSettings.password = $password - } else { - Add-XmlElement -xmlRoot $_cliSettings -xmlElementName "password" -xmlElementText $password - } - - if ( $PsBoundParameters.ContainsKey('remoteAccess') ) { - if ( invoke-xpathquery -node $_cliSettings -querymethod SelectSingleNode -Query "child::remoteAccess" ) { - $_cliSettings.remoteAccess = $remoteAccess.ToString().ToLower() - } else { - Add-XmlElement -xmlroot $_cliSettings -xmlElementName "remoteAccess" -xmlElementText $remoteAccess.ToString().ToLower() - } - } - - if ( $PsBoundParameters.ContainsKey('passwordExpiry') ) { - if ( invoke-xpathquery -node $_cliSettings -querymethod SelectSingleNode -Query "child::passwordExpiry" ) { - $_cliSettings.passwordExpiry = $passwordExpiry - } else { - Add-XmlElement -xmlroot $_cliSettings -xmlElementName "passwordExpiry" -xmlElementText $passwordExpiry - } - } - - if ( $PsBoundParameters.ContainsKey('sshLoginBannerText') ) { - if ( invoke-xpathquery -node $_cliSettings -querymethod SelectSingleNode -Query "child::sshLoginBannerText" ) { - $_cliSettings.sshLoginBannerText = $sshLoginBannerText - } else { - Add-XmlElement -xmlroot $_cliSettings -xmlElementName "sshLoginBannerText" -xmlElementText $sshLoginBannerText - } - } - - $URI = "/api/4.0/edges/$($EdgeId)/clisettings" - $body = $_cliSettings.OuterXml - - Write-Progress -activity "Update Edge Services Gateway (cliSettings) $($edgeId)" - $response = invoke-nsxwebrequest -method "put" -uri $URI -body $body -connection $connection - Write-Progress -activity "Update Edge Services Gateway (cliSettings) $($edgeId)" -completed - Get-NsxEdge -objectId $($edgeId) -connection $connection | Get-NsxcliSettings - } - - end {} -} - ######### ######### # Edge NAT related functions