2 Comments Setting a standard resource reservation across your VI - 03/2/09
Me, I’m a big fan of standards. Standard processes, standard this, standard that – standards are a great way to make your life easier when dealing with hundreds or thousands of objects.
Inside of my Virtual Infrastructure, I’m a huge fan of ignoring the micro level of things, and paying attention to things at a macro level. One of the ways I do that, is by ensuring that every virtual machine is configured with identical reservations – regardless of how much resources they are allocated. If a given virtual machine (or group of virtual machines) requires a guaranteed amount of resources, I create a resource pool and toss them in there.
Not only does this prevent a “rouge” VM from stealing resources it may not need at a moment in time, it calls out the big hitters and puts them out in the open.
Our virtual machine creation process defines all new virtual machines with our standard reservation, but over the course of weeks and months, these drift. Machines change, an admin “tests” something and forget’s to change it back, or we might even change the standard. Here is a script that will locate all virtual machines in your infratructure, and update them to whatever makes you happy.
add-pssnapin VMware.VimAutomation.Core -erroraction Silentlycontinue
$vcServer=”virtualcenter”
$credentials = get-credential
$vcConnection=connect-viserver -server $vcServer -credential $credentials
$vms=get-view -viewtype VirtualMachine -server $vcConnection$vms | % {$spec = new-object VMware.Vim.VirtualMachineConfigSpec;
$spec.memoryAllocation = New-Object VMware.Vim.ResourceAllocationInfo;
$spec.memoryAllocation.Shares = New-Object VMware.Vim.SharesInfo;
$spec.memoryAllocation.Shares.Level = “normal”;
$spec.memoryAllocation.Limit = -1;
$spec.memoryAllocation.Reservation = 512;
$spec.cpuAllocation = New-Object VMware.Vim.ResourceAllocationInfo;
$spec.cpuAllocation.reservation = 0
$spec.cpuallocation.Shares = New-Object VMware.Vim.SharesInfo;
$spec.cpuAllocation.Shares.Level = “normal”;
$spec.cpuAllocation.Limit= -1;
Get-View($_.ReconfigVM_Task($spec))}
For dumb people like me your code does not make sense as I don
Vikash – all you need to do with this code is past it into a text file and save it as a ps1 – and edit a few places to make it connect to the right server, and update things to the right value.
In this script the pertinent lines are the $vcServer, shared.level, .limit, and .reservation.
Will see if I can toss some more scripts out at some point.