Manage Independent Disks
Independent Disks are disks that can be created outside of a VM and then later attached/detached on-demand to one or multiple virtual machine. The vCloud Director UI allows to create and delete independent disks but it doesn't allow to attach/detach them to/from VMs. The only option being API or CLI.
In order to improve the user experience, this exercise will explain how to leverage vRealize Orchestrator to do this task. It will also highlights how to leverage context information passed by vCloud Director to vRealize Orchestrator to make sure that information displayed are only related to a the tenant where the service is executed.
Observe the Service Library Template
vCloud Director passes context information for the presentation (through inputs) and for the execution (through ContextExecution). In order to make it easier, a pre-created workflow will be used as template. It already contains the logic to easily capture these context informations
- Select the workflow "Workshop > Service Library > Service Library Template"
- Click the Presentation tab
- Select Hidden fields
- Observe that the whole display group is hidden, so the variable are usable by other fields to create dynamic presentation but they are not visible when a user launch the workflow presentation.
- All the fields containing context information that are passed by vCD when the presentation is invoked.
How to capture context information
Despite context information being passed to inputs in the presentation, when the workflow runs, these information needs to be retrieved through the ExecutionContext class.
This couple of javascript lines, assign all these values to workflow attributes (prefixed by _ctx_) so they can be easily used later in the workflow.
Create workflow to attach disk to VM

- Right-Click on the workflow "Workshop > Service Library > Service Library Template"
- Click on Duplicate workflow...
Name the workflow

- Enter the name of the workflow "Disk - Attach to VM"
- Click the Submit button
Edit the workflow

- Click the Edit button
Add inputs

In order to attach an independent disk to a VM, it is needed for the user to be able to select the VM and the Disk, preferably from a dropdown list. Two input parameters are created for that.
- Delete the input parameter input1 (not shown in the screenshot)
-
Add the following input parameters
diskId [string]
vmId [string]
Update presentation for the VM

- Select Presentation tab
- Select vmId input
- Update description field with
Virtual Machine (vApp)
- Click the Add Property... button
Add a dropdown list

- Select Predefined list of elements
- Click the Ok button
Configure dropdown list
- Click the Search action button
- Enter getVmsL to filter the list of actions
- Select the action getVmsListForOrg
- For apiEndpoint, change the field from static to OGNL (using the dropdown) and select the input _vcd_apiEndpoint (using the pencil button)
- For orgId, change the field from static to OGNL (using the dropdown) and select the input _vcd_orgId (using the pencil button)
- Click the Apply button
Make the field mandatory
- Click the Add Property... button
- Select Mandatory input
- Click Ok button
Update presentation for the Disk

- Select diskId input
- Update description field with
Independent Disk
- Click the Add Property... button
Add a dropdown list

- Select Predefined list of elements
- Click the Ok button
Configure dropdown list
- Click the Search action button
- Enter getdisk to filter the list of actions
- Select the action getDisksListForOrg
- For apiEndpoint, change the field from static to OGNL (using the dropdown) and select the input _vcd_apiEndpoint (using the pencil button)
- For orgId, change the field from static to OGNL (using the dropdown) and select the input _vcd_orgId (using the pencil button)
- Click the Apply button
Make the field mandatory
- Click the Add Property... button
- Select Mandatory input
- Click Ok button
Build the schema
Our workflow inputs and presentation are setup, it is now time to develop the workflow. Take the available inputs and context information and invoke the appropriate action.
Get vCloud:Host object - Add Element
vCD passes an API endpoint URL in the context (https://vcd-01a.corp.loca/api), but in vRO, most of action and workflow requires a vCloud:Host object. By using an action, it is going to convert this url into a useful vRO object that can be utilized later.
- Select Schema tab
- Select All Actions section
- Scroll down to find the module com.vmware.vcd.servicelibrary
- Expand module com.vmware.vcd.servicelibrary
- Insert the action getSystemAdminVcdHost after getContext workflow element
Get vCloud:Host object - Bind parameters
- Make sure the action previously added is selected on the schema and click on Setup...
- Observe that the attribute _ctx_vcd_apiEndpoint has been automatically chosen to bind the first and only input
- Change the output binding to Local variable and the name to vcdHost
- Click the Promote button
Get Disk object - Add Element
- Insert the action getDiskByIdForOrg after the last workflow element
Get Disk object - Bind parameters
- Make sure the action previously added is selected on the schema and click on Setup...
- Observe that the action input parameters automatically bound:
First parameter bound to the workflow input diskId (previously created)
Second parameter automatically bound to the existing attribute _ctx_vcd_orgId
Third parameter automatically bound to the existing attribute vcdHost - Change the output binding to Local variable and the name to diskObj
- Click the Promote button
Get VM object - Bind parameters
- Make sure the action previously added is selected on the schema and click on Setup...
- Observe that the action input parameters automatically bound:
First parameter bound to the workflow input vmId (previously created)
Second parameter automatically bound to the existing attribute _ctx_vcd_orgId
Third parameter automatically bound to the existing attribute vcdHost - Change the output binding to Local variable and the name to vmObj
- Click the Promote button
Attach Disk - Add element
- Enter attachDisk in the search box and press RETURN
- Insert the action attachDiskVM after the last workflow element
Attach Disk - Bind parameters
- Make sure the action previously added is selected on the schema and click on Setup...
- For the first parameter, select vmObj from the dropdown list
- For the second parameter, select diskObj from the dropdown list
- Change the output binding to Local variable and the name to task
- Click the Promote button
Wait for a task - Add Element
The action attachVm is returning a vCloud Task, it is needed to wait for the end of this task before considering the action complete and successful. The workflow we are adding now is meant to wait for any vCloud Director task. It will throw an error if the task fails, making our workflow fail as well.
- Enter Wait for a task in the search box and press RETURN
- Insert the workflow Wait for a task after the last workflow element
Wait for a task - Bind parameters
- Make sure the workflow previously added is selected on the schema and click on Setup...
- For the first parameter, task should be already selected
- Click the Promote button
Save and close

Click the Save and close button
Create the Service in Service Library

- Launch Chrome
- Select the bookmark vCloud Director > Site A - H5 Admin
- Enter credentials
user: administrator
password: VMware1! - Click the LOGIN button
Navigate to Service Library

- Click the menu button
- Click the Content Libraries element
- Select Service Management tab
- Select Service Categories tab
Create a Service Category
- Click the ADD button
- Enter a Name: Disk
- Select an Icon: Downloads > hard-disk-solid.png
- Enter a Description: Independent Disk Management
- Click the SAVE button
Create the new Service

- Select Service Library
- Click the NEW button
Select Workflow
- Select the Workshop > Service Library > Disk - Attach to VM workflow
- Click the NEXT button
Publish the Service

- Click the MANAGE button
- Select Publish Workflow [not shown in the screenshot]
Publish to all tenants

- Toggle Publish to Tenants
- Toggle Publish to All Tenants
- Click the SAVE button
Test with Tenant T1

- Launch Chrome in incognito mode
- Select the bookmark vCloud Director > Site A - Tenant T1 - H5 UI
- Enter credentials
user: t1admin
password: VMware1! - Click the LOGIN button
Launch the Service

- Click the menu button
- Click the Libraries element
- Select Service Library tab
- Click the EXECUTE button for the Service Disk - Attach to VM
Select the inputs and Execute
- Observe that the list of available VM is only the list of VM from Tenant T1, select one of the 2 VMs
- Observe that the list of available disks is only the list of independent disk from Tenant T2, select one from the list
- Click the FINISH button
Monitor the workflow running
- It is possible to check the status of the workflow directly within vCloud Director UI from the Recent Tasks pane.
Create workflow to detach disk to VM

- Right-Click on the workflow "Workshop > Service Library > Disk - Attach to VM"
- Click on Duplicate workflow...
Name the workflow

- Enter the name of the workflow "Disk - Detach from VM"
- Click the Submit button
Edit the workflow

- Click the Edit button
Update presentation for the Disk
- Select the Presentation tab
- Select diskId input
- Click the Search action button
- Enter getdiskslist to filter the list of actions
- Select the action getDisksListForVm
- For apiEndpoint, leave it as it is
For vmId, select the input vmId (using the pencil button)
For orgId, change the field from static to OGNL (using the dropdown) and select the input _vcd_orgId (using the pencil button) - Click the Apply button
Change Action
- Click the Schema tab
- Select the action attachDiskVM
- Click Change action in the menu
Select new action

- Enter detachD in the search field
- Select the action detachDiskVM
- Click the Select button
Since the signature of the action is exactly the same as for the attachDiskVM action, all the parameters stay bound as they were before.
Save and close

Click the Save and close button
Create the Service in Service Library

In vCloud Director HTML5 Provider UI,
- Click the menu button
- Click the Content Libraries element
- Select Service Library tab
Create the new Service

- Click the NEW button
Select Workflow
- Select the Workshop > Service Library > Disk - Detach from VM workflow
- Click the NEXT button
Publish the Service

- Click the MANAGE button (for the Disk - Detach from VM service)
- Select Publish Workflow [not shown in the screenshot]
Publish to all tenants

- Toggle Publish to Tenants
- Toggle Publish to All Tenants
- Click the SAVE button
Test with Tenant T1

- Launch Chrome in incognito mode
- Select the bookmark vCloud Director > Site A - Tenant T1 - H5 UI
- Enter credentials
user: t1admin
password: VMware1! - Click the LOGIN button
Launch the Service

- Click the menu button
- Click the Libraries element
- Select Service Library tab
- Click the EXECUTE button for the Service Disk - Detach to VM
Select the inputs and Execute
- Observe that the list of available VM is only the list of VM from Tenant T1 with independent disk attached, select one.
- Observe that the list of available disks is only the list of independent attached to the VM selected above.
- Click the FINISH button
Monitor the workflow running
- It is possible to check the status of the workflow directly within vCloud Director UI from the Recent Tasks pane.
Test with Tenant T2

- Launch Chrome in incognito mode
- Select the bookmark vCloud Director > Site A - Tenant T2 - H5 UI
- Enter credentials
user: t2admin
password: VMware1! - Click the LOGIN button
Launch the Service

- Click the menu button
- Click the Libraries element
- Select Service Library tab
- Click the EXECUTE button for the Service Disk - Attach to VM
Select the inputs and Execute
- Observe that the list of available VM is only the list of VM from Tenant T2.
- Observe that the list of available disks, it is empty since no independent disks has been created in tenant T2.
- If the FINISH button is clicked, an error will appears because the disk is a mandatory input.
Try to add independent disks or VMs to tenant T2 to see the behavior change.