OK, I could fix that with my trusty Powershell toolkit, and a scheduled task. But then I talked to the customer who went like: "Sure that's fine with me to script it, but make sure the sessions are drained from the webserver".. Hmm, F5 loadbalancers. I've not worked too much with those before, really. I get the general ideas within loadbalancing, but let's try and script against it.
So I had a number of things I wanted to happen:
- Log in to the F5 loadbalancer, preferably not with a script filled with credentials hardcoded into it.
- Wait an X amount of time for connections to drop from the specific pool
- Shut down the machine, and wait for it to be properly turned off.
- Set the number of CPU's and memory. This had an extra challenge, namely that the person who built the VM put in 1 vCPU with 3 cores, instead of 3 vCPU's.
- Send an email with the results, so I can see what happened from my phone.
I'll spend a few posts on those different things.
Firstly the vCPU upgrade, which is the basis of this entire story:
Normally, you can turn off a VM, upgrade vCPU's, then start a VM again, through this simple set of commands:
$VM=Get-VM -Name 'WEB01'
Stop-VMGuest –VM $VM –Confirm:$False
do {
$status = (get-VM $VM).PowerState
}until($status -eq "PoweredOff")
$VM | Set-VM -NumpCPU 4 –Confirm:$False | Start-VM
Fortunately there's another trick for that:
$VMSpec = New-Object -Type VMware.Vim.VirtualMachineConfigSpec -Property @{"NumCoresPerSocket" = 4;"numCPUs" = 4}
$VM.ExtensionData.ReconfigVM_Task($VMSpec)
Now the VM gets upgraded to 4 vCPU's, although you would think it'd be 4x4 cpu's looking at the syntax.
So now the final complete code would be:
Add-PSsnapin VMware.VimAutomation.Core
Connect-VIServer myVcenter -ErrorAction Stop
$VM=Get-VM -Name 'WEB01'
Stop-VMGuest –VM $VM –Confirm:$False
do {
$status = (get-VM $VM).PowerState
}until($status -eq "PoweredOff")
$VMSpec = New-Object -Type VMware.Vim.VirtualMachineConfigSpec -Property @{"NumCoresPerSocket" = 4;"numCPUs" = 4}
Start-VM $VM
Yeay, success! Now on to the next bit...
No comments:
Post a Comment