Thursday, 28 July 2016

Isolating vSphere Replication Traffic

One of the new great features of vSphere Replication 6 is traffic isolation, which significantly enhances security and facilitates QoS using Network I/O Control feature.

Even though TCP/IP stacks are not useful for moving vSphere Replication traffic to separate network it is not too difficult to achieve the same result using static routes.

In this post I will show the different types of vSphere Replication traffic flows and will explain how to achieve full isolation of the replication traffic from management network.

Thursday, 14 July 2016

Automating configuration of a scratch location with PowerCLI

Quite often the modern ESXi servers come with no local storage and ESXi is normally installed on SD card.

As per VMware KB1033696 the SD card can't be used to store scratch partition. The main purpose of the scratch partition is to store logging files and to provide space for vm-support output.

So, the normal practice is to use shared storage (VMFS/NFS) as a scratch location. The problem is that the configuration of the scratch location is not automated in the existing vSphere. So you have to manually create folder for each of the ESXi host and configure each ESXi host to use that folder.
This can be quite time-consuming and boring tasks when you have to do it for hundred of servers.
To make things worse Host Profiles do not let you configure scratch location too.

I had some time last week and thought it was a good chance to have fun with PowerCLI and automate the scratch configuration for ESXi hosts.

So here is overview of what the script does:

  1. Connects to vCenter
  2. Collects the list of ESXi hosts in the cluster. Very often storage is not shared across multiple compute clusters so I decided to use cluster, not a datacenter, as a configuration target.
  3. Checks if there is a designated scratch folder for each of the clusters and creates if it doesn't exist
  4. Checks if the ESXi host configured with scratch location and if it points to the right datastore and folder.
  5. If ESXi is not configured yet or points to the wrong directory the correct setting will be applied.
  6. Provides a list of the ESXi servers to be rebooted for the configuration change to take effect

There are a couple of thing you have to do before running the script:
  • Identify the datastore to be used to store scratch folders
  • In that datastore create a folder where the script will create a scratch folder per each host 

 The syntax is as following:

.\scratch.ps1 -vCenter vCenter_Name -cluster Cluster_Name -datastore Datastore_Name -folder Folder_Name
for example

.\scratch.ps1 -vCenter lab-vc-01.lab.local -cluster HA -datastore ISO -folder Scratch
* I had to add folder as input parameter because I couldn't make the script land into the correct folder with New-PSdrive commandlet

You can go even further by taking advantage of Windows Task Scheduler to run this script on a daily basis to ensure all servers are consistently configured.

Let me know how it worked for you.

#Collect the vCenter, Cluster and scratch_datastore
Param([String]$vCenter, [String]$Cluster, [String]$Datastore, [String]$Folder)
#Function to use multiple colors in one command
function Write-Color([String[]]$Text, [ConsoleColor[]]$Color) {
for ($i = 0; $i -lt $Text.Length; $i++) {
Write-Host $Text[$i] -Foreground $Color[$i] -NoNewLine
}
Write-Host
}
#defining array variables
$vmhost_array =@()
$dir = @()
$reboot_servers = @()
#Validating input
if (!$vCenter){
Write-Color -Text "Please provide valid vCenter name using ","'-vCenter' ","option, exiting.." -Color Gray,Red,Gray
exit
}
if (!$Cluster){
Write-Color -Text "Please provide valid cluster name using ","'-Cluster' ","option, exiting.." -Color Gray,Red,Gray
exit
}
if (!$Datastore){
Write-Color -Text "Please provide valid Datastore name using ","'-Datastore' ","option, exiting.." -Color Gray,Red,Gray
exit
}
if (!$Folder){
Write-Color -Text "Please provide valid scratch folder name using ","'-Folder' ","option, exiting.." -Color Gray,Red,Gray
exit
}
cls
#Getting the path of the script
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
#Collecting credentials for vCenter
do {$user = Read-Host -Prompt 'Enter username for vCenter'
$pass = Read-Host -AsSecureString -Prompt 'Enter password for vCenter'
$cont = Read-Host -Prompt 'Type y to continue'}
while ($cont -ne 'y')
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $pass
#Connecting to vCenter server
Write-Color -Text "`nConnecting to ", $vCenter -Color Gray, Red
Connect-VIserver -Server $vCenter -Credential $cred | Out-Null
#Validating connection to vCenter
if(!$DefaultVIServers){
Write-Color -Text "`nConnection to ",$vCenter," failed, exiting.." -Color Yellow,Red,Yellow
exit
} elseif($DefaultVIServer.name -ne $vCenter){
Write-Color -Text "Connected to wrong vCenter ", $DefaultVIServer.name ", exiting.." -Color Yellow,Red,Yellow
} else {
Write-Color -Text "Connection to vCenter ", $vCenter, " succeeded" -Color Green,Red,Green
Write-Host
}
#Getting the list of the ESXi hosts in the $Cluster
$vmhost_array = get-cluster -name $cluster | Get-VMhost
#Getting Scratch datastore UUID
$ds_view = Get-View (Get-View (Get-VMHost -Name $vmhost_array[0]).ID).ConfigManager.StorageSystem
foreach ($vol in $ds_view.FileSystemVolumeInfo.MountInfo) {
if ($vol.Volume.Name -eq $datastore) {
$datastore_uuid = $vol.Volume.Uuid
}
}
#Mounting datastore to be used as a scratch location
New-PSDrive -Name "DS" -Root \ -PSProvider VimDatastore -Datastore (Get-VMHost -Name $vmhost_array[0] | Get-Datastore $datastore) | out-null
Set-Location DS:\$folder
#Collect the list of the folders
$dir = dir
#Check if the scratch folders exist for the ESXi hosts and create missing folders
Foreach ($vmhost in $vmhost_array)
{
If ($dir.name -contains $vmhost.name){
Continue
}
else{
Write-Color -Text "`n Creating scratch folder for ", $vmhost -Color Green,Red
mkdir $vmhost | out-null
}
}
#Check if the ESXi host is already configured with correct scratch location
Foreach ($vmhost in $vmhost_array){
$row = '' | Select Server_Name
$configured_scratch = (Get-VMhost $vmhost | Get-AdvancedSetting -Name "ScratchConfig.ConfiguredScratchLocation").value
$current_scratch = (Get-VMhost $vmhost | Get-AdvancedSetting -Name "ScratchConfig.CurrentScratchLocation").value
$correct_scratch = "/vmfs/volumes/"+$datastore_uuid+"/"+$folder+"/"+$vmhost
# Write-Host "`n Correct scratch is" $correct_scratch
# Write-Host "`n Configured Scratch on" $vmhost "is" $configured_scratch
# Write-Host "`n Current Scratch on" $vmhost "is" $current_scratch
If (($configured_scratch -eq $correct_scratch) -and ($current_scratch -eq $correct_scratch)) {
Write-Color -Text "`n ESXi host ", $vmhost, " was already configured with the correct scratch location" -Color Green,Red,Green
} elseif($configured_scratch -eq $correct_scratch) {
Write-Color -Text "`n The ESXi host", $vmhost, " was already configured correctly, `n but it hasn't been restared after the configuration change" -Color Yellow,Red,Yellow
$row.Server_Name = $vmhost.Name
$reboot_servers += $row
} else {
Get-VMhost $vmhost | Get-AdvancedSetting -Name "ScratchConfig.ConfiguredScratchLocation" |Set-AdvancedSetting -Value $correct_scratch -Confirm:$false |out-null
Write-Host -Fore:Red "`n ESXi host" $vmhost "is configured with the correct scratch location"
$row.Server_Name = $vmhost.Name
$reboot_servers += $row
}
}
#Provide output with the list of ESXi servers to be rebooted for the configration change to take effect
Write-Host -Fore:Green "`n The configuration of the scratch location for ESXi servers in cluster" $cluster "is complete"
Write-Host -Fore:Green "`n The following ESXi hosts have to be rebooted for the configuration change to take effect:"
foreach ( $server in $reboot_servers ) {
Write-Host -Fore:Red `n $server.Server_Name
}
#Exporting the list of ESXi hosts to be rebooted
$exportfilename = "Servers_to_reboot.csv"
$exportfilepath = Join-Path -Path $scriptPath -ChildPath $exportFileName
$reboot_servers | Export-Csv -Path $exportFilePath -NoTypeInformation -Force
Write-Host "`n This list of these servers has also been exported to" $exportfilepath
#Change location back to original
Set-Location $scriptPath
#Disconnecting from vCenter
Disconnect-viserver -Confirm:$false
view raw scratch.ps1 hosted with ❤ by GitHub

Friday, 8 July 2016

vSphere Distributed Switch and Nexus 1000v comparison


Choosing between VMware and Cisco virtual switch products is not an easy tasks as it includes not only side-by-side feature comparison, but also numerous aspects of duty separations, operational overhead, current skill set and expertise. And not all of them can be compared directly. 

Apart from all that it can be simply a political decision to a question "Who is going to manage virtual networks?". 

In this article I am trying to provide essential information on things to help you make the right decision for your infrastructure.