VMware Cloud Community
AEsansun2
Enthusiast
Enthusiast
Jump to solution

How to get VC:VirtualMachine from a vcac blueprint

I was trying to follow this guide below to create a workflow to be executed from a vcac blueprint.. Basically i took the template Vcac/infrastructure administrator/Workflow Template

which has this piece of code

if (vCenterVm != null) {

  System.log("Got vCloud VM " + vCenterVm.name);

}

Well, it never prints the vm name. I need it in order to run operations on the vm after the vm is deployed .. how am i able to get it .. and why would the template have it if it's

not availabl.e

How to extend vCAC with vCO Part 2 – Hello world Script in Guest | VMtoCloud.com

1 Solution

Accepted Solutions
stvkpln
Virtuoso
Virtuoso
Jump to solution

That was why I asked about what state this was being performed... if during BuildingMachine, then there is no VM object... it hasn't been created/cloned/whatever. Important piece of diagnostic data!

-Steve

View solution in original post

24 Replies
stvkpln
Virtuoso
Virtuoso
Jump to solution

0 Kudos
AEsansun2
Enthusiast
Enthusiast
Jump to solution

I am not getting an error , just not sure which step i am missing.   Like is it passed from vcac .. or how am i suppose to get it ?

0 Kudos
zebduin
Enthusiast
Enthusiast
Jump to solution

declare it as an input parameter.  its a vCenter object that vCO is able to retrieve.  For instance, if I wanted to reference

pastedImage_1.png

bind it appropriately (ignore the other inputs from my screenshot)

pastedImage_0.png

to ensure your VC:VirtualMachine object is returning the correct value, use System.log to display the results

System.log("VC VM Name = " + vm.name);

0 Kudos
AEsansun2
Enthusiast
Enthusiast
Jump to solution

Thank you for trying to help.

Yes, that is what i have done. However, it's empty .. so vco is not getting it from vcac. It's getting everything else .. like vCACHost and all the params. This one it seems it can't get ..

banging my head ..

0 Kudos
qc4vmware
Virtuoso
Virtuoso
Jump to solution

At what stub are you calling out?  If the vCenter VM has not yet been created or has been removed then that value will be null.  Generally speaking the vCAC:VirtualMachine name will be the same so you should be able to use that.  Are you positive that the vCenter plugin is setup correctly?  Can you see the vCenter vm's in the inventory?  The vCenter plugin sometimes gets stale connections although the more recent builds of the plugin have (mostly) addressed that issue.

0 Kudos
stvkpln
Virtuoso
Virtuoso
Jump to solution

(Asking again...)  Are you running vCAC 6.1? If you are...Please follow the KB I posted earlier. You won't get an error under the conditions in that KB.  Starting with 6.1, the vmUniqueID value being collected is the InstanceUuid rather than the Uuid value stored with the VM, and without that fix, even with the 6.1 plugin, you're going to run into the issue with vCO being able to resolve the vCAC:VirtualMachine -> VC:VirtualMachine.

In fact, regardless of if you're running 6.1 or not, the included fix  (apply after updating to the 6.1 plugin, mind you) should probably be done either way. The way the code was updated for that, it is backwards compatible with > 6.1 IaaS instances.

-Steve
0 Kudos
AEsansun2
Enthusiast
Enthusiast
Jump to solution

I ran the "Assign a state change workflow to ab lueprint and it's virtual machine".

It puts in "ExternalWFStubs.BludingMachine" .

Yes, I am sure it's working - since it will build machines, run the workflows . However, the one particular workflow that needs the vm name is where the issue is.

0 Kudos
AEsansun2
Enthusiast
Enthusiast
Jump to solution

Yes, I am running 6.0.1.1 .

will be adding the update you recommended and get back to you. Thank you for your help.

0 Kudos
AEsansun2
Enthusiast
Enthusiast
Jump to solution

Unfortunately, the kb article says the package to download, without a link . Trying to find it now..

0 Kudos
AEsansun2
Enthusiast
Enthusiast
Jump to solution

can't seem to find the package. If anybody knows where i can find this..

com.vmware.vcac61_uuid_wf_patch.package


Please let me know. Many thanks !

0 Kudos
AEsansun2
Enthusiast
Enthusiast
Jump to solution

OK so in this code.

System.log("Workflow started from workflow stub " + externalWFStub + " on vCAC host " + vCACHost.displayName);

System.log("Got vCAC virtual machine " + vCACVm.virtualMachineName);

System.log("Matching virtual machine entity " + virtualMachineEntity.keyString);

System.log("Here is the  " + virtualMachineEntity.keyString);

if (vCenterVm != null) {

  System.log("Got vCloud VM " + vCenterVm.name);

}

I get nothing in vCenterVM. so how would i get now the name and uuid to input to the workflow (get vm by name .. ) ?

0 Kudos
stvkpln
Virtuoso
Virtuoso
Jump to solution

Just a quick thought, but.. what state is this workflow being called from?

-Steve
0 Kudos
qc4vmware
Virtuoso
Virtuoso
Jump to solution

Did you ever verify that the vCenter plugin is functioning correctly?  If it isn't the bug in the KB biting you then it might be an issue with that plugin or its configuration.  Also, this is the code from the "Workflow runner" workflow which is where the prep is happening during the stub call out:

System.log("vmUniqueID : " + vCACVm.vmUniqueID);

if (vCACVm.vmUniqueID != null) { // vmUniqueID may be null (i.e at BuildingMachine state)

  if (vCACVm.vmUniqueID.indexOf("vcloud") > -1) {

  System.log("Got vCloud Director VM ID");

  var vdcHosts = System.getModule("com.vmware.library.vcac").getEnabledHosts() ;

  for each (var vcdHost in vdcHosts) {

  var vCloudVApp = vcdHost.getEntityById(VclFinderType.VAPP, vCACVm.vmUniqueID);

  if (vCloudVApp != null) {

  break;

  }

  }

  }

  else {

  System.log("Trying to resolve a vCenter VM");

  var sdkConnections = VcPlugin.allSdkConnections;

  System.log(sdkConnections.length + " sdk Connections found...");

  for each (var sdkConnection in sdkConnections) {

  try {

  vCenterVm = sdkConnection.searchIndex.findByUuid(null, vCACVm.vmUniqueID, true, false);

  } catch(e) {System.log("Error for SDK connection " + sdkConnection.name + " : " + e);}

  if (vCenterVm != null) {

  System.log("Resolved vCenter VM " + vCenterVm.name);

  break;

  }

  }

  }

}

What do you see in your system logs?  That should also help shed a little light on things.  This code is from the 6.0.1.1 plugin so it may be different in the 6.1 plugin.  Anyway take a look at that workflow.  You can see it is looping through each of the vCenter connections you have in your plugin.  If the connection is not in a responsive state or the plugin is not setup correctly you will not get a hit.  Also, if timing wise the VM has not yet been created you won't get a hit.  You may need to move what you are trying to do to "machineProvisioned" or at some other point in your workflow look the vm up yourself.  Maybe put in an action that loops until the value of vCACVm.vmUniqueID returns something other than null then look the vm up yourself.

0 Kudos
stvkpln
Virtuoso
Virtuoso
Jump to solution

That was why I asked about what state this was being performed... if during BuildingMachine, then there is no VM object... it hasn't been created/cloned/whatever. Important piece of diagnostic data!

-Steve
DLally
Enthusiast
Enthusiast
Jump to solution

So are we supposed to use these new workflows like "Get VM by Name and BIOS UUID" similar to the workflow template?  Inputs should be populated when running workflows against a VM?

Just to be clear, i'm talking about machine provisioned and destroyed workflows.  My workflows fail now since I'm unable to find the vCenterVM anymore.

0 Kudos
AEsansun2
Enthusiast
Enthusiast
Jump to solution

BuildingMachine

0 Kudos
DLally
Enthusiast
Enthusiast
Jump to solution

Like others said, there will be no VC object to output during the building machine workflow

0 Kudos