From 04dba27f0c1da42570571410ea94ed34b98b5a84 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 24 Feb 2019 14:09:18 -0500 Subject: [PATCH] Commenting and Helpmessages. --- ZertoApiWrapper/Public/Install-ZertoVra.ps1 | 26 ++++++++++++------- ZertoApiWrapper/Public/Uninstall-ZertoVra.ps1 | 5 +++- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/ZertoApiWrapper/Public/Install-ZertoVra.ps1 b/ZertoApiWrapper/Public/Install-ZertoVra.ps1 index 8090596..2ae3cbc 100644 --- a/ZertoApiWrapper/Public/Install-ZertoVra.ps1 +++ b/ZertoApiWrapper/Public/Install-ZertoVra.ps1 @@ -1,37 +1,41 @@ function Install-ZertoVra { [cmdletbinding( SupportsShouldProcess = $true )] param( - [Parameter( Mandatory = $true )] + [Parameter( Mandatory = $true, HelpMessage = "Host name where the VRA is to be installed." )] [string]$hostName, - [Parameter( Mandatory = $true )] + [Parameter( Mandatory = $true, HelpMessage = "Datastore name where the VRA is to be installed." )] [string]$datastoreName, - [Parameter( Mandatory = $true )] + [Parameter( Mandatory = $true, HelpMessage = "Network name the VRA is to be assigned." )] [string]$networkName, - [Parameter( HelpMessage = "Initial amount of memory to assign to the VRA in GB. 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()] + [Parameter( HelpMessage = "Bandwidth group to assign to the VRA. If unspecified will assign to the 'default_group'" )] [string]$groupName, - [Parameter( ParameterSetName = "Dhcp", Mandatory = $true )] + [Parameter( ParameterSetName = "Dhcp", Mandatory = $true, HelpMessage = "Assign a DHCP address to the VRA." )] [switch]$Dhcp, - [Parameter( ParameterSetName = "StaticIp", Mandatory = $true )] + [Parameter( ParameterSetName = "StaticIp", Mandatory = $true, HelpMessage = "Static IP address to assign to the VRA." )] [ValidateScript( {$_ -match [IPAddress]$_ })] [string]$vraIpAddress, - [Parameter( ParameterSetName = "StaticIp", Mandatory = $true )] + [Parameter( ParameterSetName = "StaticIp", Mandatory = $true, HelpMessage = "Default gateway to assign to the VRA" )] [ValidateScript( {$_ -match [IPAddress]$_ })] [string]$defaultGateway, - [Parameter( ParameterSetName = "StaticIp", Mandatory = $true )] + [Parameter( ParameterSetName = "StaticIp", Mandatory = $true, HelpMessage = "Subnetmask to be assigned to the VRA" )] [ValidateScript( {$_ -match [IPAddress]$_ })] [string]$subnetMask ) - #TODO - Test to see if VRA already exists! + # 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 if ( -not (Get-ZertoVra -vraName $vraName) ) { + # Get identifiers for each item provided by name. $siteIdentifier = $script:zvmLocalInfo.SiteIdentifier $hostIdentifier = Get-ZertoVirtualizationSite -siteIdentifier $siteIdentifier -hosts | Where-Object {$_.VirtualizationHostName -eq $hostName} | Select-Object hostIdentifier -ExpandProperty hostIdentifier $networkIdentifier = Get-ZertoVirtualizationSite -siteIdentifier $siteIdentifier -networks | Where-Object {$_.VirtualizationNetworkName -eq $networkName} | Select-Object NetworkIdentifier -ExpandProperty NetworkIdentifier $datastoreIdentifier = Get-ZertoVirtualizationSite -siteIdentifier $siteIdentifier -datastores | Where-Object {$_.DatastoreName -eq $datastoreName} | Select-Object DatastoreIdentifier -ExpandProperty DatastoreIdentifier + + # Build the JSON object through an Ordered Hashtable. $vraBasic = [ordered]@{} $vraBasic['DatastoreIdentifier'] = $datastoreIdentifier.toString() if ($PSBoundParameters.ContainsKey('groupName')) { @@ -51,6 +55,8 @@ function Install-ZertoVra { $vraBasicNetwork['VraIPConfigurationTypeApi'] = "Dhcp" } $vraBasic['VraNetworkDataApi'] = $vraBasicNetwork + + # 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)")) { Invoke-ZertoRestRequest -uri "vras" -method POST -body $($vraBasic | ConvertTo-Json) } diff --git a/ZertoApiWrapper/Public/Uninstall-ZertoVra.ps1 b/ZertoApiWrapper/Public/Uninstall-ZertoVra.ps1 index c2864a2..951bf6f 100644 --- a/ZertoApiWrapper/Public/Uninstall-ZertoVra.ps1 +++ b/ZertoApiWrapper/Public/Uninstall-ZertoVra.ps1 @@ -1,7 +1,10 @@ function Uninstall-ZertoVra { [cmdletbinding()] param( - [Parameter( Mandatory = $true )] + [Parameter( + Mandatory = $true, + HelpMessage = "Host Name attached to the VRA to be removed." + )] [string[]]$hostName )