Home > ESX, NetApp, PowerCLI, Powershell, VMware > SRM for free with PowerCLI & DataONTAP– Part 1: NFS

SRM for free with PowerCLI & DataONTAP– Part 1: NFS

I’ve blogged before on how you can use PowerCLI to replicate some of the functionality of VMware’s SRM to easily recover VMs in a business recovery site with replicated storage.

In my previous post I had only looked at the VMware side of the automation and so it’s time for an update to include the important part of handling the underlying storage. I’m going to use NetApp storage as an example but any storage vendor that exposes their API to Powershell can be used if you can find the relevant commands.

This is where the awesomeness of Powershell really comes into its own when you can combine automation for both VMware and NetApp in a single script.

You will obviously need both PowerCLI and Netapp’s DataONTAP installed. See my previous post: Pimping your Powershell Profile for getting everything installed.

Have a look at the previous post for how to set up your vCenter folders and how you can use NFS read-only mirrored datastores to add the BR VMs to your vCenter inventory.

For the storage automation, all you really have to do is connect to the filer and then quiesce and break the storage mirror so it is writeable at the BR site. After you’ve connected this is a single line:

Get-NaSnapmirror "FilerName" | Invoke-NaSnapmirrorQuiesce | Invoke-NaSnapmirrorBreak -Confirm:$false

Here’s the whole updated script:

@"
===============================================================================
Title:         VM-NFSBRv2.ps1
Description:   BR recovery for NFS VMs with NetApp Storage
               Connects to Filer and breaks mirror.
               Connects to vCenter and Powers on all VMs in a specified folder.
               Folder name must be unique in vCenter
               Answers UUID question to say VM was Moved.
               Can be Run as Scheduled Task
Usage:         .\VM-NFSBRv2.ps1
===============================================================================
"@

$VMFolder = "BR-LondonAppServers"   # Folder where BR VMs have been placed - Must be unique in VC
$vCServer = "vcenter.local"
$FilerName = "brfiler.local"
$FilerVol = "v_lon_brservers"

# Connect to VC
Connect-VIServer -Server $vCServer

# Connect to Filer
Connect-NaController $FilerName

# Break Storage Mirror
Get-NaSnapmirror $FilerVol | Invoke-NaSnapmirrorQuiesce | Invoke-NaSnapmirrorBreak -Confirm:$false

# Get all VMs placed in $vmfolder
$VMs = Get-VM -Location (Get-Folder $VMFolder)

# Disconnect Networking FOR TESTING ONLY
#$VMs | Get-NetworkAdapter | Set-NetworkAdapter -StartConnected:$false -Confirm:$false

# Power on VMs even with questions pending
$VMs | Start-VM -RunAsync

# Answer Question to Keep UUID in Loop until Question is answered
$qMsgUuidMoved = "msg.uuid.altered:"
$ChoiceMove = 2

ForEach ($VM in $VMs) {
   do {
      $VMView = $VM | Get-View
      if($VMView.Runtime.Question -ne $null -and $VMView.Runtime.Question.Text.StartsWith($qMsgUuidMoved)) {
         $VMView.AnswerVM($VMView.Runtime.Question.Id, $ChoiceMove)
      }
   }
   until ($VMView.Runtime.PowerState -ne "PoweredOff")
}

# Disconnect from vCenter Server
Disconnect-VIServer -Confirm:$False
  1. August 16th, 2011 at 16:07 | #1

    Nice! I’m a fan of the Netapp Toolkit too – it’s allowed us to script the creation of our Linux VMs ‘end to end’ including Netapp volumes, volume options, setting NFS exports, creating datastores, VMs etc. We even use the VIX API to write the /etc/fstab file accordingly so storage is already mounted post deployment. This looks like another great use case, thanks for sharing.

  1. September 14th, 2011 at 10:32 | #1
 

Time limit is exhausted. Please reload the CAPTCHA.