VMware Cloud Community
mcfadyenj
Hot Shot
Hot Shot
Jump to solution

VcVirtualMachine types

I am trying to convert a textual name into a VcVirtualMachine type

I have tried a number of ways the only one that is close to working is using getAllVmsFromResourcePool (not sure if exact syntax I am at home no vco here)

anyway this returns an array of VcVirtualMachine types. I found a property "isTemplate" which looks like what I need, is the isTemplate supposed to be part of the VirtualMachine type? The api doco is a little confusing, I read it like it should be a direct property of that object, using it causes a failure in the code due to invalid property.

I have also tried VcPlugin.getAllVms which returns an empty array. Hence why I chose vm from resourcepool

The code looks something like this

var array = new Array();

array = getModule("com.vmware.xxxx").getAllVmsFromResourcePool(VcResourcePool type)

for (i in array)

{

     var vm = array[i];

    System.log (vm.name)    // this suceeds with vm name

    System.log (vm.isTemplate) // this fails with invalid property.

  

    if (vm.name == inputString)

     {

               if (vm.isTemplate) {return vm}

     }

}

Reply
0 Kudos
1 Solution

Accepted Solutions
cdecanini_
VMware Employee
VMware Employee
Jump to solution

If I recall well to check if a vm is a Template you can check:

vm.summary.config.template

Christophe.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter

View solution in original post

Reply
0 Kudos
4 Replies
cdecanini_
VMware Employee
VMware Employee
Jump to solution

If I recall well to check if a vm is a Template you can check:

vm.summary.config.template

Christophe.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
Reply
0 Kudos
tschoergez
Leadership
Leadership
Jump to solution

Hi!

For the VcPlugin.getAllVms you need at-least read-only-permissions on the topmost level in vCenter I think.

If that works, you could also use the xpath-filter for getAllVms, like dicussed here

http://communities.vmware.com/message/1673575?tstart=0

For your use-case:

var result = VcPlugin.getAllVirtualMachines(null ,"xpath:config/template[starts-with(.,'true')]");

Might be a more scalable way than to have a large array with all VMs (if you have hundrets of VMs...).

Regards,

Joerg

mcfadyenj
Hot Shot
Hot Shot
Jump to solution

As it turns out the isTemplate can be determined from a decision action type.

So to use this pass the vm object into the decision action, select isTemplate. I think I am trying to loop through too much in code when I should actually be using more workflow objects to handle my loops etc.

I am a little confused as to why properties are exposed only through decision objects as opposed to code level.

I will mess around with these xml filters to see what I can get to work.

Reply
0 Kudos
cdecanini_
VMware Employee
VMware Employee
Jump to solution

The isTemplate is a property of the VirtualMachine finder and not its scripting object.

These are the properties that show up when you click on an object in the UI and that are usually useful to choose between the different objects (i.e Datastore free space). I think that you can access these programmatically through the the presentation properties and that technically vCO does not have to fetch the full scripting object.

Christophe.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter