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

  1. Select the workflow "Workshop > Service Library > Service Library Template"
  2. Click the Presentation tab
  3. Select Hidden fields
  4. 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.
  5. 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

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

Name the workflow

  1. Enter the name of the workflow "Disk - Attach to VM"
  2. Click the Submit button

Edit the workflow

  1. 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.

  1. Delete the input parameter input1 (not shown in the screenshot)
  2. Add the following input parameters
    diskId [string]
    vmId [string]

Update presentation for the VM

  1. Select Presentation tab
  2. Select vmId input
  3. Update description field with
    Virtual Machine (vApp)
  4. Click the Add Property... button

Add a dropdown list

  1. Select Predefined list of elements
  2. Click the Ok button

Configure dropdown list

  1. Click the Search action button
  2. Enter getVmsL to filter the list of actions
  3. Select the action getVmsListForOrg
  4. For apiEndpoint, change the field from static to OGNL (using the dropdown) and select the input _vcd_apiEndpoint (using the pencil button)
  5. For orgId, change the field from static to OGNL (using the dropdown) and select the input _vcd_orgId (using the pencil button)
  6. Click the Apply button

Make the field mandatory

  1. Click the Add Property... button
  2. Select Mandatory input
  3. Click Ok button

Update presentation for the Disk

  1. Select diskId input
  2. Update description field with
    Independent Disk
  3. Click the Add Property... button

Add a dropdown list

  1. Select Predefined list of elements
  2. Click the Ok button

Configure dropdown list

  1. Click the Search action button
  2. Enter getdisk to filter the list of actions
  3. Select the action getDisksListForOrg
  4. For apiEndpoint, change the field from static to OGNL (using the dropdown) and select the input _vcd_apiEndpoint (using the pencil button)
  5. For orgId, change the field from static to OGNL (using the dropdown) and select the input _vcd_orgId (using the pencil button)
  6. Click the Apply button

Make the field mandatory

  1. Click the Add Property... button
  2. Select Mandatory input
  3. 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.

  1. Select Schema tab
  2. Select All Actions section
  3. Scroll down to find the module com.vmware.vcd.servicelibrary
  4. Expand module com.vmware.vcd.servicelibrary
  5. Insert the action getSystemAdminVcdHost after getContext workflow element

Get vCloud:Host object - Bind parameters

  1. Make sure the action previously added is selected on the schema and click on Setup...
  2. Observe that the attribute _ctx_vcd_apiEndpoint has been automatically chosen to bind the first and only input
  3. Change the output binding to Local variable and the name to vcdHost
  4. Click the Promote button

Get Disk object - Add Element

  1. Insert the action getDiskByIdForOrg after the last workflow element

Get Disk object - Bind parameters

  1. Make sure the action  previously added is selected on the schema and click on Setup...
  2. 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
  3. Change the output binding to Local variable and the name to diskObj
  4. Click the Promote button

Get VM object - Add Element

  1. Insert the action getVmByIdForOrg after the last workflow element

Get VM object - Bind parameters

  1. Make sure the action  previously added is selected on the schema and click on Setup...
  2. 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
  3. Change the output binding to Local variable and the name to vmObj
  4. Click the Promote button

Attach Disk - Add element

  1. Enter attachDisk in the search box and press RETURN
  2. Insert the action attachDiskVM after the last workflow element

Attach Disk - Bind parameters

  1. Make sure the action  previously added is selected on the schema and click on Setup...
  2. For the first parameter, select vmObj from the dropdown list
  3. For the second parameter, select diskObj from the dropdown list
  4. Change the output binding to Local variable and the name to task
  5. 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.

  1. Enter Wait for a task in the search box and press RETURN
  2. Insert the workflow Wait for a task after the last workflow element

Wait for a task - Bind parameters

  1. Make sure the workflow previously added is selected on the schema and click on Setup...
  2. For the first parameter, task should be already selected
  3. Click the Promote button

Save and close

Click the Save and close button

Create the Service in Service Library

  1. Launch Chrome
  2. Select the bookmark vCloud Director > Site A - H5 Admin
  3. Enter credentials
    user: administrator
    password: VMware1!
  4. Click the LOGIN button
  1. Click the menu button
  2. Click the Content Libraries element
  3. Select Service Management tab
  4. Select Service Categories tab

Create a Service Category

  1. Click the ADD button
  2. Enter a Name: Disk
  3. Select an Icon: Downloads > hard-disk-solid.png
  4. Enter a Description: Independent Disk Management
  5. Click the SAVE button

Create the new Service

  1. Select Service Library
  2. Click the NEW button

Select Category

  1. Select the Disk category
  2. Click the NEXT button

Select Orchestrator

  1. Select the vro-01a server
  2. Click the NEXT button

Select Workflow

  1. Select the Workshop > Service Library > Disk - Attach to VM workflow
  2. Click the NEXT button

Validate

  1. Click the DONE button

Publish the Service

  1. Click the MANAGE button
  2. Select Publish Workflow [not shown in the screenshot]

Publish to all tenants

  1. Toggle Publish to Tenants
  2. Toggle Publish to All Tenants
  3. Click the SAVE button

Test with Tenant T1

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

Launch the Service

  1. Click the menu button
  2. Click the Libraries element
  3. Select Service Library tab
  4. Click the EXECUTE button for the Service Disk - Attach to VM

Select the inputs and Execute

  1. Observe that the list of available VM is only the list of VM from Tenant T1, select one of the 2 VMs
  2. Observe that the list of available disks is only the list of independent disk from Tenant T2, select one from the list
  3. Click the FINISH button

Monitor the workflow running

  1. It is possible to check the status of the workflow directly within vCloud Director UI from the Recent Tasks pane.

Verify the disk has been added

Navigate to the details of the Virtual Machine and observe the list of Disks. The Disk that has been selected as an input should have been added.

It is also possible to see from the Independent Disk list that the disk is now attached to 1 VM.

Create workflow to detach disk to VM

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

Name the workflow

  1. Enter the name of the workflow "Disk - Detach from VM"
  2. Click the Submit button

Edit the workflow

  1. Click the Edit button

Update presentation for the Disk

  1. Select the Presentation tab
  2. Select diskId input
  3. Click the Search action button
  4. Enter getdiskslist to filter the list of actions
  5. Select the action getDisksListForVm
  6. 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)
  7. Click the Apply button

Change Action

  1. Click the Schema tab
  2. Select the action attachDiskVM
  3. Click Change action in the menu

Select new action

  1. Enter detachD in the search field
  2. Select the action detachDiskVM
  3. 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,

  1. Click the menu button
  2. Click the Content Libraries element
  3. Select Service Library tab

Create the new Service

  1. Click the NEW button

Select Category

  1. Select the Disk category
  2. Click the NEXT button

Select Orchestrator

  1. Select the vro-01a server
  2. Click the NEXT button

Select Workflow

  1. Select the Workshop > Service Library > Disk - Detach from VM workflow
  2. Click the NEXT button

Validate

  1. Click the DONE button

Publish the Service

  1. Click the MANAGE button (for the Disk - Detach from VM service)
  2. Select Publish Workflow [not shown in the screenshot]

Publish to all tenants

  1. Toggle Publish to Tenants
  2. Toggle Publish to All Tenants
  3. Click the SAVE button

Test with Tenant T1

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

Launch the Service

  1. Click the menu button
  2. Click the Libraries element
  3. Select Service Library tab
  4. Click the EXECUTE button for the Service Disk - Detach to VM

Select the inputs and Execute

  1. Observe that the list of available VM is only the list of VM from Tenant T1 with independent disk attached, select one.
  2. Observe that the list of available disks is only the list of independent attached to the VM selected above.
  3. Click the FINISH button

Monitor the workflow running

  1. It is possible to check the status of the workflow directly within vCloud Director UI from the Recent Tasks pane.

Verify the disk has been detached

Navigate to the details of the Virtual Machine and observe the list of Disks. The Disk is not longer attached to the VM.

It is also possible to see from the Independent Disk list that the disk is now attached to 0 VM.

Test with Tenant T2

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

Launch the Service

  1. Click the menu button
  2. Click the Libraries element
  3. Select Service Library tab
  4. Click the EXECUTE button for the Service Disk - Attach to VM

Select the inputs and Execute

  1. Observe that the list of available VM is only the list of VM from Tenant T2.
  2. Observe that the list of available disks, it is empty since no independent disks has been created in tenant T2.
  3. 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.