VMware Horizon Cloud Service Next-Gen – The Automation Series – Chapter 7 – Edge
This blog post is part of the VMware Horizon Cloud Service Next-Gen – The Automation Series, a series of blog posts that describes the possibilities and use of the VMware Horizon Cloud Service Next-Gen APIs.
In this chapter we will add, get and delete an edge configuration. We will use PowerShell to execute the requests. Since Azure is the only provider type supported at the time of writing this chapter, that’s the one we currently focusing on.
The original VMware documentation for edge operations can be found here.
Create
We will start by creating an edge configuration. For this we will use the following information:
HTTP Method | POST | |
URI | https://cloud.vmwarehorizon.com/admin/v2/edge-deployments | |
Content-Type | application/json | Header |
Authorization | Bearer <Access token> | Header |
orgId | Organization ID | Body |
name | Any name for the edge configuration | Body |
description
|
Any description for the edge configuration | Body |
fqdn | FQDN with which to resolve the Edge VM management IP | Body |
enablePrivateEndpoint
|
Use Private Link Service and enable private endpoint | Body |
providerInstanceId
|
The Provider Instance where the Edge Deployment is deployed |
Body |
infrastructure
|
Infrastructure resources needed by the Edge Deployment. Specifically, the management network. | Body |
ssoConfigurations
|
SSO configurations for the edge deployment to use | Body |
With this information we will now construct the lines of code in PowerShell to add the edge configuration.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
$Header = @{ "Content-Type" = "application/json"; "Authorization" = "Bearer " + $AccessToken } $Body = @{ "description" = "Edge Description"; "enablePrivateEndpoint" = "true"; "fqdn" = "edge.domain.com"; "name" = "Edge"; "orgId" = "x1xxx1111-x111-1111-xx11-111111x11xx1"; "providerInstanceId" = "11111111111111"; "infrastructure" = @{ "managementNetwork" = @{ "kind" = "subnets"; "id" = "/subscriptions/1x11x11x-11x1-111x-1x11-11111111x11x/resourceGroups/rg-network-horizoncloud/providers/Microsoft.Network/virtualNetworks/vnet-westeurope-horizoncloud/subnets/snet-mgmt"; "data" = @{ "parent" = "/subscriptions/1x11x11x-11x1-111x-1x11-11111111x11x/resourceGroups/rg-network-horizoncloud/providers/Microsoft.Network/virtualNetworks/vnet-westeurope-horizoncloud"; "name" = "snet-mgmt"; "availableIpAddresses" = 251; "cidr" = "10.21.0.0/24" } } } "ssoConfigurations" = @(@{ "ssoConfigurationId" = "111x1x111xx1111x1xxx11xx"; }) } Invoke-RestMethod -Uri https://cloud.vmwarehorizon.com/admin/v2/edge-deployments -Method Post -Headers $Header -Body ($Body | ConvertTo-Json) |
(1) We create the access token from the API token using the New-HCSAccessToken function we described in chapter 2. We put this value in the $AccessToken variable, which we will use in the following step.
(2) We then construct the $Header array, where we specify the expected Content-Type to be received by the URI, which is application/json. And we specify the type of authorization using the Bearer type with the access token from the variable $AccessToken.
(3) After this we construct the $Body array with all the items that define the edge configuration to be added to the Horizon Cloud Services.
Now that we have both the Header and Body information in place, it’s time to execute the command to add the edge configuration (1). Once executed, the output with what has been configured will be displayed (2).
When we look in the Horizon Universal Console, we see that the edge configuration is being added.
Get
To retrieve the edge configuration(s), we will use the following information:
HTTP Method | GET | |
URI | https://cloud.vmwarehorizon.com/admin/v2/edge-deployments | |
Content-Type | application/json | Header |
Authorization | Bearer <Access token> | Header |
With this information we will now construct the lines of code in PowerShell to retrieve the edge configuration(s).
1 2 3 4 5 6 |
$Header = @{ "Content-Type" = "application/json"; "Authorization" = "Bearer " + $AccessToken } Invoke-RestMethod -Uri https://cloud.vmwarehorizon.com/admin/v2/edge-deployments -Method Get -Headers $Header |
(1) We create the access token from the API token again using the New-HCSAccessToken function, and put this value in the $AccessToken variable, which we will use in the following step.
(2) We construct the $Header array, where we specify the expected Content-Type to be received by the URI, which is application/json. And we specify the type of authorization using the Bearer type with the access token from the variable $AccessToken.
(3) We execute the command to retrieve the edge configuration(s).
(4) Once executed, the output with what has been configured will be displayed.
Delete
To delete an edge configuration, we will use the following information:
HTTP Method | DELETE | |
URI | https://cloud.vmwarehorizon.com/admin/v2/edge-deployments/<edge record ID> | |
Content-Type | application/json | Header |
Authorization | Bearer <Access token> | Header |
id | Id of the Edge deployment | URI |
(1) We create the access token from the API token again using the New-HCSAccessToken function, and put this value in the $AccessToken variable, which we will use in the following step.
(2) We construct the $Header array, where we specify the expected Content-Type to be received by the URI, which is application/json. And we specify the type of authorization using the Bearer type with the access token from the variable $AccessToken.
(3) We execute the command to delete the edge configuration.
(4) Once executed, the output with what has been deleted will be displayed.
PowerShell Functions Examples
The scripts below serve as examples. You may change the scripts to your own needs or standards, like error handling, securing password strings and things like that. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
Function New-HCSEdgeDeployment { [CmdletBinding()] param ( [Parameter(Mandatory=$True)] [string]$AccessToken, [Parameter(Mandatory=$False)] [string]$URI, [Parameter(Mandatory=$True)] [string]$OrganizationId, [Parameter(Mandatory=$True)] [string]$Name, [Parameter(Mandatory=$False)] [string]$Description, [Parameter(Mandatory=$True)] [string]$FQDN, [Parameter(Mandatory=$True)] [string]$EnablePrivateEndpoint, [Parameter(Mandatory=$True)] [string]$ManagementSubnetId, [Parameter(Mandatory=$True)] [string]$ManagementSubnetParent, [Parameter(Mandatory=$True)] [string]$ManagementSubnetName, [Parameter(Mandatory=$True)] [string]$ManagementSubnetAvailableIPAddresses, [Parameter(Mandatory=$True)] [string]$ManagementSubnetCIDR, [Parameter(Mandatory=$True)] [string]$ProviderInstanceId, [Parameter(Mandatory=$True)] [string]$SSOConfigId ) If (!($URI)) { $URI = "https://cloud.vmwarehorizon.com/admin/v2/edge-deployments" } $Header = @{ "Content-Type" = "application/json"; "Authorization" = "Bearer " + $AccessToken } $Body = @{ "description" = "$Description"; "enablePrivateEndpoint" = $EnablePrivateEndpoint; "fqdn" = "$FQDN"; "name" = "$Name"; "orgId" = "$OrganizationId"; "providerInstanceId" = "$ProviderInstanceId"; "infrastructure" = @{ "managementNetwork" = @{ "kind" = "subnets"; "id" = $ManagementSubnetId; "data" = @{ "parent" = $ManagementSubnetParent; "name" = $ManagementSubnetName; "availableIpAddresses" = $ManagementSubnetAvailableIPAddresses; "cidr" = $ManagementSubnetCIDR } } } "ssoConfigurations" = @(@{ "ssoConfigurationId" = "$SSOConfigId"; }) } Invoke-RestMethod -Uri "$URI" -Method Post -Headers $Header -Body ($Body | ConvertTo-Json -Depth 4) -UseBasicParsing } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
Function Get-HCSEdgeDeployment { [CmdletBinding()] param ( [Parameter(Mandatory=$True)] [string]$AccessToken, [Parameter(Mandatory=$False)] [string]$URI, [Parameter(Mandatory=$False)] [string]$Name ) If (!($URI)) { $URI = "https://cloud.vmwarehorizon.com/admin/v2/edge-deployments" } $Header = @{ "Content-Type" = "application/json"; "Authorization" = "Bearer " + $AccessToken } If (!($Name)) { Write-Output (Invoke-RestMethod -Uri "$URI" -Method Get -Headers $Header -UseBasicParsing).content } Else { ForEach ($_ in (Invoke-RestMethod -Uri "$URI" -Method Get -Headers $Header -UseBasicParsing).content) { If ($_.name -eq "$Name") { Write-Output $_ $NameFound = $True } } If ($NameFound -ne $True) { Write-Warning "Name not found." } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
Function Remove-HCSEdgeDeployment { [CmdletBinding()] param ( [Parameter(Mandatory=$True)] [string]$AccessToken, [Parameter(Mandatory=$False)] [string]$URI, [Parameter(Mandatory=$True)] [string]$Id, [Parameter(Mandatory=$False)] [bool]$Force ) If (!($URI)) { If ($Force -eq $True) { $URI = "https://cloud.vmwarehorizon.com/admin/v2/edge-deployments/" + "$Id" + "?force=true" } Else { $URI = "https://cloud.vmwarehorizon.com/admin/v2/edge-deployments/" + "$Id" } } $Header = @{ "Content-Type" = "application/json"; "Authorization" = "Bearer " + $AccessToken } Invoke-RestMethod -Uri "$URI" -Method Delete -Headers $Header -UseBasicParsing } |
I hope this chapter was informative and that you enjoyed reading.
Next up is site/edge mapping.