Skip to content
This repository has been archived by the owner on Oct 28, 2022. It is now read-only.

Commit

Permalink
cliSettings: Remove [Get|Set]-NsxcliSettings
Browse files Browse the repository at this point in the history
use Set-NsxEdge for modify cliSettings
  • Loading branch information
alagoutte committed Jul 31, 2019
1 parent 44a1e1e commit 6b031bc
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 178 deletions.
2 changes: 0 additions & 2 deletions module/Include.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ $FunctionsToExport = @(
'Get-NsxEdgeStatus',
'Enable-NsxEdgeSsh',
'Disable-NsxEdgeSsh',
'Get-NsxcliSettings',
'Set-NsxcliSettings',
'Set-NsxEdgeNat',
'Get-NsxEdgeNat',
'Get-NsxEdgeNatRule',
Expand Down
176 changes: 0 additions & 176 deletions module/PowerNSX.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6b031bc

Please sign in to comment.