Saturday, February 4, 2012

Host Profile update made easy with PowerCLI GUI

You don't usually associate Powershell with GUI. However, powershell is extremely .NET friendly.  You can build pretty impressive Windows GUI interface with it. But, it is not easy writing the GUI code line by line in Powershell. That is why I like to use Sapien Primary Forms. You can build GUI inteface using the graphic utility and it will write the powershell script for you.  How awesome is that?
Script below is one of the GUI interface script that I wrote.  It checks host profile in the cluster and applies the host profile on single ESX host at a time.  It does it by putting one non-compliant host in to maintenance  mode by evacuating the VMs using DRS and vMotion.  Once the host server is place in to maintenance mode, it applies assigned host profile and takes the server out of the maintenance mode once it is completed.  I hope to post more of my GUI scripts in the future.

You can grab my script from here.





Automated ESX Virtual Machine VLAN test

At work we moved away from standalone servers to HP blade servers with two 10Gbe pass-thru configuration. I recently built 5 ESXi4.1 hosts in to our growing number of ESXi clusters. Before putting the server in to production, we let it bake in the sun for about one to two weeks. After baking is over, we test VLAN and fault tolerance on NICs. After countless clicks to Vmotion a VM_HLPER VM through ESXi hosts, I decided to make script for it. Below is the script for my automated VLAN test using VM_HELPER machine. VM_HELPER is a small VM that helps administrators run tests like this. VM_HELPER should have access to all VM VLANs with IP address.
Be sure that ESX servers are not being used in production. The script will isolate each vmnic from vSwitch0.

Thursday, February 2, 2012

NFS mapping via IP or DNS?

In the place that I work, we use NFS for are datastore mounts.  We use DNS to mount our datastores (I disagree with this approach).  I was building new servers on a new physical plateform with new network configuration.  Because of this reason, I didn't want to use existing host profile to configure the server.

Since datastore mounts will stay the same, I wanted to copy datastore mount from existing ESX host servers to new ESX servers that I built.  I was being lazy and searched for the PowerCLI script.  Google took me to ic-freak.nl PowerCLI script that will copy datastore mounts from reference hosts to the new hosts.  The problem with the script was that it will only mount the datastore using IP although reference host had DNS based mounts.


vSphere will not think IP mounted and DNS mounted datastores are same even if they point to same datastore and folder.  vMotion will fail if you try to vmotion a VM between them.  You must either mount all datastores via IP or DNS, not both.

Below is the script without using Get-View statement.  Without get-view, scripts are little bit faster using .extensiondata.


   
 $viserver = Read-Host "Enter VI server"  
 $refhost = Read-Host "Enter Reference host server"  
 $cluster = Read-Host "Enter Cluster name that has new hosts"  
   
 Connect-VIServer $viserver  
 $REFHOST = Get-VMHost $refhost  
 $NEWHosts = Get-Cluster $cluster | Get-VMHost | sort name  
   
 foreach($nfs in (Get-VMhost $REFHOST | Get-Datastore | Where {$_.type -eq "NFS"} )){  
   [string]$remotePath = $nfs.extensiondata.info.nas.remotepath  
   [string]$remoteHost = $nfs.extensiondata.info.nas.remotehost  
   [string]$shareName = $nfs.Name  
        
      Foreach ($NEWHost in $NEWHosts) {  
        $NEWHOST | Get-Datastore | Where {$_.Name -eq $shareName -and $_.type -eq "NFS"} -ErrorAction SilentlyContinue  
        If ((Get-VMHost $NEWHOST | Get-Datastore | Where {$_.Name -eq $shareName -and $_.type -eq "NFS"} -ErrorAction SilentlyContinue )-eq $null){  
          Write-Host "NFS mount $shareName doesn't exist on $($NEWHOST)" -fore Red  
          New-Datastore -Nfs -VMHost $NEWHost -Name $Sharename -Path $remotePath -NfsHost $remoteHost  | Out-Null  
        }  
      }       
 }  

Sunday, October 16, 2011

We were having performance issues wtih Netapp filer in our production environment.  We suspected that there may be problem with disk alignment (check out yellow brick's post regarding disk alignment) and VMs with high disk I/O. I was asked to provide VM I/O report for the VMs that are on the datastore.  Unlucky for me, our production environment is on ESX 4.0 and this version does not have VM I/O vSphere API.  VM I/O is availble from ESX(i)4.1 and up.  Since Tivoli was our choice for server monitoring, I had to turn to Tivoli IT guys for help.  They were able to produce the I/O report for me.  So, IF we were on 4.1, how would I pull the information for VM disk I/O?

Lets take a look what is available for Virtual Machine monitoring from vSphere API.



Counter is type of stat you will be using to look up disk I/O.  Levels is the monitoring level that you can define on vsphere.  Level "2" is the minimal requirement for this counter to work.  Finally, this entity is for for virtual machine only.

If vSphere logging level is set to less than 1, these stat types are not available.  See examples below.


Get-StatType cmdlet will give you type of stats that are available for the entity.
You should use any vm name that is up and running in the environment.


Get-StatType -entity (get-vm vmnamehere)

Level 1 logging does not provide much logging and as you can see from the screenshot, virtual disk I/O is missing from the avaiable monitoring list.

vSphere level 2 logging will provide more performance stats at the expense of more SQL disk usage.

Get-StatType -entity (get-vm vmnamehere)


Virtual disk montoring is avaiable for the VM along with alot more monitoring types.  Other monitoring types is cut-off from the screenshot because list was too long.

So, How do we apply new found stats for virtual machines?  We use Get-Type cmdlet to get the job done.
Example below will pull the stat data from 10/11/2011 to today's date.

>Get-Type -entity (get-vm vmnamehere) -stats virtualdisk.read.average -start 10/11/2011 -finish (get-date)




Saturday, October 15, 2011

First blog post

I don't know who is reading my first post.  But if you are reading this, you've just won $10,000.  Okay, I'm kidding.  On this blog, I will be focusing on VMware technologies and scripting with PowerCLI.  Couple of months ago, I didn't know jack about Powershell and PowerCLI.  Now, I can script with confidence and picked up few tricks and tips along the way.  Virtual, LucD, Reuben, and PowerCLI bloggers around the world inspired me to push further in to the world of scripting and automation.  I hope to share my knowledge and be helpful to you to get what you need in the world of virtualization.