Vidal30
Contributor
Contributor

Shutdown VM from VRA with VCO Workflow

Jump to solution

Hi,

I'm a beginner at VCO and I need some help with basic Workflow.

I tried to create a new WF -  receive a vCAC:VirtualMachine for a user and then Shutdown the machine.

For starters, I created WF and added scriptable task that print Input System.log(vCAC:VirtualMachine);

and now I don't know how to continue... In VCO doesn't has  action to Shutdown vCAC:VirtualMachine .

Thanks.

1 Solution

Accepted Solutions
poorem
Enthusiast
Enthusiast

I'm not 100% sure when it was added, but there is an action in 7.x that will help called com.vmware.vcac.asd/findVcVmByUuid. Ive included it in the attached package, if you don't already have it then you can import it. It wasn't present on my vRO 6.0.2 system but should work ok in 6.x. (I don't currently have 6.0.5 and vRA 6.2.3 running in my lab to check it with.)

To use the action, a simple bit of javascript in a scriptable task in vRO can be used:

var vraVmId = vcacVm.vmUniqueID;

System.log(vraVmId);

vcVm = System.getModule("com.vmware.vcac.asd").findVcVmByUuid(vraVmId);

Obviously, vcacVm is the VCAC:VirtualMachine and vcVm is the VC:VirtualMachine, like this:

201709249_110914-CapturFiles.png

You can then call vcVm.shutdownGuest() to shutdown the VM.

View solution in original post

7 Replies
poorem
Enthusiast
Enthusiast

Just stepping back a minute. Can you clarify exactly what you're trying to achieve? The title of this post suggests to me that you want to shutdown a VM from within vRA as a day 2 operation. There is a built-in action for that already, it just needs to be entitled,

In vRO (vCO) though, you'd need to "translate" the VCAC:VirtualMachine object to a VC:VirtualMachine object and then you could call the shutdown task on that. Happy to help you with that, but let's just make sure first that you're not doing it needlessly.

0 Kudos
Vidal30
Contributor
Contributor

Thanks for the quick answer.

The second paragraph is exactly what I need, Sorry but I don't know how to do it.

0 Kudos
poorem
Enthusiast
Enthusiast

For some reason my reply yesterday didn't post.

Can you confirm what versions of vRA / vRO you're working with please.

0 Kudos
Vidal30
Contributor
Contributor

Yes. VRA 6.2.3 & VRO 6.0.5

0 Kudos
poorem
Enthusiast
Enthusiast

I'm not 100% sure when it was added, but there is an action in 7.x that will help called com.vmware.vcac.asd/findVcVmByUuid. Ive included it in the attached package, if you don't already have it then you can import it. It wasn't present on my vRO 6.0.2 system but should work ok in 6.x. (I don't currently have 6.0.5 and vRA 6.2.3 running in my lab to check it with.)

To use the action, a simple bit of javascript in a scriptable task in vRO can be used:

var vraVmId = vcacVm.vmUniqueID;

System.log(vraVmId);

vcVm = System.getModule("com.vmware.vcac.asd").findVcVmByUuid(vraVmId);

Obviously, vcacVm is the VCAC:VirtualMachine and vcVm is the VC:VirtualMachine, like this:

201709249_110914-CapturFiles.png

You can then call vcVm.shutdownGuest() to shutdown the VM.

iiliev
VMware Employee
VMware Employee

Just to add to the previous post:

1) VM IDs are not guaranteed to be absolutely unique in all cases; for example, if you have multiple vCenter servers in your environment, it is possible to have duplicates on different vCenters. Here is a blog post that provides an excellent overview of different IDs in vSphere environment - http://www.virtu-al.net/2015/12/04/a-quick-reference-of-vsphere-ids/

If you know exactly which vCenter is managing the VM you want to shutdown, then instead of findVcVmByUuid you can use the similar action findVcVmByVcAndVmUuid, which in addition to VM UUID allows you to specify also vCenter UUID. This will provide an unique identification of your VM.

2) Instead of converting vCac VM to VC VM, there is an option to use some scripting code to invoke day-2 operation directly on vCac VM to shutdown/power off it. I don't have a code at hand, but it is likely to be more complex than the code to convert to VC VM.

poorem
Enthusiast
Enthusiast

Good point, thanks.

0 Kudos