vRA 8.4.x – How to attach disconnected persistent volume to virtual machine using API

Last time, someone asked me: what if I add a persistent disk to the virtual machine and remove it from deployment in the vRealize Automation portal. How can I attach it again? I was a little confused because I didn’t know that it could be a problem. So, I checked it on my lab, and I was surprised that there is no GUI option to attach that disk again. Instead, it can be done by API. Below I give you short instructions on how you can do it using API. In this example, I use Postman to work with vRA API.

Defining a problem:

In the first step, let’s create a simple vRA deployment:

vRA-API-disk-1

Then, let’s add a new persistent volume. Persistent means that the disk will survive machine or deployment deletion :

vRA-API-disk-2
vRA-API-disk-3

And in the last step, we are going to remove that persistent volume from the virtual machine. Because it is a persistent volume, remove means to detach. So as you can see below, we still have our volume on a vSphere environment. But there is no GUI option to attach that disk again to VM from the vRA portal. So we will do it through vRA API.

vRA-API-disk-4

Solution – attach disk using vRA API

vRA API Documentation can be found:
https://<vraFQDN>/automation-ui/api-docs

To attach disk to VM, we can use API call:
POST /iaas/api/machines/{id}/disks

To do that we will need few things:
– vRA API token to act with API
– Virtual machine ID (to do that, we need our deployment ID)
– Volume ID
– Optional: Volume name, SCSI Controller and SCSI Unit

1. Get API Token
Method: POST
URL: /csp/gateway/am/api/login
Headers: Content-Type: application/json
Authorization: No Auth
What we need from response: cspAuthToken
Body:

{
	"username": "user",
	"password": "password",
	"domain": "blanketvm.com"
}
vRA-API-disk-5

2. Get our deployment ID (filter with name: diskAPI-1.0)
Method: GET
URL: /deployment/api/deployments?name=diskAPI-1.0
Headers: Content-Type: application/json
Authorization: Bearer Token (in token value paste cspAuthToken from step 1)
What we need from response: Deployment ID
Body: empty

vRA-API-disk-6

3. Get VM resource ID from our deployment (filter with resource types: Cloud.Machine or Cloud.vSphere.Machine)
Method: GET
URL: /deployment/api/deployments/{deployment ID from step 2}/resources?resourceTypes=Cloud.Machine,Cloud.vSphere.Machine
Headers: Content-Type: application/json
Authorization: Bearer Token (in token value paste cspAuthToken from step 1)
What we need from response: VM ID
Body: empty

vRA-API-disk-7

4. Get our volume ID (in this example I do not use any filters, but if you have to much volumes on output, use filters)
Method: GET
URL: /iaas/api/block-devices
Headers: Content-Type: application/json
Authorization: Bearer Token (in token value paste cspAuthToken from step 1)
What we need from response: Volume ID
Body: empty

vRA-API-disk-8

5. Attach volume to virtual machine in our deployment
Method: POST
URL: /iaas/api/machines/{VM ID from step 4}/disks
Headers: Content-Type: application/json
Authorization: Bearer Token (in token value paste cspAuthToken from step 1)
Body:
blockDeviceId – ID from step 4
scsiController – (Optional) SCSI controller number. In my example, I changed it from value that was at the beggining.
name – (Optional) Name of our volume resource from step 4
unitNumber – (Optional) SCSI unit number

{
  "blockDeviceId": "ea34911f-24b4-4624-95c8-afa169533b82", 
  "scsiController": "SCSI_Controller_1",
  "name": "HomeClient-603",
  "unitNumber": "5"
}
vRA-API-disk-9

And finally, we have our volume attached to VM:

vRA-API-disk-10

Summary

To summarize, be aware that our volume will not be visible on canvas!
vRA version 8.4.2 introduces new feature that will reflected on deployment (topology) diagram changes by vRO workflow or API but only when it is done on initial provisioning phase.
Disks that were added using vRO workflows or ABX with vRA APIs at the time of initial provisioning are also reflected on the deployment design canvas. All current day 2 actions are available for these disks.”
Stay tunned!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s