VMware Cloud Community
dmented
Enthusiast
Enthusiast

Starting out with vCO: unable to return list of VMs with VcPlugin.getAllVirtualMachines()

Hi,

I'm following this blog to get my feet wet with vCO but it doesnt seem to return the list of all VMs:

Blog:

Automatically Securing Virtual Machines Using vCenter Orchestrator | VMware vSphere Blog - VMware Bl...

What I'm using: vCO Appliance 5.5 with vCenter 5.5/ESXi 5.5

Whats happening?

From the policy log, SNMP traps are being received just fine but the VM cannot be located from the inventory. I tried editing the policy to return the number of items in the array that is received from VcPlugin.getAllVirtualMachines() and it's returning as 0.

Not sure what else to do. Do i need to manually connect to vCenter from within the script? From the example in the blog, he just did straight apply / run policy so not sure what gives.

Thanks.

0 Kudos
5 Replies
dmented
Enthusiast
Enthusiast

i have this (from the video tutorial):

var allVms = VcPlugin.getAllVirtualMachines();
var ret = null;
System.log("Count " + allVms.length);

but its returning as Count: 0

0 Kudos
tschoergez
Leadership
Leadership

Can you see the vms when you browse through the inventory manually in the vco client?

Gesendet von meinem LG Mobile

0 Kudos
dmented
Enthusiast
Enthusiast

Hello tschoergez

Yes, I can see the VM's fine when I browse from within the vCO Client (Administer -> vCenter Server)

0 Kudos
dmented
Enthusiast
Enthusiast

Here's the script snippet, it returns null

function findVM(vmname) {

  var allVms = VcPlugin.getAllVirtualMachines();

  var ret = null;

  System.log("Count " + allVms.length);

  for (var i in allVms) {

  System.log("VM is " + allVms[i].name);

  if (allVms[i].name.match(vmname)) {

  ret = allVms[i];

  break;

  }

  }

  return ret;

}

0 Kudos
dmented
Enthusiast
Enthusiast

ok. i think i'm going somewhere, it now returned values BUT the new VM created is not on the inventory.

so whats happening from what I can see is: VM is Created -> VcPlugin.getAllVirtualMachines() -> it doesnt return the VM because it cannot see it.

Is there a way i can refresh inventory during run time?

0 Kudos