VMware Cloud Foundation APIs: Create a Cloud Proxy Group

Creating a cloud proxy group, allows you to group multiple cloud proxies. This ensures that if a cloud proxy goes offline, VCF Operations will automatically reassign the adapters with a cloud proxy that remains online ensuring data can still be collected in the event of failures, thus providing a level of high availability. Once a cloud proxy group has been created and the cloud proxies have been assigned you must then also reconfigure each adapter to point to the newly created cloud proxy group rather than directly to a cloud proxy.

In this post we will look at how to create a cloud proxy group, assigning cloud proxies and the reconfiguration of adapters using the public APIs, this is achieved via VCF Operations.

To deploy an additional cloud proxies through automation see my previous post VMware Cloud Foundation APIs: Deploy an Additional Cloud Proxy .

VCF Operations APIs Used

VMware Cloud Foundation Operations API

  • POST /suite-api/api/auth/token/acquire
  • GET /api/collectorgroups
  • POST /api/collectorgroups
  • GET /suite-api/api/collectors
  • GET /suite-api/api/adapters
  • GET /suite-api/api/adapters/{adapterId}
  • PUT /suite-api/api/adapters

Procedure

  1. Connect to a system that has access to your infrastructure and is capable of running CURL.

  2. Replace the values in the sample code with values for your VCF Operations instance and run the commands in the console.

1export vcfOperationsFqdn='flt-ops01a.rainpole.io'
2export vcfOperationsUser='admin'
3export vcfOperationsPass='VMw@re1!VMw@re1!'
  1. Authenticate to VCF Operations and obtain a token by running the following command:
1vcfOperationsToken=$(curl -k -X POST https://${vcfOperationsFqdn}/suite-api/api/auth/token/acquire \
2    --header "Content-Type:application/json" \
3    --header "Accept: application/json" \
4    -d "{\"username\":\"$vcfOperationsUser\", \"password\":\"$vcfOperationsPass\"}" \
5    | jq -r '.token')
  1. Verify you were able to successfully obtain an authentication token by running the following command:
1echo $vcfOperationsToken

Example Output:

16513db65-1c46-4482-9a4c-d257cd422906::07f2b1ee-48ae-46ca-9874-7baf79984300
  1. Replace the values in the sample code with your values and run the commands in the console.
1export collectorGroupName='sfo-collector-group'
2export collectorGroupDescription='Collector Group for San Francisco'
3export firstCloudProxy='sfo-cp01.sfo.rainpole.io'
4export secondCloudProxy='sfo-cp02.sfo.rainpole.io'
  1. First lets check to see if a collector group with this name already exists by running the following command:
1curl -k -X GET "https://${vcfOperationsFqdn}/suite-api/api/collectorgroups" \
2  --header "Authorization: OpsToken ${vcfOperationsToken}" \
3  --header 'Content-Type:application/json' \
4  --header "Accept: application/json" \
5  | jq --arg targetName "${collectorGroupName}" 'any(.collectorGroups[]; .name == $targetName)'
  1. Now obtain the IDs of the cloudy proxies that you want to associate with the collector group by running the following command:
 1firstCloudProxyId=$(curl -k -X GET "https://${vcfOperationsFqdn}/suite-api/api/collectors" \
 2  --header "Authorization: OpsToken ${vcfOperationsToken}" \
 3  --header "Content-Type:application/json" \
 4  --header "Accept: application/json" \
 5  | jq -r --arg collectorName "${firstCloudProxy}" '.collector[] | select(.name == $collectorName) | .id')
 6
 7secondCloudProxyId=$(curl -k -X GET "https://${vcfOperationsFqdn}/suite-api/api/collectors" \
 8  --header "Authorization: OpsToken ${vcfOperationsToken}" \
 9  --header "Content-Type:application/json" \
10  --header "Accept: application/json" \
11  | jq -r --arg collectorName "${secondCloudProxy}" '.collector[] | select(.name == $collectorName) | .id')
  1. Verify you have the both collector IDs by running the following command:
1echo $firstCloudProxyId
2echo $secondCloudProxyId
  1. Create the JSON payload by running the following command:
 1cat << EOF > collector-group.json
 2{
 3  "name": "${collectorGroupName}",
 4  "description": "${collectorGroupDescription}",
 5  "collectorId": [
 6    ${firstCloudProxyId},
 7    ${secondCloudProxyId}
 8  ],
 9  "systemDefined": false,
10  "haEnabled": false,
11  "lbEnabled": false
12}
13EOF
  1. Verify the JSON payload has been populated correctly by running the following command:
1cat collector-group.json

Example Output:

 1{
 2  "name": "sfo-collector-group",
 3  "description": "Collector Group for San Francisco",
 4  "collectorId": [
 5    2,
 6    3
 7  ],
 8  "systemDefined": false,
 9  "haEnabled": false,
10  "lbEnabled": false
11}
  1. Create the Collector Group and assign the Cloud Proxies by running the following command:
1collectorGroupId=$(curl -k -X POST "https://${vcfOperationsFqdn}/suite-api/api/collectorgroups" \
2  --header "Authorization: OpsToken ${vcfOperationsToken}" \
3  --header "Content-Type:application/json" \
4  --header "Accept: application/json" \
5  -d @collector-group.json \
6  | jq -r '.id')
  1. Verify the collector group has been created by running the following command:
1curl -k -X GET "https://${vcfOperationsFqdn}/suite-api/api/collectorgroups" \
2  --header "Authorization: OpsToken ${vcfOperationsToken}" \
3  --header "Content-Type:application/json" \
4  --header "Accept: application/json" \
5  | jq --arg targetName "${collectorGroupName}" 'any(.collectorGroups[]; .name == $targetName)'
  1. Verify you have the collector group IDs by running the following command:
1echo $collectorGroupId
  1. Retrieve the adapter IDs for all vCenter, vSAN, NSX and VMware Cloud Foundation adapters by running the following command:
1adapterIds=$(curl -ks -X GET "https://${vcfOperationsFqdn}/suite-api/api/adapters" \
2  --header "Authorization: OpsToken ${vcfOperationsToken}" \
3  --header "Content-Type:application/json" \
4  --header "Accept: application/json" \
5  | jq -r '.adapterInstancesInfoDto[]? | select(.resourceKey.adapterKindKey == "VMWARE" or .resourceKey.adapterKindKey == "VcfAdapter" or .resourceKey.adapterKindKey == "NSXTAdapter" or .resourceKey.adapterKindKey == "VirtualAndPhysicalSANAdapter") | .id' | tr -d '\r')
  1. Reconfigure each adapter to use the collector group rather than a specific Cloud Proxy by running the following command:
 1printf '%s\n' "${adapterIds}" | while read -r adapterId; do
 2  # Skip empty lines if any exist
 3  [ -z "$adapterId" ] && continue
 4
 5  echo "👉 Fetching details for Adapter: $adapterId"
 6
 7  # Fetch the specific adapter config blueprint
 8  currentConfig=$(curl -ks -X GET "https://${vcfOperationsFqdn}/suite-api/api/adapters/$adapterId" \
 9    --header "Authorization: OpsToken ${vcfOperationsToken}" \
10    --header "Accept: application/json")
11
12  # Strip out conflicting singular collectorId and inject the new group ID via jq
13  updatePayload=$(echo "$currentConfig" | jq --arg GID "$collectorGroupId" '
14    .collectorGroupId = $GID | 
15    del(.collectorId, .lastCollected, .lastHeartbeat, .links, .numberOfMetricsCollected, .numberOfResourcesCollected, .messageFromAdapterInstance) 
16  ')
17
18  # Push the updated specification back to VCF Operations
19  responseCode=$(curl -ks -X PUT "https://${vcfOperationsFqdn}/suite-api/api/adapters" \
20    --header "Authorization: OpsToken ${vcfOperationsToken}" \
21    --header "Content-Type:application/json" \
22    --header "Accept: application/json" \
23    -d "$updatePayload")
24done

Posts in this Series