profile for Gajendra D Ambi on Stack Exchange, a network of free, community-driven Q&A sites

Monday, October 12, 2015

IP Hashing on your clusters and hosts

Many a time i had this issue (blame me ) where i enable ip hashing on the vswitch and i forget to do the same on the portgroups or miss one of the many portgroups of the vswitch which will ultimately make me and my networking guys suffer since now we have to go keep digging from both ends, from both networking and vmware end.
You may checkout the github page where i keep such things to get them updated as and when i get time.
I now had some time and here are few lines to help me kick this problem in the dirt for good.

So here is a way to set the nicteamingpolicy for the vswitchs

get-cluster $cluster | get-vmhost | get-virtualswitch -Name $vss1,$vss2 | Get-NicTeamingPolicy | Set-NicTeamingPolicy -LoadBalancingPolicy LoadBalanceIP

obviously all those words with the $ sign are the variables.
Now how should i check this then? well it is pretty simple and straight forward

get-cluster $cluster | get-vmhost | get-virtualswitch -Name $vss1,$vss2 | Get-NicTeamingPolicy | select VirtualSwitch, LoadBalancingPolicy

Earlier i was saying about the portgroups and how me missing it on them was always a messy headache (headaches are always kinda messy). So let us set the values there too

get-cluster $cluster | get-vmhost | get-virtualswitch -Name $vss1,$vss2 | get-virtualportgroup -Name * | Get-NicTeamingPolicy | Set-NicTeamingPolicy -LoadBalancingPolicy LoadBalanceIP

Let us now check the loadbalancing on these portgroups
get-cluster $cluster | get-vmhost | get-virtualswitch -Name $vss1,$vss2 | get-virtualportgroup -Name * | Get-NicTeamingPolicy | select VirtualPortGroup, LoadBalancingPolicy


Here is the complete script.

<#
.SYNOPSIS
   This will set the ip hashing on the mentioned vswtchs.
.DESCRIPTION
   You have to mention the name of the cluster and vswitchs for it to change the load balancing to ip hash.
.NOTES
    File Name      : IPhash.ps1
    Author         : gajendra d ambi
    Date           : October 2015
    Prerequisite   : PowerShell V3, powercli 5+ over Vista and upper.
    Copyright      - None
.LINK
    Script posted over: github.com/gajuambi/vmware
   
#>

#Start of script
#Variables
$vc=read-host "target vcenter address?"
$user=read-host "username of the vcenter?"
$pass=read-host "password of the vcenter?"
$cluster=read-host "name of the cluster?"
$vss1=read-host "name of the 1st vswitch?"
$vss2=read-host "name of the 2nd vswitch?"

#connect to the vcenter
connect-viserver $vc -user root -Password VMwar3!!

#set nicteamingpolicy for the vswitchs to ip hash
get-cluster $cluster | get-vmhost | get-virtualswitch -Name $vss1,$vss2 | Get-NicTeamingPolicy | Set-NicTeamingPolicy -LoadBalancingPolicy LoadBalanceIP

#get nicteamingpolicy for the vswitchs
get-cluster $cluster | get-vmhost | get-virtualswitch -Name $vss1,$vss2 | Get-NicTeamingPolicy | select VirtualSwitch, LoadBalancingPolicy

#set nicteamingpolicy for the portgroups to ip hash
get-cluster $cluster | get-vmhost | get-virtualswitch -Name $vss1,$vss2 | get-virtualportgroup -Name * | Get-NicTeamingPolicy | Set-NicTeamingPolicy -LoadBalancingPolicy LoadBalanceIP

#get nicteamingpolicy for the portgroups
get-cluster $cluster | get-vmhost | get-virtualswitch -Name $vss1,$vss2 | get-virtualportgroup -Name * | Get-NicTeamingPolicy | select VirtualPortGroup, LoadBalancingPolicy

#End of script


Wednesday, October 7, 2015

vsphere HA host partition issue

So if you see one of your host being on a different network than the other (network partition) then i am pretty sure you might have googled for the below articles
http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1002117
http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2033250
but hey wait, before you try that you might want to take a look at this.
So, I recently came across this situation and the above articles did not help. Usually the partition of the network means the there usually 2 different sets of hosts in a cluster which cannot failover to other sets of hosts. hosts in partition 1 cannot fail over VMs to partition 2 and vice versa. This usually means that the host which is on different partition (or with that error) has different network settings than the other for communicating with other hosts in the cluster but it does not necessarily means that this is the one which needs fixing and that is exactly what was true in my case. the other host which had no partition error had its vmk management load balancing was set to virtual port ID where as it should have been ip hashing and when i changed it on this host the error on the other host vanished automagically. I hope this helps, just make sure the network settings (vswitch, portgroup settings) are identical across the cluster. In future when you want to set the load balancing across a cluster i suggest you use powercli to loop it across the portgroups, vswitchs and hosts so that you won't miss on any one of them, otherwise you are doomed to face this error.