Advanced Customization Learning Performance vCenter

Using VMware Instant Clone via PowerCLI Extensions Fling

FLINGS.png

In the last post I anounced the new PowerCLI Extensions fling, which allows admins to leverage the Instant Clone abilities found in vSphere 6. Today I’m going to walk you through how to use it.

Prerequisites

To be able to fully leverage PowerCLI Extensions, you will need to meet the following requirements:

  • VMware PowerCLI 6.0 R1 or higher
  • PowerShell v2 or higher
  • vSphere 6

Installation

  1. Download the latest release of PowerCLI
  2. Download PowerCLI Extensions on the VMware Fling page HERE
  3. Right-Click the PowerCLI Extensions zip file, click Properties, and select ‘Unblock’.
  4. Unzip the contents of the PowerCLI Extensions fling and place them in your PowerShell modules directory (do not rename the folder)
  5. Ensure the VMware.VimAutomation.Extensions folder is only a single directory deep. (module files should be in the next level down)

Using Instant Clone

before creating a parent VM, you will want to ensure that you get your intended-parent VM is in the intended state for the child VMs to pick up and continue. You will also want to create a ‘Post Clone Script’ to attach to the parent VM which will run as each child VM is started. For Windows, this would be a batch (.bat) script, for linux this would be a shell (.sh) script. an example of a Windows Post Clone Script created by  Deji Akomolafe, Staff Solutions Architect at VMware is below:

##### In-Guest Customization script
“%programfiles%\vmware\vmware tools\rpctool” “info-get guestinfo.fork.ipaddress” > c:\ip.txt
“%programfiles%\vmware\vmware tools\rpctool” “info-get guestinfo.fork.gateway” > c:\gateway.txt
set /p ip=<c:\ip.txt
set /p gateway=<c:\gateway.txt
FOR /F “tokens=2,3* ” %%j in (‘netsh interface show interface ^| find “Connected”‘) do set ConnnectedNet=%%l
netsh interface ipv4 set address name=%ConnnectedNet% static %ip% 255.255.255.0 %gateway%
netsh interface set interface %ConnnectedNet% DISABLED
netsh interface set interface %ConnnectedNet% ENABLED

Once you’ve created your Post Clone Script, you can move on to creating your Parent VM

  • Open PowerCLI and import the module
    • import-module VMware.VimAutomation.Extensions

Import Extensions

  • Connect to your vCenter Server
    • Connect-VIServer <your vCenter address>

Connect to vCenter

  • Specify your intended parent VM
    • $parentVM = Get-VM Parent2012

Get-VM Parent2012

  • Enable the $parentVM as an instant-clone parent
    • $parentForkVM = Enable-InstantCloneVM -VM $parentVM -guestUser “administrator” -GuestPassword “VMw@re123” -PostCloneScript C:\temp\WindowsPostScript.bat

Enable-InstantCloneVM

  • Add any configuration parameters you want to be able to pass to the child VM
    • $ConfigSettings = @{
      ‘ipaddress’ = “10.134.14.75”;
      ‘netmask’ = ‘255.255.255.0’;
      ‘gateway’ = ‘10.134.14.253’;
      ‘dns’ = ‘10.134.14.9’;
      }

Config Settings

  • Create the Instant-clone child VM and attach the configuration parameters
    • $childForkVm = New-InstantCloneVM -ParentVM $parentForkVM -Name Child2012 -ConfigParams $ConfigSettings

New-InstantCloneVM

  • Start the child VM
    • $childForkVm | Start-VM

Start-VM

 DEMO

Creating multiple child VMs

Using the same commands as we did above, we can create as many instant-clone VMs as we want. To keep things simple as far as IP addresses go, this example will deploy 9 child VMs from the 2012 parent.

1..9 | Foreach {

$configSettings = @{
‘ipaddress’ = “10.134.14.13$_”;
‘netmask’ = ‘255.255.255.0’;
‘gateway’ = ‘10.134.14.253’;
}

Write-Host “Creating Clone$($_)…”

$childForkVm = New-InstantCloneVM -ParentVM $parentforkVm -Name “2012ChildClone$_” -ConfigParams $configSettings

$childForkVm | Start-Vm -RunAsync | Out-Null
}

as you can see from above, the only items that have really changed from creating a single child VM is that we piped a series of numbers (1-9) in the command and for each number, it creates a virtual machine with an ip address 10.134.14.13_ where _ is the number that was piped in. The names of the VMs are also identified using the piped value, creating

Additional Actions

Sections 7 and 8 of the PowerCLI extensions guide give many examples of what can be done with Instant Clone. For additional examples please refer to these sections.

Things to know

Parent VMs

Once a VM becomes a parent VM, it has limited operations it can do. Parent VMs cannot be used or edited while running as a parent. To release it from being a parent VM, you must power that VM off. You will notice that the other power options are not available while running as a parent. See section 5.1 of the PowerCLI Extensions guide for more details on parent operations.

Child VMs

A child VM can be powered-on, off, and reset. It can be deleted once the VM is powered-off. It can be unregistered, and it can be reconfigured to add disks only. additional operations may be supported in the future, but are not at this current time.