Wednesday, August 14, 2013

Generate DR Portgroups for SRM with Powercli

The Problem

Today I was working at a customer site doing a SRM setup and was hit with a situation. The customer had setup a new DHCP vlan and portgroup at their DR site for SRM and wanted to fail over all their Production Servers to this network.
 As we went through their resource mappings and layout we came to an issue were a many to one mapping for Prod to DR for network resources was good but fail back from DR to Prod was not possible. This was because a one to one relationship was needed.

The Solution

In order to work around this I recommended to the client we setup a virtual port group for each prod network.  This new label at DR would be composed of the Prod virtual portgroup and DR DHCP network (i.e. VLAN113-DR-DHCP). Each of these new virtual portgroups will have the same VLAN ID for their newly created DHCP network.

Script was born

 So that being said, I went to my trusty script editor and started to write this powershell script that will take all production networks and apply them to DR esxi hosts. This script is for use with standard vswitch. Hope people find it useful. This will be handy script for adding new virtual portgroups or could be easily modified to use for migrations. Download here.

 #Production Cluster Name   
 $ProdClustername = "PROD CLUSTER"  
 #DR Cluster Name  
 $DRClustername = "DR CLUSTER"  
 #DR Virtual Switch Name used to create new portgroups to  
 $DRVswitchName = "vSwitch0"  
 #Vlan id to be used at DR  
 $vlanid = 20  
 #Virtual Portgroup Suffix  
 $vportgroupSuffix = "DR-DHCP"  
 #Connect to production Vcenter  
 Connect-VIServer PRODVCENTER  
 #Get portgroups from production  
 $portgroups = get-cluster $ProdClustername | get-vmhost | Get-VirtualPortGroup  
 #Disconnect from Production VCenter  
 Disconnect-VIServer -Confirm $false  
 #Connect to DR vcenter  
 Connect-VIServer DRVCENTER  
 #Loop through the list of hosts at DR site  
 foreach ($vmhost in (get-cluster $DRClustername | Get-VMHost)){  
      $vswitch = $vmhost | Get-VirtualSwitch -name $DRVswitchName  
      #Add the portgroups to each host at DR site  
      foreach ($portname in $portgroups){  
      Write-Host "Adding Portgroup $portname-$vportgroupSuffix to DR"  
      New-VirtualPortGroup -Name "$portname-$vportgroupSuffix" -VirtualSwitch $vswitch -VLanId $vlanid   
      }  
 }  
 #Disconnect DR Vcenter  
 Disconnect-VIServer -confirm $false  

Thursday, August 1, 2013

SCSI Unmap Tool for ESXi5.0 / ESXi5.1

 Last night I was hit with a question from a client about performing SCSI unmaps on an equallogic array. At first I reviewed Cormac Hogan's excellent blog post on performing this operation here. After reviewing this process I was thinking it would be beneficial to have a GUI for this operation to make it easier for execution. So, last night I went to work on a long coding binge and came up with the first iteration of SCSI unmap tool v1.0 .
 I wouldn't say it was the prettiest interface in the world but it's functional. Designed to run from the top down. Some caveats is this process does create a file based on percentage of free space you would like to reclaim. It will cause added I/O to your array during operation so should be performed during maintenance windows.

NOTE: this feature was removed from esxi5.0 due to unmap duration causing snapshot consolidation and storage vmotion timeouts while it was executing.

Requirements

  1. Powercli 5.1 or greater
  2. One LUN per datastore
  3. Execute during Maintenance window or low I/O times
  4. SSH is enabled on your esxi host performing the unmap operation
  5. v1.0 only supports using one esx host and one datastore per operation
  6. Requires root ssh access.

Tool Overview

For this test I will use a Equallogic Array with one thin provisioned volume. I created some temp vmdks on the volume and added files to the disk through the guest operating system. After completing this step I removed the vmdk from the datastore leaving freespace that is now avaliable in vsphere but showing consumed on my equallogic volumes. See screenshots:

VMFS Volume and EQ Volume before SCSI Unmap




Now I will open the GUI and execute the program to perform unmap operation.

 Below is a screenshot of the same EQ volume after the operation has completed. Due to low load on the EQ array this process took seconds after executing.

For right know the GUI only supports one esx host and one lun per operation. If you would like to do more luns at ones you will need to open multiple copies of the GUI. This was originally target for single lun use.

Download the script here

Wednesday, May 15, 2013

Export CDP info using Powercli

I was asked the other day to export cdp information from esx hosts at a client site to file. I used the vmware kb here http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1007069 that has source code for powercli. I just took this code and ammended it to export to a file instead of the console. Here is my ammended code.

$logfile = "c:\Temp\cdpinfo.txt"
Connect-VIServer vcenterhostname -User domain\username -Password password
Get-Datacenter | Get-VMHost | Where-Object {$_.State -eq "Connected"} |
%{Get-View $_.ID} |
%{$esxname = $_.Name; Get-View $_.ConfigManager.NetworkSystem} |
%{ foreach($physnic in $_.NetworkInfo.Pnic){
    $pnicInfo = $_.QueryNetworkHint($physnic.Device)
    foreach($hint in $pnicInfo){
       $esxname | Out-File $logfile -Append
    $physnic.Device | Out-File $logfile -Append
      if( $hint.ConnectedSwitchPort ) {
        $hint.ConnectedSwitchPort | Out-File $logfile -Append
      }
      else {
        "No CDP information available." | Out-File $logfile -Append
      }
    }
  }
}

Saturday, May 4, 2013

Provisioning Dell EqualLogic iscsi Storage to esxi without Vcenter

There are certain circumstances where having a script that can execute in these situations is helpful. I tend to use this script to speed up the build process while waiting on VCenter and Hitkit install/configurations to proceed.
 The script can be downloaded here. I'll do a walkthrough of the script to explain how it works.







As you can see in lines 8 and 9 from the import-module commands the Dell Hit Kit for windows and VMware powercli are required to be installed to make this work.
Line 11 is an input variable for the EQ Group IP. Line 12 input file is the service console IPs/hostnames of all the esx hosts you are connecting to. Line 13 is the name of the volumes you would like to create with the size of each volume. The syntax of each input file is referenced below.

esxhosts.txt - input file contents below

esxserver1.esx.com
esxserver2.esx.com

volumes.csv - input file contents below




After the input variables have been defined the next section of the script grabs the IQN information from all the esxi hosts. There is an assumption made at this point that you have already enable all the iscsi initiators on your esxi host and bound them to a vmkernel interface. NOTE: If there isn't atleast one iqn available for each host then the script stops.

Once we have established a list of all the active IQNs the script connects to the EQ via Dell hitkit tools for windows and provisions the volumes you indicated in the volumes.csv file with ACLs for the IQNs grabbed earlier.
 The next order of business is to grab the naa information from the storage array for each of the volumes we created. You can see below in lines 39 through 44 I started parsing this data out from the PSVID property.
  The other parts appear to be pretty self explanatory. I disconnected from the array and then establish a connection to the first host in the host file to format the volumes then perform storage rescans on all the hosts.