IntegraRoger
Enthusiast
Enthusiast

vRA 7.2 VM Rename problem

Jump to solution

So, I have setup vRA 7.2 (internal vRO) and all properties are applied including adding to the appropriate domain and OU, but I CANNOT get the extensibility to work so that I can rename either the VM name or the hostname within the VM. I kind of gave up on the lattter as I could not understand how to make some of these canned solutions work... no CLUE how to get vCAC:Entity or any of the other vCAC:<whatever> to work...  so I got approval to just set the VM Name and have that propagate to the nodename...  While I can pass all the variables and create the appropriate naming using the standard nomenclature, I just cannot get the name to change.

This is the code I am using:

// Retrieve the machine properties

var machine = payload.get("machine");

// Check the machine properties exists

if (machine == null) { throw "Unable to retrieve Machine Properties."; }

// Retrieve the values required

// virtualMachineID = machine.get("id");

// System.log(workflow.currentWorkflow.name+" System GUID is "+virtualMachineID)

var machineProperties = machine.get("properties");

//Read the hostname generated by vRA (TEE2-busGrp-run#)

var vmName = machine.get("name");

var len = vmName.length - 4;

System.log(workflow.currentWorkflow.name+" Current hostname is "+vmName);

// Remove the prefix part, leaving the unique ID

var uniqueID = vmName.substr(len);

// Retrieve the variables

var location = machineProperties.get("LOC.Hostname.Location");

var vmType = machineProperties.get("LOC.Hostname.Type");

var busGrp = machineProperties.get("LOC.Hostname.BusGrp");

// Build new hostname

var newHostname = (location+vmType+busGrp+uniqueID);

System.log(workflow.currentWorkflow.name+" New VM Name and Windows hostname will be "+newHostname);

// Change the VM Name along with the Windows hostname

var resultCode = payload.virtualMachineAddOrUpdateProperties.put("hostname", newHostname);

System.log(workflow.currentWorkflow.name+"Workflow OSFI Rename VM complete. "+resultCode);

Logs from the Orchestrator Run:

[2017-10-27 16:35:54.424] [I] UpdateMachineName Current hostname is TEE2-Dev-048

[2017-10-27 16:35:54.427] [I] UpdateMachineName New VM Name and Windows hostname will be CVOT-Test-dev-048

[2017-10-27 16:35:54.429] [I] UpdateMachineNameWorkflow OSFI Rename VM complete. undefined

As I said, everything gets passed through as I have the subscription setup as such:

Machine provisioning

Topic ID: com.vmware.csp.iaas.blueprint.service.machine.lifecycle.provision

Name: Machine provisioning

Description: Machine lifecycle events that are triggered during the provisioning phase

Publisher: iaas-service

Blockable: Yes

Replyable: No

Conditions:

Data > Lifecycle state > Lifecycle state name Equals VMPSMasterWorkflow32.BuildingMachine

Data > Lifecycle state > State phase Equals PRE

Data > Machine > Machine type Equals Virtual Machine

I've selected the Workflow (the script above) and it executes just fine... except that it does nothing to the VM.

I'm guessing that the undefined in the logs above means payload.virtualMachineAddOrUpdateProperties didn't run, but I have no clue why...Any suggestions?

Thanks in advance,

Roger

1 Solution

Accepted Solutions
CalicoJack
Enthusiast
Enthusiast

My code is an example of day-2 operations (rename VM). It takes VM (VC:VirtualMachine) as input, no output. Only in this particular case you have to work with vCAC/Entity.

If your question is to rename VM before building but after an end-user submitted request - it is even more easy!

var machine = payload.get("machine");

virtualMachineAddOrUpdateProperties = new Properties ();

virtualMachineAddOrUpdateProperties.put('Name', Your_hostname);

virtualMachineAddOrUpdateProperties.put('Hostname', Your_hostname);

virtualMachineAddOrUpdateProperties.put('DnsName', Your_hostname);

Keep in mind that you need to define "Your_hostname" somewhere/somehow. In my case, it is defined in blueprint custom property. To get it, use this code:

var vra_vm_prop = machine.get("properties");

var Your_hostname = vra_vm_prop.get("MyOrg.Your_hostname");

Don't forget to specify virtualMachineAddOrUpdateProperties (type Properties) as output of your workflow. In even broker configure this event for VMPSMasterWorkflow32.Requested PRE-stage.

BTW, if you still have issues with this case, try to google virtualMachineAddOrUpdateProperties - you could find a lot of details how to properly use it.

View solution in original post

0 Kudos
9 Replies
daphnissov
Immortal
Immortal

If you're open to a separate solution, SovLabs has a Custom Naming module for vRA which takes care of this automatically and without any vRO code on your part.

0 Kudos
IntegraRoger
Enthusiast
Enthusiast

The problem there is that you have to pay for the SOVLabs stuff...

0 Kudos
CalicoJack
Enthusiast
Enthusiast

Well, I know this game, please be ready for a lot of coding. My own script to properly rename VM in vRA is almost page long Smiley Happy Looks like VMware doesn't support it well.

Lets assume that you have you VC:VirtualMachine, here is hot to convert it to vCAC/Entity:

var vCAC_Machine = Server.findAllForType("vCAC:VirtualMachine","VMUniqueID eq '" + vm.config.instanceUuid + "'");

var virtualMachineEntity = vCAC_Machine[0].getEntity(); //to get entity

var vmEntityProps = virtualMachineEntity.getProperties(); //to get Entity properties for the next step

vmEntityProps.remove('VMDNSName');

vmEntityProps.put('VMDNSName', newName);

var hostId = virtualMachineEntity.hostId;

var modelName = virtualMachineEntity.modelName;

var entitySetName = virtualMachineEntity.entitySetName;

var entityIdString = virtualMachineEntity.keyString;

//Magic!

var Entity_Update = System.getModule("com.vmware.library.vcac").updateVCACEntity(hostId,modelName,entitySetName,entityIdString,vmEntityProps,null,null);

var VM_update_Hostname = System.getModule("com.vmware.library.vcac").addUpdatePropertyFromVirtualMachineEntity(vCAC_host,virtualMachineEntity,"Hostname",newName,false,false,false,false

It is not a complete script, but at least you get something to work with. I don't understand why VMware is keeping this stuff so complicated. Renaming VM should be OOTB feature in vRA interface. A lot of big enterprise needs this.

IntegraRoger
Enthusiast
Enthusiast

Can I assume that (in your example) that vm.config.instanceUuid is the same as the "payload" delivered information in machine.id (which I believe is the GUID?) or do you get 'vm' as input somewhere above and not from the extensibility payload?

Also, this whole vCAC:Host... I have been unable to use any of the VCAC:Entity or VCAC:Host based elements... is there a configuration workflow I need to run first to configure my vRA host as a viable entity for these libraries?

0 Kudos
CalicoJack
Enthusiast
Enthusiast

My code is an example of day-2 operations (rename VM). It takes VM (VC:VirtualMachine) as input, no output. Only in this particular case you have to work with vCAC/Entity.

If your question is to rename VM before building but after an end-user submitted request - it is even more easy!

var machine = payload.get("machine");

virtualMachineAddOrUpdateProperties = new Properties ();

virtualMachineAddOrUpdateProperties.put('Name', Your_hostname);

virtualMachineAddOrUpdateProperties.put('Hostname', Your_hostname);

virtualMachineAddOrUpdateProperties.put('DnsName', Your_hostname);

Keep in mind that you need to define "Your_hostname" somewhere/somehow. In my case, it is defined in blueprint custom property. To get it, use this code:

var vra_vm_prop = machine.get("properties");

var Your_hostname = vra_vm_prop.get("MyOrg.Your_hostname");

Don't forget to specify virtualMachineAddOrUpdateProperties (type Properties) as output of your workflow. In even broker configure this event for VMPSMasterWorkflow32.Requested PRE-stage.

BTW, if you still have issues with this case, try to google virtualMachineAddOrUpdateProperties - you could find a lot of details how to properly use it.

View solution in original post

0 Kudos
IntegraRoger
Enthusiast
Enthusiast

While I care about the VM name, the more important name is what is registered in DNS and what the nodename is in the OS (Windows 10, 7, 2008, 2012 and 2016). if I can also make the VM name be what those two are for consistency, then that's a bonus.

I've spent a week on just this problem alone... thank you so much for your help... for someone who is new to Orchestrator (at least creating new workflows etc) and having only worked on v. 6.01 of vCAC, this is incredibly confusing...

Again, thank you thank you and thank you!

0 Kudos
IntegraRoger
Enthusiast
Enthusiast

are you sure on the VMPSMasterWorkflow32.Requested PRE-stage? I forgot to change this off of VMPSMasterWorkflow32.BuildingMachine. Livecycle Stage = Pre and it substituted the VM name and the system hostname, but not the DNS entry...

0 Kudos
CalicoJack
Enthusiast
Enthusiast

In Requested-PRE phase nothing is actually happening, this is the lest step before vRA is beginning building/execute your request. I'm not a VMware engineer, but I strongly recommend to use Requested-PRE if you need to make changes in your machine. Just because no other objects (deployment/vms/etc) are existing yet. You may have inconsistency with vCAFE/vCAC objects otherwise. BTW, this is the stage where vRA is taking care of VM's hostname.

I'm not sure about DNS - what is it? What do you meant?

0 Kudos
IntegraRoger
Enthusiast
Enthusiast

I forgot to change the property in the Design...; le sigh... so many things to learn...

The DNS name is what is stored in the actual hostname within the OS... in vCenter its denoted as DNS name on the summary screen...

Its working now, thanks!

0 Kudos