Skip to content

Commit

Permalink
Merge pull request #2 from AdrianBegg/v0.4
Browse files Browse the repository at this point in the history
V0.4
  • Loading branch information
AdrianBegg committed Jun 1, 2021
2 parents b39ce0b + 1381dc1 commit 1904fb2
Show file tree
Hide file tree
Showing 16 changed files with 298 additions and 49 deletions.
10 changes: 5 additions & 5 deletions Public/Administration/Get-VCDSTasks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ function Get-VCDSTasks(){
The UserId to filter the events.
.PARAMETER IncludeFiles
If true returns the details of any files assosicated with the Task (e.g. Support Bundles)
If true returns the details of any files associated with the Task (e.g. Support Bundles)
.EXAMPLE
Get-VCDSTasks
Returtns the VCDS tasks for default environment.
Returns the VCDS tasks for default environment.
.EXAMPLE
Get-VCDSTasks -EnvironmentId "urn:vcdc:environment:3fccbd2a-003c-4303-8f1a-8569853236ac"
Expand Down Expand Up @@ -59,7 +59,7 @@ function Get-VCDSTasks(){
[switch] $IncludeFiles
)
# TO DO : Implement filtering on the Task Properties
# TO DO : Pending security fix from VMware (currently can see all tasks), adjust the URI to use the Organisation Id instead of just environment Id
# TO DO : Pending security fix from VMware (currently can see all tasks), adjust the URI to use the Organization Id instead of just environment Id
if(!$global:VCDService.IsConnected){
throw "You are not currently connected to the VMware Cloud Services Portal (CSP) for VMware Cloud Director Service. Please use Connect-VCDService cmdlet to connect to the service and try again."
}
Expand Down Expand Up @@ -103,7 +103,7 @@ function Get-VCDSTasks(){
UseBasicParsing = $true
Body = $htFilters
}
# Now make an inital call to the API
# Now make an initial call to the API
$Response = ((Invoke-WebRequest @RequestParameters).Content | ConvertFrom-Json)
# Check if single result or multiple results
if($PSBoundParameters.ContainsKey("Id")){
Expand Down Expand Up @@ -139,7 +139,7 @@ function Get-VCDSTasks(){
}
UseBasicParsing = $true
}
# Now make an inital call to the API
# Now make an initial call to the API
$FilesResponse = ((Invoke-WebRequest @FileRequestParameters).Content | ConvertFrom-Json)
# Check if anything was returned
if($FilesResponse.Count -gt 0){
Expand Down
2 changes: 1 addition & 1 deletion Public/Administration/Watch-VCDSTaskCompleted.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function Watch-VCDSTaskCompleted(){
[double] $Percentage = 0
}
Write-Debug $objTaskStatus
# Check if the Percentage is greater then 100 (this can happen) and normalise it
# Check if the Percentage is greater then 100 (this can happen) and normalize it
if($Percentage -gt 100){
$Percentage = 100
}
Expand Down
2 changes: 1 addition & 1 deletion Public/Environment/Get-VCDSEnvironments.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function Get-VCDSEnvironments(){
.PARAMETER Id
The Environment unique identifier to filter results by
.PARAMETER Loaction
.PARAMETER Location
Optionally the Amazon Region to filter results by (e.g. us-west2)
.EXAMPLE
Expand Down
14 changes: 5 additions & 9 deletions Public/Environment/Get-VCDSUpgradeTracks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function Get-VCDSUpgradeTracks(){
Optionally the Station Name to filter.
.PARAMETER DefaultStation
If set returns the deafult station for the provided environment
If set returns the default station for the provided environment
.EXAMPLE
Get-VCDSUpgradeTracks
Expand All @@ -32,8 +32,8 @@ function Get-VCDSUpgradeTracks(){
.NOTES
AUTHOR: Adrian Begg
LASTEDIT: 2020-11-17
VERSION: 1.0
LASTEDIT: 2021-05-07
VERSION: 1.1
#>
[CmdletBinding(DefaultParameterSetName="Default")]
Param(
Expand Down Expand Up @@ -76,7 +76,7 @@ function Get-VCDSUpgradeTracks(){
UseBasicParsing = $true
}
try{
# First return the environments collection from CSP
# Make a call to return all the Upgrade Stations/Tracks
$colUpgradeTracks = ((Invoke-WebRequest @RequestParameters).Content | ConvertFrom-Json)
if($DefaultStation){
return $colUpgradeTracks.defaultStation
Expand All @@ -85,11 +85,7 @@ function Get-VCDSUpgradeTracks(){
return $colUpgradeTracks.tracks | Where-Object {$_.name -eq $TrackName}
}
elseif($PSBoundParameters.ContainsKey("StationName")){
foreach($Station in $colUpgradeTracks.tracks.stations){
if($Station -eq $StationName){
return $StationName
}
}
return $colUpgradeTracks.tracks.stations | Where-Object {$_.name -eq $StationName}
} else {
return $colUpgradeTracks.tracks
}
Expand Down
12 changes: 6 additions & 6 deletions Public/Environment/New-VCDSInstance.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ function New-VCDSInstance(){
Optionally The Cloud Director Service Environment Id (Default is used if none is provided)
.PARAMETER UpgradeCategory
The Cloud Director Upgrade "Station" for the deployed instance. Use the Get-VCDSUpgradeTracks cmdlet to view valid Stations.
The Cloud Director Upgrade "Station" for the deployed instance. Use the Get-VCDSUpgradeTracks cmdlet to view valid Stations. The Station name should be used (not the localizedName)
If none is provided the default will be used for the environment.
.PARAMETER AdministratorPassword
The password for the administrator user in the System Org
.EXAMPLE
New-VCDSInstance -Name "CDS-Instanace-01" -AdministratorPassword "Welcome@123"
Creates a new VCDS Instance named "CDS-Instance-01" in the default environment with the default upgrade catagory.
Creates a new VCDS Instance named "CDS-Instance-01" in the default environment with the default upgrade category.
.EXAMPLE
New-VCDSInstance -Name "CDS-Instanace-01" -UpgradeCategory "sp-main:alpha" -AdministratorPassword "Welcome@123"
Creates a new VCDS Instance in the default environment using Upgrade Catagory "sp-main:alpha"
Creates a new VCDS Instance in the default environment using Upgrade Category "sp-main:alpha"
.EXAMPLE
New-VCDSInstance -Name "CDS-Instanace-01" -EnvironmentId "urn:vcdc:environment:3fccbd2a-003c-4303-8f1a-8569853236ac" -UpgradeCategory "sp-release:production" -AdministratorPassword "Welcome@123"
Creates a new VCDS Instance in the environment with the Id "urn:vcdc:environment:3fccbd2a-003c-4303-8f1a-8569853236ac" using UpgradeCatagory "sp-release:production"
Creates a new VCDS Instance in the environment with the Id "urn:vcdc:environment:3fccbd2a-003c-4303-8f1a-8569853236ac" using UpgradeCategory "sp-release:production"
.NOTES
AUTHOR: Adrian Begg
Expand Down Expand Up @@ -64,10 +64,10 @@ function New-VCDSInstance(){
# Setup a Service URI for the environment
$ServiceURI = $Environment.url

# Check if the UpgradeCategory was provided, if yes check if its valid, if no then retireve the default for the environment
# Check if the UpgradeCategory was provided, if yes check if its valid, if no then retrieve the default for the environment
if($PSBoundParameters.ContainsKey("UpgradeCategory")){
# Check if the provided Station is valid for the provided environment
$UpgradeCategory = Get-VCDSUpgradeTracks -EnvironmentId $Environment.id -StationName $UpgradeCategory
$UpgradeCategory = (Get-VCDSUpgradeTracks -EnvironmentId $Environment.id -StationName $UpgradeCategory).name
if($UpgradeCategory.Count -eq 0){
throw "The provided Station Name $UpgradeCategory is not compatible with the provided environment VCDS Environment with the Id $EnvironmentId. Please check the Station Name is correct and try again."
}
Expand Down
99 changes: 99 additions & 0 deletions Public/Operations/Get-VCDSInstanceMaintenance.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
function Get-VCDSInstanceMaintenance(){
<#
.SYNOPSIS
Returns the Maintenance window for the provided Cloud Director Service instance.
.DESCRIPTION
Returns the weekly 2-hour maintenance window configured during which VMware checks if the VMware Cloud Director instance is eligible for upgrade and upgrade it if it is the case.
The maintenance window Start Time/Day is set in UTC.
.PARAMETER InstanceId
The Cloud Director Instance Id
.PARAMETER InstanceName
The Cloud Director Instance Name
.PARAMETER EnvironmentId
Optionally The Cloud Director Service Environment Id (Default is used if none is provided)
.EXAMPLE
Get-VCDSInstanceMaintenance -InstanceName "CloudDirector-TestInstance-01"
Returns the currently configured Maintenance Window for the instance named "CloudDirector-TestInstance-01"
.NOTES
AUTHOR: Adrian Begg
LASTEDIT: 2021-05-08
VERSION: 1.0
#>
[CmdletBinding(DefaultParameterSetName="ByInstanceId")]
Param(
[Parameter(Mandatory=$True, ParameterSetName="ByInstanceId")]
[ValidateNotNullorEmpty()] [string] $InstanceId,
[Parameter(Mandatory=$True, ParameterSetName="ByInstanceName")]
[ValidateNotNullorEmpty()] [string] $InstanceName,
[Parameter(Mandatory=$False, ParameterSetName="ByInstanceId")]
[Parameter(Mandatory=$False, ParameterSetName="ByInstanceName")]
[ValidateNotNullorEmpty()] [String] $EnvironmentId
)
if(!$global:VCDService.IsConnected){
throw "You are not currently connected to the VMware Console Services Portal (CSP) for VMware Cloud Director Service. Please use Connect-VCDService cmdlet to connect to the service and try again."
}
# Next check if the EnvironmentId has been provided and is valid
if($PSBoundParameters.ContainsKey("EnvironmentId")){
$Environment = $global:VCDService.VCDSEnvironments | Where-Object {$_.id -eq $EnvironmentId}
if($Environment.count -eq 0){
throw "An VCDS Environment with the Id $EnvironmentId can not be found. Please check the Id and try again."
}
} else {
$Environment = $global:VCDService.DefaultEnvironment
}
# Setup a Service URI for the environment
$ServiceURI = $Environment.url

if($PSCmdlet.ParameterSetName -eq "ByInstanceName") {
# Check if an instance already exists with the provided Name
$Instance = Get-VCDSInstances -EnvironmentId $Environment.id -Name $InstanceName
if($Instance.count -eq 0){
throw "An instance with the Name $InstanceName can not be found in the environment with the Id $($Environment.id) please check the Name and try again."
}
}
if($PSCmdlet.ParameterSetName -eq "ByInstanceId") {
# Check if an instance already exists with the provided Id
$Instance = Get-VCDSInstances -EnvironmentId $Environment.id -Id $InstanceId
if($Instance.count -eq 0){
throw "An instance with the Id $InstanceId can not be found in the environment with the Id $($Environment.id) please check the Name and try again."
}
}

# Setup a HashTable for the API call to the Cloud Gateway
$InstanceOperationAPIEndpoint = "$ServiceURI/environment/$($Environment.id)/instances/$($Instance.id)/operations/CONFIGURE_MAINTENANCE"

# A Hashtable of Request Parameters to the API
[Hashtable] $RequestParameters = @{
URI = $InstanceOperationAPIEndpoint
Method = "Get"
ContentType = "application/json"
Headers = @{
"Authorization" = "Bearer $($global:VCDService.AccessToken)"
"Accept" = "application/json"
}
UseBasicParsing = $true
}
try{
$MaintenanceResult = ((Invoke-WebRequest @RequestParameters).Content | ConvertFrom-Json)
} catch {
throw "An exception has occurred attempting to make the API call. $_"
}
# Parse the result and create an object with the current maintenance schedule
$MaintenanceDay = ($MaintenanceResult.arguments | Where-Object {$_.id -eq "maintenanceDay"}).defaultValue
$MaintenanceHour = ($MaintenanceResult.arguments | Where-Object {$_.id -eq "maintenanceHour"}).defaultValue

# Define the Object to Post as Data to the API
[PSObject] $MaintenanceWindow = New-Object -TypeName PSObject -Property @{
MaintenanceDay = (($MaintenanceResult.arguments | Where-Object {$_.id -eq "maintenanceDay"}).options).$MaintenanceDay
MaintenanceHoursUTC = (($MaintenanceResult.arguments | Where-Object {$_.id -eq "maintenanceHour"}).options).$MaintenanceHour
MaintenanceHourStartUTC = $MaintenanceHour
}
return $MaintenanceWindow
}
4 changes: 2 additions & 2 deletions Public/Operations/New-VCDSSupportBundle.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function New-VCDSSupportBundle(){
.EXAMPLE
New-VCDSSupportBundle -InstanceId "urn:vcdc:vcdInstance:182297f8-36d0-4901-9f1d-42a2524fa091" -Download
Generates a new Cloud Director support bundle for the provided instance and downloads the buddle files to the current working directory.
Generates a new Cloud Director support bundle for the provided instance and downloads the bundle files to the current working directory.
.NOTES
AUTHOR: Adrian Begg
Expand Down Expand Up @@ -75,7 +75,7 @@ function New-VCDSSupportBundle(){
# Setup a HashTable for the API call to the Cloud Gateway
$InstanceOperationAPIEndpoint = "$ServiceURI/environment/$($Environment.id)/instances/$($Instance.id)/operations/invokeOperation"
[Hashtable] $htPayload = @{
operationType = "createSupportBundle"
operationType = "CREATE_SUPPORT_BUNDLE"
arguments = @{}
}

Expand Down
2 changes: 1 addition & 1 deletion Public/Operations/Register-VCDSSDDC.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function Register-VCDSSDDC(){
# Setup a HashTable for the API call to the Cloud Gateway
$InstanceOperationAPIEndpoint = "$ServiceURI/environment/$($Environment.id)/instances/$($Instance.id)/operations/invokeOperation"
[Hashtable] $htPayload = @{
operationType = "associateVmc"
operationType = "REGISTER_VMC"
arguments = @{
apiToken = $VMCAPIToken
vmcCspOrgId = $VMCOrganisationUUID
Expand Down
13 changes: 5 additions & 8 deletions Public/Operations/Set-VCDSDomain.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,27 @@ function Set-VCDSDomain(){
}
}

# Setup a HashTable for the API call to the Cloud Gateway
# Setup a HashTable for the API call to the Cloud Gateway and the default operation type (Set Custom Domain)
$InstanceOperationAPIEndpoint = "$ServiceURI/environment/$($Environment.id)/instances/$($Instance.id)/operations/invokeOperation"
[Hashtable] $htPayload = @{
operationType = "associateCustomDomain"
operationType = "PLAIN_CUSTOM_DOMAIN"
arguments = @{}
}

# Set the arguments to reset the DNS and certificate settings to default
if($PSBoundParameters.ContainsKey("Reset")){
[Hashtable] $htArguments = @{
revertToDefaultDomain = $true
}
$htPayload.operationType = "REVERT_CUSTOM_DOMAIN"
} else {
# Set the arguments
[Hashtable] $htArguments = @{
customDomainName = $InstanceFQDN
consoleProxyCustomDomainName = $ConsoleProxyFQDN
privateKey = $CertificateKeyPEM
certificates = $CertificatePEM
revertToDefaultDomain = $null
}
# Set the arguments to the Payload
$htPayload.arguments = $htArguments
}
# Set the arguments to the Payload
$htPayload.arguments = $htArguments

# A Hashtable of Request Parameters
[Hashtable] $RequestParameters = @{
Expand Down
4 changes: 2 additions & 2 deletions Public/Operations/Set-VCDSIdPSettings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function Set-VCDSIdPSettings(){
.DESCRIPTION
Configure CSP (VMware Cloud Services) as Identity Provider for instance's System Org. Once this has been set users with the VMware Cloud Director Administrator Service role will be able to login to the Cloud Director instance using there myVMware identity.
PLEASE NOTE: The API Token used in the Connect-VCDService must have "Organization Owner" role in hosting CSP Organisation in additon to the "Cloud Director Administrator" service role.
PLEASE NOTE: The API Token used in the Connect-VCDService must have "Organization Owner" role in hosting CSP Organization in addition to the "Cloud Director Administrator" service role.
.PARAMETER InstanceId
The Cloud Director Instance Id
Expand Down Expand Up @@ -69,7 +69,7 @@ function Set-VCDSIdPSettings(){
# Setup a HashTable for the API call to the Cloud Gateway
$InstanceOperationAPIEndpoint = "$ServiceURI/environment/$($Environment.id)/instances/$($Instance.id)/operations/invokeOperation"
[Hashtable] $htPayload = @{
operationType = "setupCspAsIdp"
operationType = "SETUP_CSP_AS_IDP_FOR_SYSTEM_ORG"
arguments = @{}
}

Expand Down
Loading

0 comments on commit 1904fb2

Please sign in to comment.