VMware Cloud Community
pizzle85
Expert
Expert

vRA 8 VM with multiple unique disks

I have released a version 2 that allows the disks to be managed by vRA GitHub - pgsmith123/vRA8.1

So we have the requirement to allow our customers to create VMs with N disks, each with a unique size and on a unique tier. Our rules are that each disk can only be 1TB in size and that storage has to be purchased in "blocks" based on the selected tier. To facilitate this we used cloud assembly tied with a subscription to call a vRO workflow. Essentially CA creates the VM and at the compute allocated state we execute the "Add disk" vRO workflow to add disks. The disks show up in CA at the next inventory cycle under the VM resource storage section and are deleted when the VM is deleted. They do not show up as objects on the deployment topology nor in the deployment resource list and are not re-configurable in CA.

This is a work in progress and is a ghetto way to get this working. But if it satisfies your needs here's the specifics...

CA Blueprint Code

inputs:

  az:

    type: string

    enum:

      - AZ1

      - AZ2

    title: Availability Zone

  bootDiskTier:

    type: string

    enum:

      - Gold

      - Silver

      - Bronze

    title: Boot Disk Tier

  bootDiskCapacityGB:

    type: number

    title: Boot Disk Size GB

    minimum: 80

    maximum: 1000

  disks:

    type: array

    title: Disks

    items:

      type: object

      properties:

        tier:

          type: string

          title: Tier

          enum:

            - Gold

            - Silver

            - Bronze

        size:

          type: number

          title: Size GB

          minimum: 80

          maximum: 1000

resources:

  Cloud_vSphere_Machine_1:

    type: Cloud.vSphere.Machine

    properties:

      disks: '${to_string(input.disks)}'

      az: '${input.az}'

      storage:

        bootDiskCapacityInGB: '${input.bootDiskCapacityGB}'

        constraints:

          - tag: 'storageTier:${input.bootDiskTier}'

I built two custom actions and two custom workflow. I cant figure out how to export them from the embedded vRO... so here's the code.

getVmFromVcenterByName

Inputs:

vmName     string

Return type:     VC:VirtualMachine

System.log("Trying to resolve a vCenter VM with ID: " + vmName);

var vms = Server.findAllForType('VC:VirtualMachine', vmName);

if (vms.length > 0) {

     for each (vm in vms) {

          if (vm.name == vmName) {

               System.log('Found vCenter VM ' + vm.name);

               return vm;

          }

     }

}

throw 'No vCenter found with name ' + vmName;

getDatastoreWithMostFreeSpace

Inputs:

vc                  VC:sdkConnection

datacenter     string

tier                 string

Return type:     VC:Datastore

var datastores = System.getModule("com.vmware.library.vc.datastore").getAllDatastoresOfVC(vc);
var validDatastores = new Array()
for each (datastore in datastores) {if (datastore.parent.name.toLowerCase().indexOf(datacenter.toLowerCase()) > -1 && datastore.parent.name.toLowerCase().indexOf(tier.toLowerCase()) > -1) {        validDatastores.push(datastore);    }}validDatastores.sort(function(a,b){// Turn your strings into dates, and then subtract them// to get a value that is either negative, positive, or zero.return new Number(b.info.freeSpace) - new Number(a.info.freeSpace);});return validDatastores[0];

Add disk to VM

The first workflow just calls the system "Add disk" workflow and takes in input of a composite type to work around the limit of one input array to the foreach workflow in the next workflow below. Input each type in the composite type to the appropriate input on the Add disk workflow.

Inputs:

  disk Object     CompositeType(vm:VC:VirtualMachine,datastore:VC:Datastore,diskIndex:number,diskSize:number,diskMode:VC:VirtualDiskMode,scsiBusNumber:number,thinProvisioned:boolean):disk

CA-Add disks to VM

This woflow grabs the VM name from the input properties, then runs the getVmFromVcenterByName action above then builds the array of composite types from the "disks" inputs from the CA blueprint then executes the "Add disk to VM" workflow above in a loop to add each disk.

pastedImage_9.png

Build Disk Objects script code

Inputs:

inputProperties     Properties

vm                         VC:VirtualMachine

thinProvisioned      boolean

diskMode               VC:VirtualDiskMode

Outputs:

diskObjects     Array/CompositeType(vm:VC:VirtualMachine,datastore:VC:Datastore,diskIndex:number,diskSize:number,diskMode:VC:VirtualDiskMode,scsiBusNumber:number,thinProvisioned:boolean):disk

diskObjects = new Array();
var disks = JSON.parse(inputProperties.get('customProperties').get('disks'));
var i = 1;
for each (disk in disks) {
     var obj = new Object();
     obj.vm = vm;
     obj.datastore = System.getModule("edu.ufl.vcenter").getDatastoreWithMostFreeSpace(Server.findForType('VC:SdkConnection', vm.sdkId.split('/'[0]),inputProperties.get('customProperties').get('az'),disk.tier);
      obj.diskIndex = i;
     obj.diskSize = disk.size * 1;
     obj.diskMode = diskMode;
     obj.thinProvisioned = thinProvisioned;
     diskObjects.push(obj);
     i++
}
2 Replies
mmonkman
Enthusiast
Enthusiast

This is a great post and addresses the requirement that I have too for specifying N disks and sizes in the CA blueprint.

Would you mind elaborating further how on to create the composite array that feeds in to the for each loop?

Do you set a value for diskMode anywhere?  I can't see how this value gets populated.

Thank you.

0 Kudos
maneeSEA
Contributor
Contributor

Does this add them in the order in which they appear in the array? 
0 Kudos