VMware Cloud Community
esarakaitis
Enthusiast
Enthusiast

using onyx code in vCO

So I've written a scriptable task

var vms = new Array();
getVMsOfPool(cluster.resourcePool);
function getVMsOfPool(pool) {
    vms = vms.concat(pool.vm);
    var pools = pool.resourcePool;
    if (pools != null) {
        for (index in pools) {
            if (pools[index] != null)
                getVMsOfPool(pools[index]);
        }
    }
}
System.log(vms)
for (i=0; i<vms.length; i++) {
var spec = System.getModule("com.vmware.onyx").array(VcResourceConfigSpec, 1);
spec[0] = new VcResourceConfigSpec();
spec[0].entity = Server.findForType("VC:VirtualMachine", vms[i].vimHost.id + vms[i]);;
spec[0].cpuAllocation = new VcResourceAllocationInfo();
spec[0].memoryAllocation = new VcResourceAllocationInfo();
spec[0].memoryAllocation.limit = -1;

vms[$i].updateChildResourceConfiguration(spec);  // ResourcePool
}

and the error i get is: Property or method ‘entity’ not found on object

VcResourceConfigSpec

I do have a cluster input of VC Compute cluster type... Do I need to load anything for the onxy code?

0 Kudos
2 Replies
Burke-
VMware Employee
VMware Employee

Eric, I'm unsure of how/why that is not working because that object does appear to have an entity property when reviewing in the API explorer. Hopefully someone from Engineering can provide a response. Until then, I would try something a little more like this:

var vms = new Array();

getVMsOfPool(cluster.resourcePool);
function getVMsOfPool(pool) {
vms = vms.concat(pool.vm);
var pools = pool.resourcePool;
if (pools != null) {
for (index in pools) {
if (pools[index] != null)
getVMsOfPool(pools[index]);
}
}
}

System.log(vms);

for (i=0; i<vms.length; i++) {
try{
var spec = new VcVirtualMachineConfigSpec();
spec.cpuAllocation = new VcResourceAllocationInfo();
spec.memoryAllocation = new VcResourceAllocationInfo();
spec.memoryAllocation.limit = -1;
}
catch(ex){
throw "Unable to create VcVirtualMachineConfigSpec: "+ex;
}
// Try to reconfig the vm now:
if(spec instanceof VcVirtualMachineConfigSpec){
task = vms[$i].reconfigVM_Task(spec);
//System.log("Spec: "+spec);
}
}

With the code above, you would set an out parameter for your scriptable task for a "task"object which you would then pass to a "vim3WaitTaskEnd" action.

I hope this helps you along Smiley Happy

Visit me at for vCenter Orchestrator tips and tutorials Smiley Happy

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
esarakaitis
Enthusiast
Enthusiast

nice, that works well!

now if i could just figure out the code above Smiley Happy

0 Kudos