Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ESX PowerCLI script to activate a VM when a failover occurs

Posted on 2012-04-09
7
Medium Priority
?
739 Views
Last Modified: 2012-04-26
My customer has 2 Production DC sites & one DR site.

The production DC sites has 8 web servers (all on Win
2008) each.

The DR site currently has 8 VMs up & running, ready to
take over when any one of the Production DC site is
down.  However, the customer only have 8 Win 2008
licences for the 8 VMs in an ESXi host.

We're assuming that at any one time, only one of the
Production DC site is down.  The customer wants the
DR site to be able to provide full support (ie provide
8 full VMs to support whichever DC that was hit).

Q1:
Anyone has any solution without buying more Win 2008
server licences for the DR site to meet the customer's
requirement?

Q2:
I thought of configuring 4 active VMs to support the 1st
Production site with another 4 'shutdown' or 'network-
disconnected' VMs for the 1st Production site.  Similarly
configure 4 active VMs (with another 4 'shutdown' VMs)
to support the 2nd Production site.   So in the event a
disaster strikes Production Site 1, a script in the ESXi
host will shut down the 4 active VMs for Site 2 &
bring up (or boot up) the 4 'shutdown' VMs for Site 1,
thus providing the full 8 Web servers to Site 1.
In this way, I will not be violating Windows 2008 server
licencing as I only have 8 VMs up at any one time.

Does anyone has any PowerCLI (for ESXi Ver 5) scripts
& commands to perform the above requirement?


Q3:
Pls suggest a few good websites/links that give good
examples on ESXi automation (esp using scripts )
0
Comment
Question by:sunhux
  • 4
  • 3
7 Comments
 

Author Comment

by:sunhux
ID: 37823650
Guess I'm looking for something mentioned in Point 6 in
the link / url below :
  http://www.simple-talk.com/sysadmin/virtualization/10-steps-to-kick-start-your-vmware-automation-with-powercli/


Also from the url below,
  http://communities.vmware.com/message/1162125
I'll need to clarify:
a) is this "Invoke-VMScript" a script & where can I download its codes?
b) can I run "Invoke-VMScript" to disable the NIC port (just like right-
    clicking the NIC icon on the bottom right bar of my desktop & select
    disable) to disable a VM that I want to stay 'shutdown' & to bring up
    a VM, invoke this script with parameter to enable it.  This is better
    than shutdown & booting up a VM (as this takes longer).  
    By disabling a NIC of a VM, can I say I've legally disabled the use
    of one Windows 2008 (Guest OS) licence?
0
 
LVL 5

Assisted Solution

by:Daryl Bamforth
Daryl Bamforth earned 2000 total points
ID: 37830480
Are the production boxes physical or virtual?  How are the sites interconnected? If they are all virtual with high speed links is High Availability not an option?

Deploying VMs from a template would not help (unless there was a different angle to step 6 you were thinking of?) as these would just deploy a brand new machine that would need configuring.

If you are wanting to change the state of a network port through vcenter you could use this
https://www.vmware.com/support/developer/PowerCLI/PowerCLI41U1/html/Set-NetworkAdapter.html

This would allow you to change the 'state' of the adapter to be connected or unconnected. (similar to plugging in or removing the network cable).  

There are also some 3rd party products that may allow better failovers.
http://communities.vmware.com/thread/253736

In terms of the licensing although I would assume they would be happy as long as only one instance of a licensed server is available at any one time, you would really need to speak to your MS license supplier for confirmation that this would be abiding by Microsoft's EULA.
0
 

Author Comment

by:sunhux
ID: 37837378
So if I want to 'deactivate' or disconnect VM3 & deallocate its CPU/RAM
resource, the PowerCLI codes would be:
    $vmnet = Get-VM VM3 | Get-NetworkAdapter | where {$_.Name -eq "Network Adapter 1"}
    Set-VM -vm VM3 -Numcpu 2 -Confirm:$false
    Set-VM -VM VM3 -MemoryMB 8192 -Confirm:$false
    $vmnet | Set-NetworkAdapter -NetworkName $VM.Network -Connected:$false
-StartConnected:$false -Confirm:$false

& if I want to 'activate' or connect VM9 & allocate its CPU/RAM
resource, the PowerCLI codes would be:
    $vmnet = Get-VM VM9 | Get-NetworkAdapter | where {$_.Name -eq "Network Adapter 1"}
    Set-VM -vm VM9 -Numcpu 2 -Confirm:$false
    Set-VM -VM VM9 -MemoryMB 8192 -Confirm:$false
    $vmnet | Set-NetworkAdapter -NetworkName $VM.Network -Connected:$true
-StartConnected:$true -Confirm:$false
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 5

Accepted Solution

by:
Daryl Bamforth earned 2000 total points
ID: 37837593
You wouldn't want to be deallocating cpu and ram on a system that is turned on.  What would you be gaining by doing this anyway?

If you just wanted to disable a network adapter you could actually just do

connect-viserver <server-address>
get-networkadapter <server-name> | set-networkadapter -connected:$false -startconnected:$false -confirm:$false

the way you have written it would only return the value of get-network adapter, when you then tried to set it it would fail as there would be no vm to associate it with.

Starting it would just need -connected:$true and -startconnected:$true

Are you just talking about web servers?  Or domain controllers as well?

How would you be intending to synchronise this?  
If you bring an outdated web server online your site will be potentially be out of date.
If you brought a severely out of date DC into the mix there would be a number of problems.  If you are wanting to leave it in a 'prepared' state have a look at this.

http://technet.microsoft.com/en-us/library/cc782557%28v=ws.10%29.aspx
0
 

Author Comment

by:sunhux
ID: 37848099
>You wouldn't want to be deallocating cpu and ram on a system that is turned
>on.  What would you be gaining by doing this anyway?
By deallocating VMs that are disconnected, it would free up more CPU
& RAM for me to allocate to VMs that I'm connecting up, isn't it?  In
this way those VMs that are no longer 'active' will have 0 RAM & 0
CPU so that I can allocate more resource to the newly brought up
VMs


Btw, to enable the use of PowerCLI script (those  *.ps1 such as the
ones listed in the links below), what must I install?  PowerShell or
PowerCLI package?  & is this installed on the vCentre, vSphere,
ESX host itself or the individual VMs?  Pls provide me the links to
download these packages (for vSphere/vCentre 5 & ESXi 5)

http://poshcode.org/3222
http://poshcode.org/2051
0
 
LVL 5

Assisted Solution

by:Daryl Bamforth
Daryl Bamforth earned 2000 total points
ID: 37848186
No, you can over allocate as long as the machines are in a powered down state it doesn't matter how much you have allocated (although ESX5 licensing does care about allocations, this shouldn't kick in unless you were running a much bigger infrastructure).

If you are leaving this back-up systems in an powered down state I wouldn't bother disconnecting the networking either.  Just prep them with the correct IP's and shut them down.  Do remember you will need to synch them when you power them up to ensure they are up-to-date.  (one way to ensure they don't jump on accidentally is to have a separate private lan that is not routed outside of the DR infrastructure.  When it is ready to go live you can just switch the guest over to the correct network.)

Powershell is installed by default on all 2008, however the latest version can be downloaded from

http://technet.microsoft.com/en-us/scriptcenter/dd742419

Then youjust need to download and install the powercli snapin
http://www.vmware.com/go/PowerCLI

This targets your Virtual Centre but does not need to be installed there.
0
 

Author Closing Comment

by:sunhux
ID: 37897796
excellent
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

August and September have been big months for VMware—from VMworld last month to our new Course of the Month in VMware Professional - Data Center Virtualization. We reached out to Andrew Hancock, resident VMware vExpert, to have a more in-depth discu…
It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
How to install and configure Citrix XenApp 6.5 - Part 1. In this video tutorial we have explained step by step installation of Citrix XenApp 6.5 Server on Windows Server 2008 R2 is explained in this video. We have explained the difference between…
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question