Automatic disk resizing in vRA8 during deployment

In this post I described how to build a blueprint with multiple disk devices for MS Windows deployment. Now my Linux colleagues want a single disk with multiple LVM Virtual Groups on it. Based on this same disk form input as for Windows deployment of course.

The plan is to create one disk with a size equal to sum of all disks defined by user in an input form. Later we will create volume group structure on this disk and mount it to user defined mount points.

So lets start again with the Input definition (this is basically ^C^V form previous post):

inputs:
  disks:
    type: array
    title: Additional Disks
    description: Additional data disks.
    maxItems: 10
    minItems: 1
    items:
      type: object
      properties:
        mountPoint:
          type: string
          title: Mount Point
        size:
          type: integer
          title: Size (GB)
          minSize: 1
          maxSize: 1000
    default:
      - mountPoint: '/opt/MyApp'
        size: 100

On a blueprint level we add vSphere.Disk to design canvas and connect it to a VM. Add a custom property on the disk device level we will use it later in Extensibility Subscription.

UserVolumes:
    type: Cloud.vSphere.Disk
    properties:
      SetDisksDataRhel: true
      name: User Volumes
      capacityGb: 10  

We need a single disk and we will overwrite the size with vRO so that is all here.

Cloud Template Design

Now we will have to work on vRO workflow. We have to calculate total size of the disk based on user input and change it in the fly.

Create workflow named: “Set Disk Data Rhel”. It will get the inputProperties from vRA payload and calculate new disk size. Then it will overrate diskSizesInGb property this way in machine provisioning stage VM will be created with a proper disk size on vSphere level.

This code is using an action named vraService to get the deployment data form vRA. This is a simple REST call to vRA deployment service under url: /deployment/api/deployments/{depId}. If you want to know how to do a REST call to vRealize Automation 8 check this post.

Workflow Input:

  • inputProperties [Properties]

Outputs:

  • diskSizesInGb [Array/number]
  • customProperties [Properties]
customProperties = inputProperties.customProperties || new Properties();
diskSizesInGb = inputProperties.diskSizesInGb || new Array();
var deploymentId = inputProperties.deploymentId
System.debug('blueprintId: ' + deploymentId);
//Get input data
var VraService = System.getModule("com.libs.vra").vraService();
var vraService = new VraService();
var depl = vraService.getDeployment(deploymentId);
var disks = depl.inputs.disks;

System.log(JSON.stringify(disks));
var newDiskSize = 0; 

for each (var disk in disks){
    newDiskSize += disk.diskSize;
}
System.log("newDiskSize: " + newDiskSize)
diskSizesInGb[0] = newDiskSize;

Now we have to create subscription for Disk allocation state.

Go to Cloud Assembly -> Extensibility -> Subscriptions->New Subscription and add this.

Subscribtion

In the filter section you can see a bit of code:

event.data.customProperties.SetDisksDataRhel == 'true'

It is our insurance that this subscription will run only if you set a custom property on a disk device in the Cloud Templates designer. So this subscription will run only for our RHEL template not for a Windows one.

Now once we have the disk connected to VM, we will have to create LVM structure and mount points. I’m doing this using python/bash scripts and running it on a VM with VMware tools. Since this one is pretty specific to what I do I’m not publishing it here but if you are interested in more details drop me a mail.

As always good luck and make force be with you 😉