_MikeW_
Enthusiast
Enthusiast

Event Broker to trigger when MachineProvisioned and move to VM Folder

Jump to solution

I'm still really new to vRA/vRO and trying to wrap my head around some of the concepts. To that end I've been trying to make a simple event that will move a VM to a specific folder after provisioning for the VM takes place.

I've setup the event with the proper conditions and receive the "payload" of "Extensibility.Lifecycle.Properties.VMPSMasterWorkflow32.MachineProvisioned.*". I've logged those values to see what they were.

My problem now is trying to move the VM using those properties. I can't seem to find a "getVirtualMachine()" method that will take the "machine.id" property so that I can apply it to the Move virtual machine workflow (one that comes with vRO).

I've been digging around trying to figure out if I can pass that data directly to the event but finding the variables to expose seems to be ... difficult.

Can someone suggest a process that will allow me to follow this through to the end? If I can find a way to hand off the VCVirtualMachine  value to the workflow that would be easiest but if I could also find a method to get that using the machine.id from the payload properties that also would allow me to do it.

1 Solution

Accepted Solutions
_MikeW_
Enthusiast
Enthusiast

So I spent sometime over the weekend working on this and tried to use some of the examples provided but it just wasn't coming together. I did figure out how to get it to work and here are the specifics.

Blueprint, I set a custom property option: "VMware.VirtualCenter.Folder". This I don't think was necessary.

Event-Broker/Subscription. I created an event with conditions on a virtual machine build, waitingtobuild and "pre".

For the workflow I created a attribute "vmFolder". I could probably just use an input. Set to type string and the value to "Provisioned".

Inputs added, "payload" of type properties.

Output added "virtualMachineAddOrUpdateProperties".

The schema was a "scritable task" with input of vmFolder and payload. Output was configured for virtualMachineAddOrUpdateProperties.

Lastly the little scripting required was...

if (payload) {

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

    var virtualMachineAddOrUpdateProperties = new Properties();

    virtualMachineAddOrUpdateProperties.put("VMware.VirtualCenter.Folder",vmFolder);

    System.log("Set vmFolder to :" + vmFolder + " for host "+ machine.name + " with ID: "+machine.id);

} else {

    System.log("Payload was null.");

}

Once I ran the build the host was created in the "Provisioned" folder as desired. Follow ups will be to make the vmFolder created based on the business prefix host id (if I can find it) and perhaps the machine type (linux/etc).

View solution in original post

10 Replies
daphnissov
Immortal
Immortal

There's a much easier way to go about this that doesn't involve moving VMs around Smiley Happy

Sovereign Systems - vRA and The Problem of the vCenter Folder

qc4vmware
Virtuoso
Virtuoso

I'd suggest accomplishing this by setting the vm property for VMware.VirtualCenter.Folder much earlier on in the cycle.  MachineRequested during the PRE phase should work I'd think.

_MikeW_
Enthusiast
Enthusiast

These are both good suggestions and I will try and figure out the "this is a better method" when I've more experience. Right now this is mostly proof of concept for our group and to determine how things work. Even if I used the .Requested event I am still unsure how to retrieve the required variables to pass to the workflow for moving.

I'll keep looking and see if I can find an example for this type of event.

0 Kudos
daphnissov
Immortal
Immortal

I'm not sure you're quite understanding. By setting the custom property VMware.VirtualCenter.Folder, there is no vRO work and no moving of VMs required in any fashion. Try it out yourself. Set this custom property at either the blueprint level or the machine level and give it a value. When the machine is built, if that folder doesn't exist first, you'll see the service account creating the folder followed by the VM getting created in said folder. Again, there's no work in vRO required for that. Where there would be vRO work is if you're trying to determine the value of that custom property based upon other inputs or conditions. And for that, you can either take the hard road (in which custom vRO coding/manipulation would be required) or take the easy road by using SovLabs Property Toolkit (which is why I gave you the link to my blog article). The choice is up to you, but the main points being, once again:

  1. There is no "moving" around of VMs to land them into the desired folder.
  2. The custom property VMware.VirtualCenter.Folder is what determines the folder location, and this happens automatically once the value is set.
_MikeW_
Enthusiast
Enthusiast

I believe I understand the part of setting the .Folder. My problem is I don't know how to get/set that value while in the event-broker called workflow to do it (PRE or POST) period Smiley Wink All I have acess is the payload properties which I can't figure out how to reference down to VMware.*

Is this one of the properties I can add into the blueprint and then expose TO the event-broker?

Is there a list of all these properties (going back to my first post) where this stuff is documented?

0 Kudos
daphnissov
Immortal
Immortal

What exactly are you trying to do here? I think that would help to explain in detail. Because of you're new to vRA, you may be going about whatever this is in a roundabout way.

0 Kudos
_MikeW_
Enthusiast
Enthusiast

The goal is a simple how-to do this sorta thing (event-broker) to manage tasks we're going to need to have a handle on. To figure out that process I thought simply putting the VM in a specific VMfolder on creation would be a good learning experience.

I did find this which seems to have what I was looking for, custom-properties reference doc.

https://docs.vmware.com/en/vRealize-Automation/7.3/vrealize-automation-73-custom-properties.pdf​.

I wasn't aware of the VMware.VirtualCenter.* custom properties. I should be able to expose that to the event-broker workflow and change it to what I'd like (for now just a simple set value) and the VM be placed there.

I'm still a bit confused but I'll experiment with this and see what I can come up with.

Apologies for the probably dumb questions Smiley Wink

0 Kudos
qc4vmware
Virtuoso
Virtuoso

I'm uploading a sample of an event broker template.  In the first scriptable task it unfolds a bunch of what is in the payload and also retrieves the vCenter vm (which you'd need to pass into the workflow you are trying to call).  There is also a step in that workflow that shows setting that property value.  Hopefully this will be enough to get you pointed in the right direction.  Good luck!

0 Kudos
_MikeW_
Enthusiast
Enthusiast

So I spent sometime over the weekend working on this and tried to use some of the examples provided but it just wasn't coming together. I did figure out how to get it to work and here are the specifics.

Blueprint, I set a custom property option: "VMware.VirtualCenter.Folder". This I don't think was necessary.

Event-Broker/Subscription. I created an event with conditions on a virtual machine build, waitingtobuild and "pre".

For the workflow I created a attribute "vmFolder". I could probably just use an input. Set to type string and the value to "Provisioned".

Inputs added, "payload" of type properties.

Output added "virtualMachineAddOrUpdateProperties".

The schema was a "scritable task" with input of vmFolder and payload. Output was configured for virtualMachineAddOrUpdateProperties.

Lastly the little scripting required was...

if (payload) {

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

    var virtualMachineAddOrUpdateProperties = new Properties();

    virtualMachineAddOrUpdateProperties.put("VMware.VirtualCenter.Folder",vmFolder);

    System.log("Set vmFolder to :" + vmFolder + " for host "+ machine.name + " with ID: "+machine.id);

} else {

    System.log("Payload was null.");

}

Once I ran the build the host was created in the "Provisioned" folder as desired. Follow ups will be to make the vmFolder created based on the business prefix host id (if I can find it) and perhaps the machine type (linux/etc).

View solution in original post

qc4vmware
Virtuoso
Virtuoso

Please mark any of our replies as helpful please if they did indeed help and/or mark one as correct.

Thanks!

0 Kudos