Update function to enable password installation
This commit is contained in:
@@ -1,36 +1,111 @@
|
||||
<# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #>
|
||||
#TODO - Add ability to installed with root password, Move to Begin, Process, End Format
|
||||
function Install-ZertoVra {
|
||||
[cmdletbinding( SupportsShouldProcess = $true )]
|
||||
[cmdletbinding( SupportsShouldProcess )]
|
||||
param(
|
||||
[Parameter( Mandatory = $true, HelpMessage = "Host name where the VRA is to be installed." )]
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
HelpMessage = "Host name where the VRA is to be installed."
|
||||
)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$hostName,
|
||||
[Parameter( Mandatory = $true, HelpMessage = "Datastore name where the VRA is to be installed." )]
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
HelpMessage = "Datastore name where the VRA is to be installed."
|
||||
)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$datastoreName,
|
||||
[Parameter( Mandatory = $true, HelpMessage = "Network name the VRA is to be assigned." )]
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
HelpMessage = "Network name the VRA is to be assigned."
|
||||
)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$networkName,
|
||||
[Parameter( HelpMessage = "Initial amount of memory to assign to the VRA in GB. Default is 3, Minimum is 1, Maximum is 16" )]
|
||||
[Parameter(
|
||||
HelpMessage = "Initial amount of memory to assign to the VRA in GB. Default is 3, Minimum is 1, Maximum is 16"
|
||||
)]
|
||||
[ValidateRange(1, 16)]
|
||||
[int]$memoryInGB = 3,
|
||||
[Parameter( HelpMessage = "Bandwidth group to assign to the VRA. If unspecified will assign to the 'default_group'" )]
|
||||
[Parameter(
|
||||
HelpMessage = "Bandwidth group to assign to the VRA. If unspecified will assign to the 'default_group'"
|
||||
)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$groupName,
|
||||
[Parameter( ParameterSetName = "Dhcp", Mandatory = $true, HelpMessage = "Assign a DHCP address to the VRA." )]
|
||||
[Parameter(
|
||||
ParameterSetName = "Dhcp",
|
||||
Mandatory,
|
||||
HelpMessage = "Assign a DHCP address to the VRA."
|
||||
)]
|
||||
[Parameter(
|
||||
ParameterSetName = "DhcpWithRoot",
|
||||
Mandatory,
|
||||
HelpMessage = "Assign a DHCP address to the VRA."
|
||||
)]
|
||||
[switch]$Dhcp,
|
||||
[Parameter( ParameterSetName = "StaticIp", Mandatory = $true, HelpMessage = "Static IP address to assign to the VRA." )]
|
||||
[Parameter(
|
||||
ParameterSetName = "StaticIp",
|
||||
Mandatory,
|
||||
HelpMessage = "Static IP address to assign to the VRA."
|
||||
)]
|
||||
[Parameter(
|
||||
ParameterSetName = "StaticIpWithRoot",
|
||||
Mandatory,
|
||||
HelpMessage = "Static IP address to assign to the VRA."
|
||||
)]
|
||||
[ValidateScript( { $_ -match [IPAddress]$_ })]
|
||||
[string]$vraIpAddress,
|
||||
[Parameter( ParameterSetName = "StaticIp", Mandatory = $true, HelpMessage = "Default gateway to assign to the VRA" )]
|
||||
[Parameter(
|
||||
ParameterSetName = "StaticIp",
|
||||
Mandatory,
|
||||
HelpMessage = "Default gateway to assign to the VRA"
|
||||
)]
|
||||
[Parameter(
|
||||
ParameterSetName = "StaticIpWithRoot",
|
||||
Mandatory,
|
||||
HelpMessage = "Default gateway to assign to the VRA"
|
||||
)]
|
||||
[ValidateScript( { $_ -match [IPAddress]$_ })]
|
||||
[string]$defaultGateway,
|
||||
[Parameter( ParameterSetName = "StaticIp", Mandatory = $true, HelpMessage = "Subnetmask to be assigned to the VRA" )]
|
||||
[Parameter(
|
||||
ParameterSetName = "StaticIp",
|
||||
Mandatory,
|
||||
HelpMessage = "Subnetmask to be assigned to the VRA"
|
||||
)]
|
||||
[Parameter(
|
||||
ParameterSetName = "StaticIpWithRoot",
|
||||
Mandatory,
|
||||
HelpMessage = "Subnetmask to be assigned to the VRA"
|
||||
)]
|
||||
[ValidateScript( { $_ -match [IPAddress]$_ })]
|
||||
[string]$subnetMask
|
||||
|
||||
[string]$subnetMask,
|
||||
[Parameter(
|
||||
ParameterSetName = "StaticIpWithRoot",
|
||||
Mandatory,
|
||||
HelpMessage = "Use this switch to install the VRA using the root password install method."
|
||||
)]
|
||||
[Parameter(
|
||||
ParameterSetName = "DhcpWithRoot",
|
||||
Mandatory,
|
||||
HelpMessage = "Use this switch to install the VRA using the root password install method."
|
||||
)]
|
||||
[switch]$UseRootCredential,
|
||||
[Parameter(
|
||||
ParameterSetName = "StaticIpWithRoot",
|
||||
Mandatory,
|
||||
HelpMessage = "The password for the root user of the ESXi host where the VRA is to be installed."
|
||||
)]
|
||||
[Parameter(
|
||||
ParameterSetName = "DhcpWithRoot",
|
||||
Mandatory,
|
||||
HelpMessage = "The password for the root user of the ESXi host where the VRA is to be installed."
|
||||
)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[securestring]$HostRootPassword
|
||||
)
|
||||
|
||||
begin {
|
||||
|
||||
}
|
||||
Process {
|
||||
# Build the VRA Name.
|
||||
$vraName = "Z-VRA-{0}" -f $hostName
|
||||
# If the VRA does not exist, proceed with the installation. If it does exist, bypass and
|
||||
@@ -64,7 +139,7 @@ function Install-ZertoVra {
|
||||
$vraBasic['NetworkIdentifier'] = $networkIdentifier.toString()
|
||||
$vraBasic['UsePublicKeyInsteadOfCredentials'] = $true
|
||||
$vraBasicNetwork = [ordered]@{ }
|
||||
if ( $PSCmdlet.ParameterSetName -eq "StaticIp" ) {
|
||||
if ( $PSCmdlet.ParameterSetName -eq "StaticIp" -or $PSCmdlet.ParameterSetName -eq "StaticIpWithRoot") {
|
||||
$vraBasicNetwork['DefaultGateway'] = $defaultGateway.toString()
|
||||
$vraBasicNetwork['SubnetMask'] = $subnetMask.toString()
|
||||
$vraBasicNetwork['VraIPAddress'] = $vraIpAddress.toString()
|
||||
@@ -73,12 +148,22 @@ function Install-ZertoVra {
|
||||
$vraBasicNetwork['VraIPConfigurationTypeApi'] = "Dhcp"
|
||||
}
|
||||
$vraBasic['VraNetworkDataApi'] = $vraBasicNetwork
|
||||
if ($PSCmdlet.ParameterSetName -eq "StaticIpWithRoot" -or $PSCmdlet.ParameterSetName -eq "DhcpWithRoot") {
|
||||
$HostRootCredential = [pscredential]::new('root', $HostRootPassword)
|
||||
$vraBasic['UsePublicKeyInsteadOfCredentials'] = $false
|
||||
$vraBasic['HostRootPassword'] = $HostRootCredential.GetNetworkCredential().Password
|
||||
}
|
||||
|
||||
# Leverage WhatIf functionality to see what might happen, if WhatIf is not specified, attempt to install.
|
||||
if ($PSCmdlet.ShouldProcess("Preforming operation 'Install-Vra' on Host $hostName with the following data \n $($vraBasic | ConvertTo-Json)")) {
|
||||
if ($PSCmdlet.ShouldProcess($hostName)) {
|
||||
Invoke-ZertoRestRequest -uri "vras" -method POST -body $($vraBasic | ConvertTo-Json)
|
||||
}
|
||||
} else {
|
||||
Write-Error "Host $hostName already has a VRA installed. Aborting Install Call"
|
||||
}
|
||||
}
|
||||
|
||||
End {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user