VMware Cloud Community
horse81
Contributor
Contributor

setting cpu reservation on a vm

Hi Folks,

In need to set cpu reservation for a vm ( see screenshot ). I coudn't find an action for that, so I'm trying to write one as follows:

var myVcVirtualMachineConfigSummary = new VcVirtualMachineConfigSummary() ;
myVcVirtualMachineConfigSummary.cpuReservation = reservation;
var task = vm.reconfigVM_Task( myVcVirtualMachineConfigSummary );
return task;

Unfortunatley this VcVirtualMachineConfigSummary is not compatible with this (VirtualMachineConfigSpec so i cannot use the  vm.reconfigVM_Task(). This is what i get:

[2012-03-23 17:33:56.057] [I] Cannot convert com.vmware.vim.vi4.VirtualMachineConfigSummary@8d6 to com.vmware.vim.vi4.VirtualMachineConfigSpec (Dynamic Script Module name : reconfigCpuReservation#2)

Can anyone help me with this?
Thanks
Tommaso
0 Kudos
4 Replies
tschoergez
Leadership
Leadership

ONYX (http://labs.vmware.com/flings/onyx) for rescue! :smileycool: It's not the ConfigSummary but a ConfigSpec you need...

var spec = new VcVirtualMachineConfigSpec();
spec.cpuAllocation = new VcResourceAllocationInfo();
spec.cpuAllocation.reservation = reservation; //second reservation is the value 😉

var task = vm.reconfigVM_Task(spec);  // VirtualMachine

return task;

Cheers,

Joerg

horse81
Contributor
Contributor

amazing! This tool is exacly what I needed!

Thank you!

0 Kudos
horse81
Contributor
Contributor

Using onyx i managed to set ram reservation, anyway I still have problems setting a limit for iops, this is the vco js

var spec = new VcVirtualMachineConfigSpec();
spec.changeVersion = "2012-03-27T09:05:39.090102Z";
spec.deviceChange = System.getModule("com.vmware.onyx").array(VcVirtualDeviceConfigSpec, 1);
spec.deviceChange[0] = new VcVirtualDeviceConfigSpec();
spec.deviceChange[0].operation = VcVirtualDeviceConfigSpecOperation.edit;
spec.deviceChange[0].device = new VcVirtualDisk();
spec.deviceChange[0].device.key = 2000;
spec.deviceChange[0].device.deviceInfo = new VcDescription();
spec.deviceChange[0].device.deviceInfo.label = "Hard disk 1";
spec.deviceChange[0].device.deviceInfo.summary = "8,388,608 KB";
spec.deviceChange[0].device.backing = new VcVirtualDiskFlatVer2BackingInfo();
spec.deviceChange[0].device.backing.fileName = "[Datastore] centos/centos.vmdk";
spec.deviceChange[0].device.backing.diskMode = "persistent";
spec.deviceChange[0].device.backing.split = false;
spec.deviceChange[0].device.backing.writeThrough = false;
spec.deviceChange[0].device.backing.thinProvisioned = true;
spec.deviceChange[0].device.backing.uuid = "6000C297-a5fb-16d7-deb9-f7fc47d5d31a";
spec.deviceChange[0].device.backing.contentId = "f27d0cd5e14f73e655cc113d89b81562";
spec.deviceChange[0].device.backing.digestEnabled = false;
spec.deviceChange[0].device.controllerKey = 1000;
spec.deviceChange[0].device.unitNumber = 0;
spec.deviceChange[0].device.capacityInKB = 8388608;
spec.deviceChange[0].device.shares = new VcSharesInfo();
spec.deviceChange[0].device.shares.shares = 1000;
spec.deviceChange[0].device.shares.level = VcSharesLevel.normal;
spec.deviceChange[0].device.storageIOAllocation = new VcStorageIOAllocationInfo();
spec.deviceChange[0].device.storageIOAllocation.limit = 1502;
spec.deviceChange[0].device.storageIOAllocation.shares = new VcSharesInfo();
spec.deviceChange[0].device.storageIOAllocation.shares.shares = 1000;
spec.deviceChange[0].device.storageIOAllocation.shares.level = VcSharesLevel.normal;
spec.cpuAffinity = new VcVirtualMachineAffinityInfo();
spec.memoryAffinity = new VcVirtualMachineAffinityInfo();
managedObject.reconfigVM_Task(spec);  // VirtualMachine

Now let's say I want to do this dinamically, how can I asiign all the attributes for the deviceChange[0].device array? Apparently if you don't assign most of them ( backing and device info ) the storageIOAllocation.limit fails.

Thanks

0 Kudos
tschoergez
Leadership
Leadership

Hi!

1. Delete the line spec.changeVersion = ....., otherwise you will get an error later (each change to a VM has to be unique, so the Client creates this identifier; no need for it in vCO)

2. More challenging: You have to get the current values from the current configuration of the VM. So you have to "crawl" through the hardware-devices of the VM, figure out the Disk you want to change the IO-Limit and "copy" the values  to your spec.

See the vSphere API Reference Guide for further information, expecially which parameters of the Spec are optional...

The Managed Object Browser (http://your-vc-server.tld/mob ) also is very helpful for that, to figure out how to accees the hardware-devices (from mind, I think it's vm.config.hardware....something)

Cheers,

Joerg

0 Kudos