First I’ll add a few new inputs to the cloud template in Cloud Assembly:
inputs:
description:
type: string
title: Description
description: Server function/purpose
default: Testing 12345
poc_name:
type: string
title: Point of Contact Name
default: Phil
ticket:
type: string
title: Ticket/Request Number
default: 5497358
I’ll also need to add these to the resources section of the template so that they will get passed along with the deployment properties:
resources:
Cloud_vSphere_Machine_1:
type: Cloud.vSphere.Machine
properties:
poc: '${input.poc_name}'
ticket: '${input.ticket}'
description: '${input.description}'
vRO Workflow
Okay, so we’ve got the information to pass on to vCenter. Now I need to create a new workflow in vRO that will actually do that (after telling vRO how to connect to the vCenter, don’t forget this step!). I’ll want to call this after the VM has been provisioned, so I’ll call the workflow “VM Post-Provisioning”.
The workflow will have a single input from vRA, inputProperties of type Properties
The first thing this workflow needs to do is parse inputProperties (Properties)
to get the name of the VM, and it will then use that information to query vCenter and grab the corresponding VM object. So I’ll add a scriptable task item to the workflow canvas and call it Get VM Object
. It will take inputProperties (Properties)
as its sole input, and output a new variable called vm
of type VC:VirtualMachine
.
This is the script for this task:
// JavaScript: Get VM Object
// Inputs: inputProperties (Properties)
// Outputs: vm (VC:VirtualMachine)
var name = inputProperties.resourceNames[0]
var vms = VcPlugin.getAllVirtualMachines(null, name)
System.log("Found VM object: " + vms[0])
vm = vms[0]
I’ll add another scriptable task item to the workflow to actually apply the notes to the VM – I’ll call it Set Notes
, and it will take both vm (VC:VirtualMachine)
and inputProperties (Properties)
as its inputs.
The first part of the script creates a new VM config spec, inserts the description into the spec, and then reconfigures the selected VM with the new spec.
The second part uses a built-in action to set the Point of Contact
and Ticket
custom attributes accordingly.
// Javascript: Set Notes
// Inputs: vm (VC:VirtualMachine), inputProperties (Properties)
// Outputs: None
var notes = inputProperties.customProperties.description
var poc = inputProperties.customProperties.poc
var ticket = inputProperties.customProperties.ticket
var spec = new VcVirtualMachineConfigSpec()
spec.annotation = notes
vm.reconfigVM_Task(spec)
System.getModule("com.vmware.library.vc.customattribute").setOrCreateCustomField(vm,"Point of Contact", poc)
System.getModule("com.vmware.library.vc.customattribute").setOrCreateCustomField(vm,"Ticket", ticket)
Extensibility subscription
Now I need to return to Cloud Assembly and create a new extensibility subscription that will call this new workflow at the appropriate time. I’ll call it “VM Post-Provisioning” and attach it to the “Compute Post Provision” topic.
And then I’ll link it to my new workflow:
Then start testing
Leave a Reply