PowerShellVMware

Proof Of Concept Implementation Guide to Clone and Apply changes to VM images in VMware

POC Scope: The goal of this POC is to evaluate automation to clone and apply changes to VM images. So that users from other teams or external customers can apply their changes directly to the VMs and save them for later use.

 

POC Architecture:

POC is built on top of Powershell snapin called “VMware vSphere PowerCLI” for automated communications with VMware infrastructure that is hosting VMs.

POC UI is developed in PowerGUI editor to simplify the communication between UI to the backend operations and presenting back their results to the user.

A vanilla Windows Server 2008 R2 standalone server is used as a base image to evaluate the automation functionality of saving changes to Windows VMs.

For auto login to RDP session of Selected VM, use of MSRDP ActiveX code is used.

 

How it works?

In PowerGUI interface you’ll link context menu options to equivalent “VMware vSphere PowerCLI” automation commands that run on VMs and presents results back to the user.

This POC covers supporting below operations via automation

  1. Convert a base image into active VM: In this operation, a clone of base image is created, the VM is renamed in both VM and Guest OS
  2. Launch RDP session to the VM: In the operation, an RDP session to the cloned VM will be given to the user so that they can make the required changes to it
  3. Convert the updated VM into base image: In the operation, save the changes to the active VM by gracefully shutting it down and moving the VM to base images location

 

POC Setup Details:

Backend Server Infrastructure:

· VMware Software versions:

Host Server

VMware ESXi 5.1.0

vCenter Server

VMware vCenter Server 5.1.0

vSphere Client

VMware vSphere Client 5.1.0

All are run in Evaluation Mode & are latest version available as of this writing.

Scripting Automation Infrastructure:

VMware API

VMware vSphere PowerCLI 5.1.0

Quest PowerGUI

Quest PowerGUI 3.6.0

 

POC VMware Setup: Create two folders to categorize the base images and Active VMs as shown below:

 

Implementing POC Operations via automation:

1. Convert a base image into active VM

In this operation, a clone of base image is created, the VM is renamed in both VM and Guest OS

Sequence of Automation Commands to be used:

  1. Read-Host: Prompt user for a name to the cloned VM
  2. New-VM: Parameters (This command clones the VM from the base image)
    1. –Name <name of selected VM object>
    2. –VM <new name provided by the user>
    3. –Location <specify VM folder created to host the active VMs>
  3. Start-VM: To bring the cloned VM into active State
  4. Start-Sleep: Wait till the VM and it’s guest OS Windows comes up
  5. Rename Windows: Then run WMIC or Registry commands to change the Windows VM name to avoid conflicts on the network
  6. Restart-VMGuest: Restart VM in order for Windows system rename action to take affect

2. Launch RDP session to the VM:

In the operation, an RDP session to the cloned VM will be given to the user so that they can make the required changes to it

Sequence of Automation Commands to be used:

  1. Guest.IPAddress: Retrieve the IP-address of the VM selected
  2. Guest.OSFullName: Retrieve the Full Operating System name of the VM selected
  3. Match “Windows”: Ensure the choosen VM is running Windows OS
  4. Copy the MSRDP ActiveX source files for the loggedin user session
  5. Update the ActiveX rdp configuration file with IP-Address of the choosen VM
  6. Launch Start-Menu.hta to auto login to the selected VM via MSRDP ActiveX code

3. Convert the updated VM into base image

In the operation, save the changes to the active VM by gracefully shutting it down and moving the VM to base images location

Sequence of Automation Commands to be used:

  1. Read-Host: Prompt user for a name to the Base Image
  2. Set-VM: Parameters (This command renames the VM)
    1. –VM <name of selected VM object>
    2. –Name <new image name provided by the user>
  3. Move-VM: Parameters
    1. –Destination <specify VM folder created to host the Base Images>
  4. Stop-VM: This will PowerOff the VM as base Images do not run actively
Advertisements