Skip to content

Commit

Permalink
chore: code formatting for tanzu functions (#422)
Browse files Browse the repository at this point in the history
- Applied code formatting standards to Tanzu functions.

Signed-off-by: Gary Blake <gblake@vmware.com>
  • Loading branch information
GaryJBlake authored Nov 30, 2023
1 parent b802ec4 commit f40a94f
Showing 1 changed file with 41 additions and 83 deletions.
124 changes: 41 additions & 83 deletions PowerValidatedSolutions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -24708,7 +24708,7 @@ Function Enable-WMRegistry {

if ($vCenterApi -ge 800) {
Write-Warning "The embedded Harbor registry is not supported on vSphere 8.0 and higher: SKIPPED"
break
Break
}

Try {
Expand All @@ -24725,20 +24725,17 @@ Function Enable-WMRegistry {
if (!$getHarborInstalled) {
Try {
$wmClusterId = (Invoke-RestMethod -Method GET -URI https://$vcApiServer/api/vcenter/namespace-management/clusters -Headers $vcApiHeaders | Where-Object { $_.cluster_name -eq $Cluster }).cluster
}
Catch {
} Catch {
Write-Error $_.Exception.Message
}

if (!$StoragePolicy) {
Try {
$storagePolicyId = (Invoke-RestMethod -Method GET -URI https://$vcApiServer/api/vcenter/namespace-management/clusters/$wmClusterId -Headers $vcApiHeaders).image_storage.storage_policy
}
Catch {
} Catch {
Write-Error $_.Exception.Message
}
}
elseif ($StoragePolicy) {
} elseif ($StoragePolicy) {
Try {
if ($vCenterApi -ge 702) {
$storagePolicyId = ((Invoke-WebRequest -Method GET -URI https://$vcApiServer/api/vcenter/storage/policies -Headers $vcApiHeaders -UseBasicParsing | ConvertFrom-Json) | Where-Object { $_.name -eq $StoragePolicy }).policy
Expand All @@ -24753,8 +24750,7 @@ Function Enable-WMRegistry {
]
}
"@
}
elseif ($vCenterApi -le 701) {
} elseif ($vCenterApi -le 701) {
$storagePolicyId = ((Invoke-WebRequest -Method GET -URI https://$vcApiServer/rest/vcenter/storage/policies -Headers $vcApiHeaders -UseBasicParsing | ConvertFrom-Json).value | Where-Object { $_.name -eq $StoragePolicy }).policy
$json = @"
{
Expand All @@ -24771,8 +24767,7 @@ Function Enable-WMRegistry {
}
"@
}
}
Catch {
} Catch {
Write-Error $_.Exception.Message
}
}
Expand All @@ -24781,21 +24776,18 @@ Function Enable-WMRegistry {
if ($vCenterApi -le 701) {
Try {
$installHarbor = Invoke-RestMethod -Method POST -URI https://$vcApiServer/rest/vcenter/content/registries/harbor -Headers $vcApiHeaders -Body $json -ContentType application/json
}
Catch {
} Catch {
Write-Error $_.Exception.Message
}

if ($installHarbor) {
$installHarborValue = $installHarbor.value
Write-Output "Embedded registry $installHarborValue deployment successfully started on Supervisor Cluster $cluster"
}
}
elseif ($vCenterApi -ge 702) {
} elseif ($vCenterApi -ge 702) {
Try {
$installHarbor = Invoke-RestMethod -Method POST -URI https://$vcApiServer/api/vcenter/content/registries/harbor -Headers $vcApiHeaders -Body $json -ContentType application/json
}
Catch {
} Catch {
Write-Error $_.Exception.Message
}

Expand Down Expand Up @@ -24838,14 +24830,13 @@ Function Get-WMRegistry {

if ($vCenterApi -ge 800) {
Write-Warning "The embedded Harbor registry is not supported on vSphere 8.0 and higher: SKIPPED"
break
Break
}

if ($Cluster) {
Try {
$wmClusterId = (Invoke-RestMethod -Method GET -URI https://$vcApiServer/api/vcenter/namespace-management/clusters -Headers $vcApiHeaders | Where-Object { $_.cluster_name -eq $Cluster }).cluster
}
Catch {
} Catch {
Write-Error $_.Exception.Message
}
}
Expand All @@ -24855,18 +24846,15 @@ Function Get-WMRegistry {
if ($vCenterApi -le 701) {
$response = Invoke-RestMethod -Method GET -URI https://$vcApiServer/rest/vcenter/content/registries/harbor -ContentType application/json -headers $vcApiHeaders
$response.value
}
elseif ($vCenterApi -ge 702) {
} elseif ($vCenterApi -ge 702) {
$response = Invoke-RestMethod -Method GET -URI https://$vcApiServer/api/vcenter/content/registries/harbor -ContentType application/json -headers $vcApiHeaders
$response
}
}
elseif ($PsBoundParameters.ContainsKey("Cluster")) {
} elseif ($PsBoundParameters.ContainsKey("Cluster")) {
if ($vCenterApi -le 701) {
$response = Invoke-RestMethod -Method GET -URI https://$vcApiServer/rest/vcenter/content/registries/harbor -ContentType application/json -headers $vcApiHeaders
$response.value | Where-Object { $_.cluster -eq $wmClusterId }
}
elseif ($vCenterApi -ge 702) {
} elseif ($vCenterApi -ge 702) {
$response = Invoke-RestMethod -Method GET -URI https://$vcApiServer/api/vcenter/content/registries/harbor -ContentType application/json -headers $vcApiHeaders
$response | Where-Object { $_.cluster -eq $wmClusterId }
}
Expand Down Expand Up @@ -24902,20 +24890,18 @@ Function Remove-WMRegistry {
Try {
if ($vCenterApi -ge 800) {
Write-Warning "The embedded Harbor registry is not supported on vSphere 8.0 and higher: SKIPPED"
break
Break
}

if ($inputObject) {
$harborRegistryId = $inputObject.registry
}
else {
} else {
$harborRegistryId = (Get-WMRegistry -cluster $cluster).registry
}

if ($vCenterApi -le 701) {
$uri = "https://$vcApiServer/rest/vcenter/content/registries/harbor/$harborRegistryId"
}
elseif ($vCenterApi -ge 702) {
} elseif ($vCenterApi -ge 702) {
$uri = "https://$vcApiServer/api/vcenter/content/registries/harbor/$harborRegistryId"
}
$response = Invoke-WebRequest -Method DELETE -URI $uri -ContentType application/json -headers $vcApiHeaders -UseBasicParsing
Expand Down Expand Up @@ -24953,9 +24939,9 @@ Function Get-WMRegistryHealth {
Try {
if ($vCenterApi -ge 800) {
Write-Warning "The embedded Harbor registry is not supported on vSphere 8.0 and higher: SKIPPED"
break
Break
}

if ($inputObject) {
$registry = $inputObject.registry
}
Expand Down Expand Up @@ -25075,28 +25061,21 @@ Function Get-TanzuKubernetesCluster {
if ($PsBoundParameters.ContainsKey("detail")) {
if (!$tkc -and !$namespace) {
Invoke-Expression "kubectl describe tkc --all-namespaces"
}
elseif (!$tkc -and $namespace) {
} elseif (!$tkc -and $namespace) {
Invoke-Expression "kubectl describe tkc -n $namespace"
}
elseif ($tkc -and !$namespace) {
} elseif ($tkc -and !$namespace) {
Write-Error "A resource cannot be retrieved by tkc name across all namespaces"
}
elseif ($tkc -and $namespace) {
} elseif ($tkc -and $namespace) {
Invoke-Expression "kubectl describe tkc $tkc -n $namespace"
}
}
else {
} else {
if (!$tkc -and !$namespace) {
Invoke-Expression "kubectl get tkc --all-namespaces"
}
elseif (!$tkc -and $namespace) {
} elseif (!$tkc -and $namespace) {
Invoke-Expression "kubectl get tkc -n $namespace"
}
elseif ($tkc -and !$namespace) {
} elseif ($tkc -and !$namespace) {
Write-Error "A resource cannot be retrieved by name across all namespaces"
}
elseif ($tkc -and $namespace) {
} elseif ($tkc -and $namespace) {
Invoke-Expression "kubectl get tkc $tkc -n $namespace"
}
}
Expand Down Expand Up @@ -25163,19 +25142,16 @@ Function Get-VMClass {
$uri = "https://$vcApiServer/api/vcenter/namespace-management/virtual-machine-classes/$vmClass"
$response = Invoke-RestMethod -Method 'GET' -URI $uri -Headers $vcApiHeaders
$response
}
elseif ($PsBoundParameters.ContainsKey("namespace")) {
} elseif ($PsBoundParameters.ContainsKey("namespace")) {
$uri = "https://$vcApiServer/api/vcenter/namespaces/instances/$namespace"
$response = Invoke-RestMethod -Method 'GET' -URI $uri -Headers $vcApiHeaders
$response.vm_service_spec.vm_classes
}
else {
} else {
$uri = " https://$vcApiServer/api/vcenter/namespace-management/virtual-machine-classes"
$response = Invoke-RestMethod -Method 'GET' -URI $uri -Headers $vcApiHeaders
$response
}
}
Catch {
} Catch {
Write-Error $_.Exception.Message
}
}
Expand Down Expand Up @@ -25212,16 +25188,14 @@ Function Add-VMClass {
$jsonFormat = ConvertTo-Json $newVmClass

$body = '{"vm_service_spec": { "vm_classes": '+ $jsonFormat +'}}'
}
else {
} else {
$body = '{ "vm_service_spec": { "vm_classes": [ "' + $vmClass + '" ] }}'
}

$uri = "https://$vcApiServer/api/vcenter/namespaces/instances/$namespace"
$response = Invoke-RestMethod -Method 'PATCH' -Uri $uri -Headers $vcApiHeaders -body $body
$response
}
Catch {
} Catch {
Write-Error $_.Exception.Message
}
}
Expand All @@ -25240,18 +25214,12 @@ Function Get-WMLicenseStatus {
This example gets the vSphere with Tanzu licenses status from vCenter Server for Workload Management
#>

# Param (
# [Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$server,
# [Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$domain
# )

Try {
$uri = "https://$vcApiServer/api/vcenter/namespace-management/capability"
$response = Invoke-RestMethod -Method GET -Uri $uri -Headers $vcApiHeaders
$response

}
Catch {
} Catch {
Debug-ExceptionWriter -object $_
}
}
Expand Down Expand Up @@ -25302,8 +25270,7 @@ Function Request-WMClusterCSR {
$response = Invoke-RestMethod -Method POST -Uri $uri -Headers $vcApiHeaders -body $body
$response | Out-File -FilePath $filePath
Write-Output "Certificate Signing Request (.csr) file for ($commonName) has been successfully saved to file ($filePath)"
}
Catch {
} Catch {
Write-Error $_.Exception.Message
}
}
Expand Down Expand Up @@ -25331,19 +25298,16 @@ Function Install-WMClusterCertificate {
if ($PsBoundParameters.ContainsKey("filepath")) {
if (!(Test-Path $filepath)) {
Throw "Certificate File Not Found"
}
else {
} else {
$certificate = Get-Content -Path $filePath -Raw -ErrorAction SilentlyContinue
$inputFileName = Split-Path -Path $filePath -Leaf -ErrorAction SilentlyContinue
}
}
if ($isMacOS -eq $true -or $isLinux -eq $true) {
$certificateFormatted = $Certificate -Replace "`n","\n"
}
elseif ($isWindows -eq $true -or $PSEdition -eq "Desktop") {
} elseif ($isWindows -eq $true -or $PSEdition -eq "Desktop") {
$certificateFormatted = $Certificate -Replace "`r`n","\n"
}
else {
} else {
Write-Error "Unsupported Operating System"
Break
}
Expand All @@ -25357,20 +25321,17 @@ Function Install-WMClusterCertificate {
$uri = "https://$vcApiServer/api/vcenter/namespace-management/clusters/$clusterId/"
if ($PSEdition -eq 'Core') {
$response = Invoke-WebRequest -Method PATCH -Uri $uri -Headers $vcApiHeaders -body $body -SkipCertificateCheck -UseBasicParsing # PS Core has -SkipCertificateCheck implemented
}
else {
} else {
$response = Invoke-WebRequest -Method PATCH -Uri $uri -Headers $vcApiHeaders -body $body -UseBasicParsing
}
if ($response.StatusCode -lt 300) {
if ($inputFileName) {
Write-Output "Signed Certificate ($inputFileName) has been successfully applied to Supervisor Cluster ($cluster)"
}
else {
} else {
Write-Output "Signed Certificate has been successfully applied to Supervisor Cluster ($cluster)"
}
}
}
Catch {
} Catch {
Debug-ExceptionWriter -object $_
}
}
Expand All @@ -25395,7 +25356,6 @@ Function Watch-WmClusterConfigStatus {
[Parameter (Mandatory = $false)] [int]$sleepTime = 30
)


Try {
$try = 1
Do {
Expand All @@ -25410,12 +25370,10 @@ Function Watch-WmClusterConfigStatus {
if ($wmCluster.ConfigStatus -ne "Running") {
Write-Error "Workload management on cluster: $wmClusterName status: $($wmCluster.ConfigStatus)"
write-Error "Workload management on cluster: $wmClusterName status messages: $($wmCluster.StatusMessages.Messages)"
}
else {
} else {
Write-Output "Workload Management on cluster: $wmClusterName completed with status: $($wmCluster.ConfigStatus)"
}
}
Catch {
} Catch {
Write-Error $_.Exception.Message
}
}
Expand Down

0 comments on commit f40a94f

Please sign in to comment.