DRY Refactor

This commit is contained in:
Wes Carroll
2020-04-09 10:37:36 -04:00
parent 96b3e65be2
commit e3cba682c7
@@ -133,33 +133,27 @@ function Get-ZertoVirtualizationSite {
HelpMessage = "The identifier of the Zerto Virtual Manager site." HelpMessage = "The identifier of the Zerto Virtual Manager site."
)] )]
[switch]$repositories [switch]$repositories
) )
begin { begin {
$baseUri = "virtualizationsites"
$returnObject = @()
} }
process { process {
# Return information based on ParameterSetName invoked. # Return information based on ParameterSetName invoked.
$baseUri = "virtualizationsites"
switch ( $PSCmdlet.ParameterSetName ) { switch ( $PSCmdlet.ParameterSetName ) {
# If no ParameterSetName is specified, return all data # If no ParameterSetName is specified, return all data
"main" { "main" {
$returnObject = Invoke-ZertoRestRequest -uri $baseUri $uri = $baseUri
} }
# If devices is specified along with a hostId, build return just that host information, otherwise return all devices at the site # If devices is specified along with a hostId, build return just that host information, otherwise return all devices at the site
#TODO - remove foreach, only one siteIdentifier can be specified.
"devices" { "devices" {
$returnObject = foreach ( $id in $siteIdentifier ) { if ( $PSBoundParameters.ContainsKey( "hostIdentifier" ) ) {
if ( $PSBoundParameters.ContainsKey( "hostIdentifier" ) ) { $uri = "{0}/{1}/devices?hostIdentifier={2}" -f $baseUri, $siteIdentifier, $hostIdentifier
$uri = "{0}/{1}/devices?hostIdentifier={2}" -f $baseUri, $siteIdentifier, $hostIdentifier } else {
} else { $uri = "{0}/{1}/devices" -f $baseUri, $siteIdentifier
$uri = "{0}/{1}/devices" -f $baseUri, $siteIdentifier
}
Invoke-ZertoRestRequest -uri $uri
} }
} }
@@ -170,24 +164,22 @@ function Get-ZertoVirtualizationSite {
} else { } else {
$uri = "{0}/{1}/hosts" -f $baseUri, $siteIdentifier $uri = "{0}/{1}/hosts" -f $baseUri, $siteIdentifier
} }
$returnObject = Invoke-ZertoRestRequest -uri $uri
} }
# If siteIdentifier is specified, return information for that site. # If siteIdentifier is specified, return information for that site.
"siteIdentifier" { "siteIdentifier" {
$uri = "{0}/{1}" -f $baseUri, $siteIdentifier $uri = "{0}/{1}" -f $baseUri, $siteIdentifier
$returnObject = Invoke-ZertoRestRequest -uri $uri
} }
# If a different ParameterSetName is selected, use that information to build the URI and return that information # If a different ParameterSetName is selected, use that information to build the URI and return that information
default { default {
$uri = "{0}/{1}/{2}" -f $baseUri, $siteIdentifier, $PSCmdlet.ParameterSetName.ToLower() $uri = "{0}/{1}/{2}" -f $baseUri, $siteIdentifier, $PSCmdlet.ParameterSetName.ToLower()
$returnObject = Invoke-ZertoRestRequest -uri $uri
} }
} }
Invoke-ZertoRestRequest -uri $uri
} }
end { end {
return $returnObject
} }
} }