Hi all,
Just trying to implement a UPS solution here and am getting a bit stuck.
Client has the following:
2x HP R/T3000 UPS with network cards. Both UPS attached to VCentre via USB also.
1x HP DL380 G7 (VCentre server, win 2008)
2x HP DL380 G7 (VSphere1 and VSphere2) - esxi version 4.1
HP P2000 array
Just wondering if there is a simple way to get the VMs to suspend in the event of an extended power failure, then have the hosts shut down?
When power returns, is it possible to have the hosts power back on, and the VMs then resume from suspended state?
I've installed VMA 4.1 but haven't gotten to the APCUPSD step, as it is not an APC ups. Also seems like a VERY convoluted process for what should be a simple task.
Can something like this be configured through HP SIM, or another tool?
Any help greatly appreciated ![]()
Welcome to the Forums
On each Hosts Configuration tab under "Edit Virtual Machine Startup/Shut Down Settings" You can control the VMs in behavior case of host shutdown or startup. In a cluster these settings will follow the VM.
However, if HA is enabled in this cluster, these settings are silently disabled. (Can configure but will be ignored)
So with a HA cluster you will need to write scripts to shutdown/suspend VMs before Host shutdown and also Startup/Resume VMs after host is back up.
HA will not startup/resume a VM that has been gracefully shut down or suspended
Please award points if you find this helpful/correct ![]()
Thanks for the reply ![]()
Is there a repository of scripts around here at all for doing this? Would this need to be done via vMA, or is there an easier way? Maybe via vSphere CLI client?
The way I have investigated so far is via apcupsd on vMA (using the great ghettoups script), but I doubt this solution would work for a HP UPS.
I just need some software that will receive an SNMP trap for low battery, and begin the shutdown/suspend process.
Currently I have Vcentre shutting down safely when the power goes out (via USB monitoring), but it doesn't know that it needs to power the hosts down as well.
That is good info regarding HA, would have tripped me up!
Cheers ![]()
Looks like HP Power Protector initiating a PowerCLI script might be the go, and avoids vMA:
http://www.virtu-al.net/2010/01/06/powercli-shutdown-your-virtual-infrastructure/
http://sigtar.com/2009/12/18/vma-using-hp-power-protector-agent-to-shutdown-virtual-hosts/
I'm a complete PowerShell/scripting n00b, is it just a matter of copy-pasting the code into notepad, saving it as a *.ps1 file, and telling HP Power Protector to run it if the power has been out for a certain amount of time?
Or does something need to be done to the script to make it executable or something?
At least the VCentre box is physical not a VM, which may help. Since it is a HA environment, I'm not sure if anything needs to be added to the script, eg adding both ESX hosts or something.
$VCENTER = "vcentre"
Connect-VIServer $VCENTER
# Get All the ESX Hosts
$ESXSRV = Get-VMHost
# For each of the VMs on the ESX hosts (excluding virtual center box)
Foreach ($VM in ($ESXSRV | Get-VM)){
# Shutdown the guest cleanly
if ($VM -match $VCENTER){}
else {$VM | Shutdown-VMGuest -Confirm:$false}
}
# Set the amount of time to wait before assuming the remaining powered on guests are stuck
$WaitTime = 120 #Seconds
do {
# Wait for the VMs to be Shutdown cleanly
sleep 1.0
$WaitTime = $WaitTime - 1
$numvms = ($ESXSRV | Get-VM | Where { $_.PowerState -eq "poweredOn" }).Count
Write "Waiting for shutdown of $numvms VMs or $WaitTime seconds"
} until ((@($ESXSRV | Get-VM | Where { $_.PowerState -eq "poweredOn" }).Count) -eq 0 -or $WaitTime -eq 0)
# Shutdown the ESX Hosts - and remaining virtual center box (if virtual)
$ESXSRV | Foreach {Get-View $_.ID} | Foreach {$_.ShutdownHost_Task($TRUE)}
Write-Host "Shutdown Complete"
# If virtual center box is physical and still alive it will need to be shutdown...
Write-Host "Shutting down virtual center"
shutdown -s -f -t 1
OK to help the other n00bs out there like me ![]()
Good article:
http://technet.microsoft.com/en-us/library/ee176949.aspx#EFAA
So steps are:
Launch PowerShell as an admin
Type in: Set-ExecutionPolicy RemoteSigned
Type Y (for yes) when prompted.
I then created 2 files using Notepad:
First file, saved to C:/scripts/powerdown.vbs and its contents, this will basically run the second script:
Set objShell = CreateObject("Wscript.Shell")
objShell.Run("powershell.exe -noexit c:\scripts\powerdown.ps1")
Second file, saved to C:\scripts\powerdown.ps1 and its contents:
echo "hello world"
I then pointed HP Power Protector at C:/scripts/powerdown.vbs
Once I get the PS1 script right I'll paste it into powerdown.ps1 ![]()
Discovered you need to have this first line added before PowerShell will know WTF you are doing ![]()
if (!(get-pssnapin -name VMware.VimAutomation.Core -erroraction silentlycontinue)) {add-pssnapin VMware.VimAutomation.Core}
$VCENTER = "vcentre"
Connect-VIServer $VCENTER
# Get All the ESX Hosts
$ESXSRV = Get-VMHost
# For each of the VMs on the ESX hosts (excluding virtual center box)
Foreach ($VM in ($ESXSRV | Get-VM)){
# Shutdown the guest cleanly
if ($VM -match $VCENTER){}
else {$VM | Shutdown-VMGuest -Confirm:$false}
}
# Set the amount of time to wait before assuming the remaining powered on guests are stuck
$WaitTime = 120 #Seconds
do {
# Wait for the VMs to be Shutdown cleanly
sleep 1.0
$WaitTime = $WaitTime - 1
$numvms = ($ESXSRV | Get-VM | Where { $_.PowerState -eq "poweredOn" }).Count
Write "Waiting for shutdown of $numvms VMs or $WaitTime seconds"
} until ((@($ESXSRV | Get-VM | Where { $_.PowerState -eq "poweredOn" }).Count) -eq 0 -or $WaitTime -eq 0)
# Shutdown the ESX Hosts - and remaining virtual center box (if virtual)
$ESXSRV | Foreach {Get-View $_.ID} | Foreach {$_.ShutdownHost_Task($TRUE)}
Write-Host "Shutdown Complete"
# If virtual center box is physical and still alive it will need to be shutdown...
Write-Host "Shutting down virtual center"
shutdown -s -f -t 1
I've done everything you mentioned but HPE Power Protector does not run the script. I've installed HPE Power Protector on a Windows VM on a ESXi Host. UPS is connected as expected and when I use the "Shutdown" shutdown type, the VM is immediately shutdown. But when I use the "Script" shutdown as you mentioned, nothing happens. When I press the "Test shutdown" button, a prompt is shown indicating "Test shutdown running" but nothing happens. I tried powershell, VBS and perl scripts but neither seems to be run. So far, I've used:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File C:\Scripts\myscript.ps1
and other variations of this. I've tried to pass the path for the VBS script as well. Not sure what exactly must be in "Shutdown script" field.
Any idea?
