vSphere Auto Deploy – Image Profile and Booting ESXi

April 24, 2012 in DCA, vHersey, VMware

The VCAP5-DCA Blueprint has objectives on working with ESXi Image Profiles and configuring VMware Auto Deploy which are both new features that were released with vSphere 5. As part of studying for the VCAP5-DCA beta exam I have been working on becoming more familiar with these features in my home lab. The vSphere Installation and Setup Documentation does a good job walking through the process of preparing a ESXi Software Image and setting up Auto Deploy.

Enable Auto Deploy on vCenter Server Virtual Appliance

If you are running vCenter on a Windows Server you will need to install the Auto Deploy server on that server. If you are running the vCenter Server Appliance Auto Deploy needs to be enabled by logging in to the web management interface and navigating to Services -> Autodeploy.

To use the default port and repository size just click “Test Settings”, then click “Save Settings.” Then you must stop and start the ESXi services from the Services -> Status page. ESXi Autodeploy status should change to “Running”.

Once Auto Deploy is running it can be accessed from the Home menu in the vSphere Client. From here download the TFTP Boot Zip and note the BIOS DHCP File Name.

Set up DHCP and TFTP

I am using this DHCP server running on an XP VM to serve up DHCP for my lab environment. This DHCP server also has a built in TFTP server.

Configure the DHCP scope and add the BIOS DHCP File Name and the TFTP server IP address to the boot file parameter (this is done in the advanced options of the DHCP wizard if you use this DHCP Server). Unzip the Auto Deploy TFTP Boot File into the TFTP server root directory.

ESXi Image Profile

Adding an ESXi Software Image Profile is done using PowerCLI cmdlets. I downloaded the ESXi 5 zipped distribution from VMware.com and placed it in a directory on my C:\ drive.

The zip is then added as a Software Depot using PowerCLI.

Add-ESXSoftwareDepot c:\pathto\ESXi5.zip

Use Get-ESXImageProfile to display the available images in the depot.

Name                           Vendor          Last Modified   Acceptance Level
----                           ------          -------------   ----------------
ESXi-5.0.0-20111104001-stan... VMware, Inc.    10/13/2011 3... PartnerSupported
ESXi-5.0.0-20111104001-no-t... VMware, Inc.    10/13/2011 3... PartnerSupported

Then create a new deploy rule to use the Image Profile you want and apply it based on a host pattern. I am checking that the IP address (ipv4) is within the DHCP range set up for the hosts.

New-DeployRule -Name “ESXiDeployProfile” -Item ESXi-5.0.0-20111104001-standard -Pattern “ipv4=192.168.1.230-192.168.1.239″

The software will unzip and the packages will be uploaded to the Auto Deploy server.

Once the deploy rule is created it has to be activated.

Add-DeployRule -DeployRule ESXiDeployProfile

Auto Deploying ESXi

Since I am running my lab in Workstation I created an ESXi VM with no hard drives and added the necessary NICs for my environment (connections to management, storage, vMotion, and VM networks). The VM boots straight to network boot. The VM receives a DHCP address, the boot file from the TFTP server, and then begins booting from the Auto Deploy repository.

After the initial PXE boot the ESXi VM begins booting ESXi from the Image Profile based on the Deploy Rule.

When the host finishes booting it is added to the vCenter server inventory in maintenance mode.

Now a Host Profile and Answer File will need to be applied to configure the ESXi host for use in the environment. I will cover this in another post in the next couple days… and here it is Auto Deploy: Host Profiles and Answer Files.

VMware PowerCLI 5 Reference iPad/iPhone App

February 15, 2012 in iPad Apps, VMware

The more I use PowerCLI the more uses I find for it. Searching out configurations, setting options, migrating VMs, powering down VMs, deploying new VMs, and a long list of other handy things that can be accomplished with a single easy to write line of PowerCLI code. My copy of the VMware vSphere PowerCLI Reference: Automating vSphere Administration book gets a pretty regular workout but I don’t always have it with me.

I downloaded this free iPad/iPhone/iPod VMware PowerCLI 5.0 Reference app in the itunes store – vPowerCLI5 Reference App that was developed by theHyperAdvisor.com. The app provides an easy to use and searchable PowerCLI cmdlet reference on my iPhone.

App description: “This tool is to be used for referencing the VMware vSphere PowerCLI cmdlets. vSphere PowerCLI is a command-line and scripting tool built on Windows PowerShell, and is used for managing and automating vSphere.

Not really digging the yellow background and blue/green text. Would be nice if there was a way to change that. Other than that a great free app. Get it here. The app is also available for the Andriod in the Andriod Market.

Read the rest of this entry →

Configuring Advance HA Settings with PowerCLI

January 27, 2012 in vHersey, VMware

In the TCC lab (and in many production environments) the default gateway filters ICMP packets. In order for HA to be successfully configured the isolation address, which is the default gateway by default, must be a pingable address. In the TCC lab you have to configure HA to not use the default isolation address and you have to set a different isolation address for it to use. These options are set in the Advance Options of the HA configuration using the vSphere client but can also be configured using PowerCLI.

To configure advance VMware HA settings with PowerCLI the New-AdvancedSetting cmdlet is used.

Here are the PowerCLI commands used to set the das.isolationaddress1 and das.usedefaultisolationaddress

$cluster = Get-Cluster -Name YourCluster

New-AdvancedSetting -Entity $cluster -Type ClusterHA -Name 'das.isolationaddress1' -Value YourPingableIPAddress

New-AdvancedSetting -Entity $cluster -Type ClusterHA -Name 'das.usedefaultisolationaddress' -Value false

Once these options are set you have to reconfigure HA and the simplest way I found to do this was to disable and re-enable HA.

Set-Cluster -Cluster $cluster -HAEnabled:$false

Set-Cluster -Cluster $cluster -HAEnabled:$true

If someone has a better way to reconfigure the cluster in using PowerCLI let me know.

Resources:

PowerCLI Class References and Resources

January 21, 2012 in vHersey, VMware

I am currently teaching the VMware vSphere: Automation with vSphere PowerCLI [V4.x] as part of the VMware IT Academy program offered at Tidewater Community College (TCC).

Here are a few of the online resources that I have referenced in the class:

VMware vSphere: Automation with vSphere PowerCLI [V4.X] course description/outline – http://www.vmware.com/go/vsphereautomation

Download the latest version of VMware PowerCLI and get access to the PowerCLI documentation at http://www.vmware.com/go/PowerCLI

PowerCLI Posters and Reference Cards:

ProfessionalVMware.com BrownBag PowerCLI 101
This BrownBag Video is a great PowerCLI primer.

ProfessionalVMware BrownBag – PowerCLI 101 w/ Glenn Sizemore from ProfessionalVMware on Vimeo.

Cmdlet References:

Other great resources:

If anyone has any useful PowerCLI resources please add a comment and I will update the post.
Read the rest of this entry →

PowerCLI Script to Shutdown My Home Lab

December 14, 2011 in vHersey, VMware

Ran across a PowerCLI script that can be used to shutdown your virtual infrastructure written by Alan Renouf and thought it would be pretty handy to use to automate shutting down my home lab.

The original script attempts to shutdown VMs “cleanly” using Shutdown-VMGuest. Shutdown-VMGuest attempts to shutdown the VMs OS and requires that VM Tools be installed and running. Most of the VMs in my lab are running Damn Small Linux (DSL) and do not have VM tools installed so this would not work and it would shutdown the host without shutting down the VMs first. Not really a big deal but I wanted to make the process just a bit cleaner.

I changed the script to first shutdown VMs that are powered on and have VM tools running. It then waits $waittime in seconds and uses Stop-VM to forcefully power off any remaining powered on VMs. As in the original script it then waits $waittime or until no VMs are powered on to shutdown the ESXi hosts.

Connect-VIServer MyVIServer

# Set the amount of time to wait before assuming the remaining powered on guests are stuck
$waittime = 60 #Seconds

# Get All the ESX Hosts
$ESXSRV = Get-VMHost

# For each of the powered on VMs with running VM Tools
Foreach ($VM in ($ESXSRV | Get-VM | Where {$_.PowerState -eq "poweredOn" -and $_.Guest.State -eq "Running"})){
    # Shutdown Guest
    write-host "Shutting down $VM"
    $VM | Shutdown-VMGuest -Confirm:$false
}

Write-host "Pausing for $waittime seconds to allow VMs to shutdown cleanly"
sleep $waittime

#Force Poweroff of any VMs still running
Foreach ($VM in ($ESXSRV | Get-VM | Where {$_.PowerState -eq "poweredOn"})){
      # Power off Guest 
      write-host "Powering off $VM"
      $VM | Stop-VM -Confirm:$false
}

$Time = (Get-Date).TimeofDay
do {
    # Wait for the VMs to poweroff
    sleep 1.0
    $timeleft = $waittime - ($Newtime.seconds)
    $numvms = ($ESXSRV | Get-VM | Where { $_.PowerState -eq "poweredOn" }).Count
    Write-host "Waiting for shutdown of $numvms VMs or until $timeleft seconds"
    $Newtime = (Get-Date).TimeofDay - $Time
    } until ((@($ESXSRV | Get-VM | Where { $_.PowerState -eq "poweredOn" }).Count) -eq 0 -or ($Newtime).Seconds -ge $waittime)

# Shutdown the ESX Hosts
Write-host "Shutting down hosts"
$ESXSRV | Foreach {Get-View $_.ID} | Foreach {$_.ShutdownHost_Task($TRUE)}

Write-Host "Shutdown Complete"

To use the script just change MyVIServer in line 1 to be the IP address or hostname of you vCenter server. Set $waittime at line 4 to be the number of seconds to wait before forcefully powering off VMs. The $waittime may need to be increased depending on the speed of your lab and the number of VMs that are shutting down. Run the script as you would any other PowerCLI script.

It is probably not completely necessary to force the shutdown of all VMs before shutting down the hosts. They will be shutdown when the host they are running on is shutdown. It just gave me some PowerCLI practice and it works.

Be EXTREMELY careful with this script. When you run it all VMs and Host managed by the vCenter you are connecting to will be shutdown!

DO NOT RUN THE SCRIPT AGAINST YOUR vCENTER SERVER IF YOU DO NOT WANT TO SHUTDOWN VMs!

Thanks again to Alan Renouf for the original script which can be found at http://www.virtu-al.net/2010/01/06/powercli-shutdown-your-virtual-infrastructure/.

If you found this script useful or have other ideas for improvements post to the comments.

PowerCLI to Check for VMware ToolsOK

November 30, 2011 in VMware

Had an issue last night with setting a VM’s IP Address, DNS, and name using Invoke-VMScript after powering on the VM. The Invoke-VMScript would timeout because VMware Tools was not started. I tried using sleeps in the script to pause the script long enough so Tools would start. I could not get this to work consistently so I did some searching around and found this bit of PowerCLI code that loops until the status of VMware Tools returns OK.

write-host “Waiting for VM Tools to Start”
do {
$toolsStatus = (Get-VM $vm | Get-View).Guest.ToolsStatus
write-host $toolsStatus
sleep 3
} until ( $toolsStatus -eq ‘toolsOk’ )

Exactly what I needed it to do. Will probably enhance it to update tools if $toolsStatus is equal to ‘toolsOld’ but not sure that will be necessary I am usually pretty good at keeping the VM tools installs up to date in my templates.

I cannot find the source where I found this, it was part of another script and I should have saved the URL. If this is your snippet – THANKS!

Got an update from Alan Renouf (@alanrenouf) from http://www.virtu-al.net/

“You might want to check out (Get-VM $vm).extensiondata.Guest.ToolsStatus rather than (Get-VM $vm | Get-View).Guest.ToolsStatus it should give you the same results but be slightly quicker. ”

Thanks for the tip Alan!

VMware PowerCLI Function to Modify Virtual Machine Configuration Options

May 31, 2011 in VMware

This is a blog post I did on a different blog and I am am migrating most of the VMware/system admin posts here and this is the first.
—-

I was looking for a powershell script to set a few virtual machine security options for a school lab. The configuration keys I need to set are isolation.device.connectable.disable, isolation.device.edit.disable, and RemoteDisplay.maxConnections.

I found a function used to set RemoteDisplay.maxConnections here. By changing the RemoteDisplay.maxConnections it could be used to also change the other options so I modified the function to accept another parameter for the setting you want to add or change.

Here is the function:

Function Set-ExtraOptions{
param(
    [string[]]$vmName,
    [string[]]$KeyName,
    $KeyValue
)
    $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

    $extra = New-Object VMware.Vim.optionvalue
    $extra.Key="$KeyName"
    $extra.Value="$KeyValue"
    $vmConfigSpec.extraconfig += $extra

        $vm = Get-VM $vmName | Get-View
        $vm.ReconfigVM($vmConfigSpec)
}

And here is how you call it:

Set-ExtraOptions -vmName VM_NAME -KeyName KEY_NAME -KeyValue KEY_VALUE

To set isolation.device.connectable.disable to FALSE for LabVM-A just call the function like this:

Set-ExtraOptions -vmName “LabVM-A” -KeyName isolation.device.connectable.disable -KeyValue FALSE

Awesome HA and DRS Audit Script Based on the HA/DRS Technical Deepdive

May 17, 2011 in VMware

If you do not have a copy of VMware vSphere 4.1 HA and DRS Technical Deepdive by @DuncanYB and @FrankDenneman then go here, buy it, and read it cover to cover. The book covers everything VMware High Availability (HA) and the Distributed Resource Scheduler (DRS) (and then some!).

Alan Renouf, co-author of another must have book – VMware vSphere PowerCLI Reference: Automating vSphere Administration, has put together a nice HA and DRS Audit PowerCLI script that can be used to gather information and check for best practices on your HA/DRS cluster based on the information from the Technical Deepdive book.

The script is run against your vCenter and creates a nicely formatted HTML report with all the HA/DRS related details of each cluster managed by vCenter. This gives you a detailed overview of your environment and the configuration of HA and DRS.

As of right now the script is based on the information contained in just the first 50 pages of the HA and DRS Deepdive. Alan Renouf is promising updates to the script as he works his way through the book.

Go here to download the HA and DRS Audit script.