VMware Cloud Community
UofS
Enthusiast
Enthusiast

findAllforType filter?

I am using the Server.findAllForType("vCloud:VM") function and able to return all VMs but its not exactly what I need.

I was hoping there was a more efficient way to get the vm object for a single VM based on one of the parameters of the VM (the artificialId field).

maybe something like this:

Server.findAllForType("vCloud:VM:artificalid=sfw@System@https://cloud.example.com/api/Vapp/vm-234234-234-23423-423-4234-23") ?

or based on href url?

otherwise I end up having to loop through and search this all the time and likely place unecessary stress on the system.

Dion

0 Kudos
2 Replies
Burke-
VMware Employee
VMware Employee

Try using xpath as discussed here:

http://communities.vmware.com/message/1892584#1892591

instead of name, use artificialId -- see if that works Smiley Wink I haven't tried but think this may be the way to go..

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 vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos
UofS
Enthusiast
Enthusiast

It doesnt seem to work as well as I would expect.  I have tried variations like this:

var vms = Server.findAllForType("vCloud:VM","xpath:name='VM-RHEL6'");

And get no items returned (and I know there are many VMs returned with the name= to this)

I also tried the variations we discussed:

var vmName = 'sfw@System@https://cloud.boo.ca/api/vApp/vm-6e4e0da2-524b-44fd-9dc4-343706eb7ff9';
var vms = Server.findAllForType("VC:VirtualMachine","xpath:artificialId='"+vmName+"'");

which also didnt return anything.

I also tried

var vmName = 'https://cloud.boo.ca/api/vApp/vm-6e4e0da2-524b-44fd-9dc4-343706eb7ff9';
var vms = Server.findAllForType("VC:VirtualMachine","xpath:href='"+vmName+"'");

also no good.

the href and artificialId were all properties available when I did

var vms = Server.findAllForType("vCloud:VM");

for each (var vm in vms) {

    for(var propertyName in vm) {
        try {
            System.log(  " vm var: " + propertyName + " = " + vm[propertyName] );
        } catch( e ) {

        }

    } 

Dion

0 Kudos