vMA – Using HP Power Protector agent to shutdown virtual hosts

Goal was to create a vMA which would send a shutdown signal to all the virtual hosts it knows about. I’ve assumed that ESX and management agents that live within the service console will eventually be phased out.

The steps…

  1. Download and install the vMA from vmware – fire up the vm and setup the basic networking required
  2. Create trusts within the vMA to each of the vmware hosts you wish to manage (sudo vifp addserver <server>)
  3. Install HP Power Protector (linux agent) – you could substitute for your UPS client software
  4. Modify the shutdown script (may differ per vendor) to shutdown the esxboxs- “SDScript” (hostops.pl)

The 1st step is easy enough. Find the download at vmware and install (Deploy OVF Template…)

Once up and running you need to create the trust between the vMA and your ESX hosts. Logon using vi-admin and your password. then;

sudo vifp addserver esxbox1 (you will be prompted for the hosts root password)

Do this for each box you wish the vMA to manage.

Once you have installed your UPS agent into the vMA (linux client should work without issue) the next step is to modify the shutdown script to do the work. Within the script you will need the following in it…

vifpinit esxbox1

This sets the context of vMA to this host. Note: the server should have been added as one of the managed

/usr/lib/vmware-vcli/apps/host/hostops.pl –target_host esxbox1 –operation enter_maintenance –url https:///sdk/vimService.wsdl

Note: you need to use the actual name of the host and not its IP. You can get the exact name of the

The HP power protector agent script is located at /usr/local/DevMan/SDScript

If you want to ensure all your guests shutdown cleanly, enable “shutdown virtual machines on host shutdown”. Also note that if you shutdown the host that the vMA is running on it will kill the script. So shutdown the host that the vMA is running on last (remove vm from DRS)

Update (08/04/2010): I have found the above vMA to be quite fiddly. And have had much better luck with the PowerCLI code found on this page : http://www.virtu-al.net/2010/01/06/powercli-shutdown-your-virtual-infrastructure/

I have made some slight mods but essentaillly…

$VCENTER = "vcenter"
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

940 Replies to “vMA – Using HP Power Protector agent to shutdown virtual hosts”

  1. It’s a shame you don’t have a donate button! I’d definitely donate to this excellent blog!
    I guess for now i’ll settle for book-marking and adding your RSS feed to
    my Google account. I look forward to brand new updates and will talk about this site with my Facebook group.
    Chat soon!

  2. You could definitely see your enthusiasm in the work you write.
    The sector hopes for more passionate writers such as you who are not afraid to say how they
    believe. At all times follow your heart.

  3. Hi, I do think this is an excellent website. I stumbledupon it
    ;) I may come back once again since I bookmarked it.

    Money and freedom is the best way to change, may you be
    rich and continue to help other people.

  4. Great goods from you, man. I’ve understand your stuff previous to and you
    are just too excellent. I actually like what you’ve acquired here,
    really like what you’re saying and the way in which you say it.
    You make it enjoyable and you still take care of to keep it smart.
    I can not wait to read far more from you.
    This is really a tremendous site.

  5. Pretty element of content. I just stumbled upon your site
    and in accession capital to say that I acquire actually loved account your blog posts.
    Anyway I’ll be subscribing for your feeds or even I achievement you get entry to consistently quickly.

  6. Youre so cool! I dont suppose Ive read anything in this way before. So nice to find somebody with a few original applying for grants this subject. realy appreciate starting this up. this excellent website is something that is required on the net, a person with some originality. helpful work for bringing something totally new on the world wide web!

  7. Pretty nice post. I just stumbled upon your weblog and wanted to mention that I have truly loved surfing around
    your weblog posts. After all I will be subscribing on your feed and I am hoping
    you write again very soon!

  8. hello there and thank you for your info – I’ve certainly picked up anything new from right here. I did however expertise several technical issues using this website, as I experienced to reload the site many times previous to I could get it to load properly. I had been wondering if your web hosting is OK? Not that I am complaining, but sluggish loading instances times will often affect your placement in google and can damage your high quality score if ads and marketing with Adwords. Well I’m adding this RSS to my email and could look out for much more of your respective fascinating content. Ensure that you update this again very soon..

  9. When someone writes an paragraph he/she
    keeps the plan of a user in his/her mind that how a user can be aware of it.
    Thus that’s why this paragraph is great. Thanks!

  10. Have you ever thought about writing an ebook or guest authoring
    on other sites? I have a blog centered on the same ideas you discuss and would love to have you share some stories/information. I know my visitors would appreciate your work.
    If you are even remotely interested, feel free to shoot me an e mail.

  11. I know this if off topic but I’m looking into starting my own blog and was curious what all is required to get set up?
    I’m assuming having a blog like yours would cost a pretty penny?
    I’m not very web smart so I’m not 100% certain. Any recommendations or advice would be greatly appreciated.
    Many thanks

  12. Wonderful blog! I found it while surfing around
    on Yahoo News. Do you have any suggestions on how to get listed in Yahoo
    News? I’ve been trying for a while but I never seem to get there!

  13. Great post. I used to be checking constantly this blog and I am inspired!

    Very helpful information specifically the remaining part :) I care for such
    information a lot. I used to be looking for this particular information for a long time.

    Thanks and best of luck.

  14. Oh my goodness! Impressive article dude! Thank you, However I
    am going through troubles with your RSS. I don’t understand
    why I cannot join it. Is there anybody else getting similar RSS issues?
    Anyone that knows the answer will you kindly respond? Thanks!!

  15. hello there and thank you for your information – I have certainly picked up something new from right here.
    I did however expertise some technical points using this website,
    as I experienced to reload the web site lots of times previous to I could get it to load correctly.

    I had been wondering if your web host is OK?
    Not that I’m complaining, but slow loading instances times will
    sometimes affect your placement in google and could damage your
    high-quality score if ads and marketing with Adwords.

    Anyway I’m adding this RSS to my e-mail and could look out for much more of your respective
    intriguing content. Ensure that you update this
    again soon.

  16. What’s Going down i’m new to this, I stumbled
    upon this I have discovered It absolutely useful and it
    has helped me out loads. I am hoping to give a contribution & assist different
    users like its aided me. Great job.

  17. Hmm is anyone else having problems with the pictures on this blog loading?
    I’m trying to determine if its a problem on my
    end or if it’s the blog. Any responses would be greatly appreciated.

  18. Good day! Do you know if they make any plugins to safeguard against hackers?
    I’m kinda paranoid about losing everything I’ve worked hard on. Any recommendations?

  19. you are truly a just right webmaster. The site loading pace is
    incredible. It seems that you are doing any unique trick.
    In addition, The contents are masterwork. you’ve performed a magnificent task in this topic!

  20. Howdy! This blog post couldn’t be written any better!
    Going through this article reminds me of my previous roommate!

    He continually kept talking about this. I will send this article to him.
    Fairly certain he’s going to have a great read. Thanks for sharing!

  21. I used to be recommended this website by means of my cousin. I’m now not certain whether or not this submit is written by way of him as no
    one else realize such exact approximately my trouble.
    You are wonderful! Thanks!

  22. Today, while I was at work, my cousin stole my iphone and tested to see if it can survive a 40 foot drop,
    just so she can be a youtube sensation. My iPad is now destroyed and she has 83 views.
    I know this is totally off topic but I had to
    share it with someone!

  23. This is really interesting, You’re a very skilled
    blogger. I’ve joined your feed and look forward to seeking more
    of your fantastic post. Also, I’ve shared your site in my social networks!

  24. Very good website you have here but I was wondering if you knew of any user discussion forums
    that cover the same topics talked about here? I’d really love to be a part of community where I can get feedback from other experienced people that share the same interest.
    If you have any suggestions, please let me know. Cheers!