Skip to content
vWorld
Menu
  • Main Page
  • About
  • Study Guide
    • VCAP-CMA Deploy 2018
Menu

Change VM Name before deploy

Posted on January 19, 2019January 19, 2019 by admin

vRealize Automation giving us the possibility to use Machine Prefixes to set VM name in deployment process, but what we can do when this is too small functionality.

Then we can use vRealize Orchestrator and Event Broker. Event Broker helps us to upgrade functionality vRealize Automation with workflow deployed in vRealize Orchestrator.

Event Broker is a solution which run element from workflow based on some conditions defined in vRA

In our case we want change VM name before it is deployed. So at the begining we need to creat blueprint and for connection between blueprint and Event Broker we need to add custom properties from list of available.

Extensibility.Lifecycle.Properties.VMPSMasterWorkflow32.Buildingmachine
Extensibility.Lifecycle.Properties.VMPSMasterWorkflow32.DeactivateMachine
Extensibility.Lifecycle.Properties.VMPSMasterWorkflow32.Disposing
Extensibility.Lifecycle.Properties.VMPSMasterWorkflow32.MachineActivated
Extensibility.Lifecycle.Properties.VMPSMasterWorkflow32.MachineProvisioned
Extensibility.Lifecycle.Properties.VMPSMasterWorkflow32.RegisterMachine
Extensibility.Lifecycle.Properties.VMPSMasterWorkflow32.Requested
Extensibility.Lifecycle.Properties.VMPSMasterWorkflow32.UnprovisionMachine
Extensibility.Lifecycle.Properties.VMPSMasterWorkflow32.WaitingToBuild

In this case we want to change name before everything so we will use extensibility VMPSMasterWorkflow32.Requested

Now we can create subscription which will be connectet with specific workflow.

Go to the Administration –> Events –> Subscriptions and click new

In first tab we need to select Event Topic. Every element providing to us something differen but in this case we will manage VM so we have to choose Machine Provisioning

At the condition tabe set the Requested Phase and PRE as a condition

In next tab we will choose our workflow from vRealize Orchestrator but first we need to create it.

So go to the vRO and create new workflow.

My workflow has 3 element. Two Scriptable Task and 1 Action from out of box actions.

First scriptable task is for collecting data from payload which is properties send by Event Broker

IN: payload(Properties)

OUT: virtualMachineId(string),Hostname(string),NewHostname(string)

var machine = payload.get("machine");
var virtualMachineId = payload.get("machine").get("id");
var machineProperties = machine.get('properties');
var node_name = machineProperties.get("node_name");
var Hostname = machine.get('name');
System.log(Hostname);
var NewHostname = Hostname + node_name

Action which is delivered by VM getting VirtualMachineEntityFromId wchich we collect from payload.

IN: virtualMachineId(string) ,host(vCAC:VCACHost)

OUT: actionResult(vCAC:Entity)

//Auto generated script, cannot be modified !
actionResult = System.getModule("com.vmware.library.vcac").getVirtualMachineEntityFromId(host,virtualMachineId);

And in last script we are doing actual change

IN: NewHostname(string) , virtualMachineEntity(vCAC:Entity)

OUT:

System.log(workflow.currentWorkflow.name+": Updating VirtualMachineName to '" + NewHostname + "'.");


//Get the properties of the vCAC VM Entity object (different than vCAC custom properties)
var vmEntityProps = virtualMachineEntity.getProperties();

//Change the VirtualMachineName property by deleting it and re-adding it
vmEntityProps.remove('VirtualMachineName');
vmEntityProps.put('VirtualMachineName', NewHostname);

//Update the Entity object to save the change
var hostId = virtualMachineEntity.hostId;
var modelName = virtualMachineEntity.modelName;
var entitySetName = virtualMachineEntity.entitySetName;
var entityIdString = virtualMachineEntity.keyString;
var actionResult = System.getModule("com.vmware.library.vcac").updateVCACEntity(hostId,modelName,entitySetName,entityIdString,vmEntityProps,null,null);

System.log(workflow.currentWorkflow.name+": Update of VirtualMachineName finished.");

All those element after succesfully run change VM name for that as we Request. So now we can add this workflow to our Event broker




In details setup the name and publish this subscription




Share with:


Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • VCF Automation: From Zero to a Running Virtual Machine – A Step-by-Step Guide
  • Activating the Supervisor in VMware Cloud Foundation 9 with NSX VPC – A Step-by-Step Guide
  • Configuring an NSX Edge Cluster in VMware Cloud Foundation 9
  • Complete pfSense 2.7.2‑RELEASE configuration for a VMware Cloud Foundation 9 home lab
  • Automating vRO Workflow Documentation with GitHub Actions

Archives

Follow Me!

Follow Me on TwitterFollow Me on LinkedIn

GIT

  • GITHub – vWorld GITHub – vWorld 0
© 2025 vWorld | Powered by Superbs Personal Blog theme