Solved

ESX PowerCLI script to activate a VM when a failover occurs

Posted on 2012-04-09
7
721 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 2

Assisted Solution

by:un0ri
un0ri earned 500 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
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 2

Accepted Solution

by:
un0ri earned 500 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 2

Assisted Solution

by:un0ri
un0ri earned 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Last article we focus in how to VMware: How to create and use VMs TAGs – Part 1 so before follow this article and perform the next tasks, you should read the first article how to create the TAG before using them in Veeam Backup Jobs.
In this article, I will show you HOW TO: Create your first Windows Virtual Machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, the Windows OS we will install is Windows Server 2016.
This video shows you how to use a vSphere client to connect to your ESX host as the root user. Demonstrates the basic connection of bypassing certification set up. Demonstrates how to access the traditional view to begin managing your virtual mac…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now