VMware Cloud Disaster Recovery (VCDR) provides a REST API for monitoring and retrieving information about the service’s major components. This includes the cloud file systems, protected sites, protected VMs, protection groups, protection group snapshots, and recovery SDDCs.
This blog post shows how to create a Postman collection that uses VMware Cloud DR REST API to retrieve VMs protected by the service – an idea initially developed by Pavlin Shterev. While the API is well documented, the requests authentication might be a little tricky.
There is also a great article that shows how to use the REST API with PowerCLI. It is written by Michael McLaughlin and Max Daneri and introduces a set of PowerShell cmdlets to monitor VMware Cloud Disaster Recovery (VCDR).
How to define a Postman collection for retrieving protected VMs
First you must create a Postman environment and setup the following variables (you can find more information about Postman variables here):
- api_token – CSP API token required for authentication. Getting API Token to authenticate is described in the article mentioned above (see Getting a token section).
- cloud_console_url – VMware Cloud Service console URL, e.g. : https://console.cloud.vmware.com
- vcdr_fqdn – The FQDN of the VCDR Orchestrator.
Then create a VCDRGetProtectedVMs.postman_collection.json file with the following content:
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
{ "info": { "name": "VCDR Get Protected VMs", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" }, "item": [ { "name": "Get authentication token from CSP", "event": [ { "listen": "test", "script": { "exec": [ "pm.collectionVariables.unset(\"csp_auth_token\");", "tests[\"Status code is 200\"] = responseCode.code === 200;", "var jsonData = JSON.parse(responseBody);", "tests[\"Access token exists\"] = jsonData.access_token !== null;", "pm.collectionVariables.set(\"csp_auth_token\", jsonData.access_token);" ], "type": "text/javascript" } } ], "request": { "auth": { "type": "noauth" }, "method": "POST", "header": [], "body": { "mode": "urlencoded", "urlencoded": [ { "key": "api_token", "value": "{{api_token}}", "type": "text" } ] }, "url": { "raw": "{{cloud_console_url}}/csp/gateway/am/api/auth/api-tokens/authorize", "host": [ "{{cloud_console_url}}" ], "path": [ "csp", "gateway", "am", "api", "auth", "api-tokens", "authorize" ] } }, "response": [] }, { "name": "Get cloud file systems", "event": [ { "listen": "test", "script": { "exec": [ "tests[\"Status code is 200\"] = responseCode.code === 200;", "var jsonData = JSON.parse(responseBody);", "tests[\"Cloud file systems exists\"] = jsonData.cloud_file_systems !== null;", "tests[\"There is at least 1 cloud file system\"] = jsonData.cloud_file_systems[0] !== null;", "console.log(\"Found \" + jsonData.cloud_file_systems.length + \" cloud file system(s).\"); ", "pm.collectionVariables.set(\"cfs_id\", jsonData.cloud_file_systems[0].id);", "console.log(\"Using cloud file system: \" + pm.collectionVariables.get(\"cfs_id\"));" ], "type": "text/javascript" } } ], "request": { "method": "GET", "header": [], "url": { "raw": "https://{{vcdr_fqdn}}/api/vcdr/v1alpha/cloud-file-systems", "protocol": "https", "host": [ "{{vcdr_fqdn}}" ], "path": [ "api", "vcdr", "v1alpha", "cloud-file-systems" ] } }, "response": [] }, { "name": "Get protected VMs for the first cloud file system", "event": [ { "listen": "test", "script": { "exec": [ "tests[\"Status code is 200\"] = responseCode.code === 200;", "var jsonData = JSON.parse(responseBody);", "console.log(\"Found \" + jsonData.vms.length + \" protected VMs.\");" ], "type": "text/javascript" } } ], "request": { "method": "GET", "header": [], "url": { "raw": "https://{{vcdr_fqdn}}/api/vcdr/v1alpha/cloud-file-systems/{{cfs_id}}/protected-vms", "protocol": "https", "host": [ "{{vcdr_fqdn}}" ], "path": [ "api", "vcdr", "v1alpha", "cloud-file-systems", "{{cfs_id}}", "protected-vms" ] } }, "response": [] } ], "auth": { "type": "apikey", "apikey": [ { "key": "key", "value": "x-da-access-token", "type": "string" }, { "key": "value", "value": "{{csp_auth_token}}", "type": "string" } ] }, "event": [ { "listen": "prerequest", "script": { "type": "text/javascript", "exec": [ "" ] } }, { "listen": "test", "script": { "type": "text/javascript", "exec": [ "" ] } } ], "variable": [ { "key": "csp_auth_token", "value": "" }, { "key": "cfs_id", "value": "" } ] } |
Using the VCDR Postman collection
Now, you can import the provided JSON file in Postman and run the collection by selecting the Save Responses checkbox in the Advanced settings section. Then you can go to the Test results and see the response body and headers for each request by clicking on its name.
The collection is ready to be reused. You can easily modify it and add another request to retrieve the protection groups – just use the https://{{vcdr_fqdn}}/api/vcdr/v1alpha/cloud-file-systems/{{cfs_id}}/protection-groups URL and run it again.
This demonstrates how easy it is to consume the VCDR REST API via Postman.
Follow the VMware DR Community Team on Twitter @VMware_DR_team and send us any feedback.