VMware Cloud Community
0j3r3my0
Contributor
Contributor
Jump to solution

APC PowerChute on VMware ESXi 4

Hi!

We've a problem with the ESXi 4 during the test with our APC SUA-2200 UPS. We have only 1 ESXi server. The vMA doesn't want to shut the ESXi down when receive the shutdown signal, so when the UPS battery. So when the battery dies the machine just powers off without graceful shutdown of the VMs. The UPS has an installed network management card. We deployed a vMA to our ESXi and installed the APC's PowerChute Software (PCNS). So the status is the following:

1. The network management in the UPS card is working correctly (we can access the webUI from any computer)

2. The vMA has a correct Powerchute software. We opened all require ports with the iptables. So we can reach the PowerChute's webUI.

3. We configured the ESXi with the vSphere to automaticaly startup/shutdown with the system. If we reboots the ESXi with the vShere the system shuts the Virtual Machines down correctly.

4. The PowerChute can communicate with the UPS Network card correctly. And the vMA receives the shutdown signal correctly. But the vMA only shuts down itself and leaves the ESXi on, that is our problem.

How can we force the vMA to shutdown our ESXi?

Have you experienced a problem like this before with the PowerChute, or do you have any idea what causes this error?

Thank you for your help!

Regards,

Robert

<!Session data>

Tags (2)
Reply
0 Kudos
59 Replies
0j3r3my0
Contributor
Contributor
Jump to solution

That is not good Smiley Sad I haven't seen anything about this. Is this restriction also available on ESXi 4.0? Could you give me a command which I can test this write protection on our (free licensed) server?

Thank you!

Reply
0 Kudos
fixitchris
Hot Shot
Hot Shot
Jump to solution

This read-only change took effect with ESXi 3.5 U4, so ESXi 4 is affected.

1. Install PowerShell on a laptop

2. Install PowerCLI on the laptop: http://communities.vmware.com/community/vmtn/vsphere/automationtools/windows_toolkit?view=overview

3. Open PowerCLI or get PowerGUI to run your scripts

## run these two lines if you're running your script from PowerGUI
$VMCore = Get-PSSnapin VMware.VimAutomation.Core -EA 0
if ( -not $VMCore ) { Add-PSSnapin VMware.VimAutomation.Core };

Connect-VIServer -Server xxx.xxx.xxx.xxx -User username -Password myPassword;

if ( $DefaultVIServer -eq $null) 
	{ Write-Host "Connection Failed!"; return $false }
else
	{ Write-Host "Connected : " $DefaultVIServer.IsConnected;
		## Lets assign some views to variables
		$global:moServiceInstance = (get-view ServiceInstance);
		$global:moHostSystem = Get-View -VIObject (Get-VMHost);
		$global:DefaultVIServer = $DefaultVIServer;
	};

## This is a write op, setting the VM start policies; should fail
Get-VMHostStartPolicy -VMHost (Get-VMHost -Server $DefaultVIServer) | Set-VMHostStartPolicy -Enabled $true -WaitForHeartbeat $true -StopDelay 120 -StopAction "GuestShutDown";

## this is a write op too, shut down a vm
Stop-VM "myVM";

## another write op, shut down the entire HOST
$global:moHostSystem.ShutdownHost_Task($true);

Disconnect-VIServer -Server $DefaultVIServer -Confirm:$false -EA 0;

Ref: http://www.vmware.com/support/developer/windowstoolkit/wintk40u1/html/index.html

Reply
0 Kudos
fixitchris
Hot Shot
Hot Shot
Jump to solution

Another possible solution is to use VMRUN included in VIX API. Once the battery is dying the PCNS would run a batch file.

vmrun.exe -h https://192.168.1.1:443/sdk -T esx -u username -p password stop "|datastore1| myvm/myvm.vmx" soft
vmrun.exe -h https://192.168.1.1:443/sdk -T esx -u username -p password stop "|datastore1| myvm2/myvm2.vmx" soft

You also might be able to shutdown the host via SSH, but I'm not sure.

Reply
0 Kudos
admin
Immortal
Immortal
Jump to solution

> ## another write op, shut down the entire HOST
> $global:moHostSystem.ShutdownHost_Task($true);
> 

Don't mean to threadjack but we have a Stop-VMHost in PowerCLI as of U1. A lot more readable than the ShudownHost_Task stuff.

Back to the topic, ESX 3.5 and 4.0 are locked down, even the vmrun command above. Might be possible to enable SSH and shut down via sshing in and running a shutdown command within the ESXi console.

=====

Carter Shanklin

Read the PowerCLI Blog
[Follow me on Twitter|http://twitter.com/cshanklin]

Reply
0 Kudos
J1mbo
Virtuoso
Virtuoso
Jump to solution

I have just tested a solution to this problem - will be posting a blog about it in the next couple of days!

And it works with free licensed ESXi Smiley Happy

Reply
0 Kudos
0j3r3my0
Contributor
Contributor
Jump to solution

Super! It would be great! Thank you! :smileygrin: &lt;!Session data&gt;<!Session data>

Reply
0 Kudos
DSTAVERT
Immortal
Immortal
Jump to solution

The two scripts posted earlier do work.

-- David -- VMware Communities Moderator
Reply
0 Kudos
J1mbo
Virtuoso
Virtuoso
Jump to solution

Hi DSTAVERT - which two scripts do you mean? As from everything I have read, free-licensed (specifically) ESXi is locked down for this kind of thing since 3.5U3,

ESX 3.5 and 4.0 are locked down, even the vmrun command above

Reply
0 Kudos
DSTAVERT
Immortal
Immortal
Jump to solution

This one does work on 3.5 and 4 although it requires SSH enabled. I forgot that lamw's script was perl and required a licensed version.

-- David -- VMware Communities Moderator
Reply
0 Kudos
J1mbo
Virtuoso
Virtuoso
Jump to solution

OK that's good to know.

Here's what I've been working on - this doesn't need SSH and will work from Windows:

http://www.techhead.co.uk/how-to-automatically-shut-down-vmware-esxi-gracefully-during-power-failure...

Please award points to any useful answer.

Reply
0 Kudos
fixitchris
Hot Shot
Hot Shot
Jump to solution

Very clever approach!

Reply
0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

Very interesting indeed, it sounds like this can even be re-integrated with my ghettoShutdown.pl script and instead of relying on the APIs, do exactly what's been discovered by sending this soap call to shutdown the host.

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Comuunity

If you find this information useful, please award points for "correct" or "helpful".

Reply
0 Kudos
DSTAVERT
Immortal
Immortal
Jump to solution

Superb job. Someone at APC should be watching you.

-- David -- VMware Communities Moderator
Reply
0 Kudos
J1mbo
Virtuoso
Virtuoso
Jump to solution

Thanks for the positive feedback on this Smiley Happy

Re APC - it occured to me this morning, it would be very simple for the APC management card itself to fire off the shutdown command when needed, completely bypassing the need for installed agents or any work on the part of vmware. I wonder how easy it is to reverse engineer the management card firmware!?

Please award points to any useful answer.

Reply
0 Kudos
fixitchris
Hot Shot
Hot Shot
Jump to solution

Now I'm interested in the messages to shutdown the guests 😛

Reply
0 Kudos
fixitchris
Hot Shot
Hot Shot
Jump to solution

here's your new avatar jimbo:

Reply
0 Kudos
J1mbo
Virtuoso
Virtuoso
Jump to solution

Lol...Thanks!

That I can help you with, because I used suspend etc to develop it. Would have been a bit time consuming waiting for the host to power cycle each time.

Burp is your friend - everything in the client is just this soap stuff, which incidentally I know nothing about. I figured for the shutdown, a dos script would be fine but can immediately see there is great potential to develop a kind of "esxi command line" using these captures, that would be if I knew anything about programming (my skills on which ended at Turbo Pascal for DOS in 1994).

Here for example is a suspend request:

This is why it's going to be hard to script this, as we need to pick up the VM GUIDs (and friendly names) before hand to pick. In a DOS script that will be horrid, it was bad enough checking for connectivity and working out the length of the username and password! That said I suppose it is doable, I might give it a whirl later.

Cheers

Reply
0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

Is the serverGuid basically the moref ID for the VM via the APIs? If so, then it's a piece of cake to extract via the vSphere API (remember the APIs are full read access, just can't perform any write operation)

It sounds like we're just constructing the SOAP messages to send to ESX(i), so long as its constructed correctly with the right credentials, all of this is pretty simple .. if I understand what you're doing, though you're right, wouldn't recommend doing this in windows .bat file (probably PowerCLI or Perl) would be a better fit

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Comuunity

If you find this information useful, please award points for "correct" or "helpful".

Reply
0 Kudos
fixitchris
Hot Shot
Hot Shot
Jump to solution

I started exploring and it would be fairly simple to construct various XML requests:

https://192.168.1.1/mob/?moid=ha-sessionmgr

https://192.168.1.1/mob/?moid=ha-host

for above suspend example: https://192.168.1.1/mob/?moid=400

https://192.168.1.1/sdk/vim.wsdl

Reply
0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

Yep, I already got some working samples already Smiley Wink

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Comuunity

If you find this information useful, please award points for "correct" or "helpful".

Reply
0 Kudos