Category Archives: VSAN

Retrieving NVMe details through PowerCLI

Recently I was contacted and asked if there was a way to retrieve information about the NVMe Drives in an ESXi host, this information is easily accessible via ESXCLI using the “nvme” namespaces.

Through PowerCLI this can be easily called and then each feature can be called under this namespace to give you detailed information on the NVMe devices in your ESXi host.  The reason they wanted to do this was to first check the firmware on all the NVMe devices in a cluster to see if they are at the latest revision.  Another reason they wanted this script was in case one of the NVMe devices was behaving differently than the others it would be an easy way to compare the devices.

You can see an example of the script running below:

Continue reading Retrieving NVMe details through PowerCLI

Automating the VSAN HCL with PowerCLI

Recently I was contacted by a customer who needed to be able to update their VSAN Hardware Compatibility List in the VSAN Health Check but was unable to do so via the GUI as their vCenter servers did not have internet access.

This is a common setup as a lot of customers clearly do not want their Server infrastructure having a direct connection to the internet due to strict security requirements. The problem is when the vCenter server needs to update the VSAN HCL database file it requires a connection to the internet to do this. Whats more, this specific customer had several VCs and was getting quite frustrated with the warning that the HCL database had not been updated. Rather than turning this feature off the customer was looking for a way to update the HCL from a computer that had internet access – his desktop.

New in PowerCLI 6.5 (backwards compatible to previous versions) is a cmdlet that will help us achieve this… Update-VSANHCLDatabase, as you can see from the below image this can be run either grabbing the database information directly from the internet or if you add the “FilePath” parameter you can load the database locally.

Continue reading Automating the VSAN HCL with PowerCLI

Creating a manual VSAN Cluster with PowerCLI

In my previous post I showed how to create a datacenter, cluster, add hosts and create an automatic VSAN cluster allowing for the local SSDs and HDDs to be added to a new VSAN datastore, check it out here.

But what if you wanted to create a manual VSAN cluster and select the disks to add to the VSAN Diskgroup to create the datastore, this gives more control and allows for a precisely configured environment making the most of local resources and perhaps saving other disks for further use and alternate features.

In the below code you can see that instead of automatic we can easily set the cluster to manual and add the disks ourselves, with my code I have selected the disks I want to use as all blank SSDs and all HDDs but you could easily use PowerCLI to define the make, model, size or other factors to use before creating the diskgroup and manually adding the SSDs and HDDs.

Output

SNAGHTML15bb0de

The script

import-module VMware.VimAutomation.Extensions
Connect-VIServer 172.16.78.191 -User root -Password vmware
$Datacenter = "DC01"
$Cluster = "VSAN Cluster"
$ESXHosts = "172.16.78.129", "172.16.78.130"
$ESXUser = "root"
$ESXPWD = "vmware"
$VMKNetforVSAN = "Management Network"

# If doesnt exist create the datacenter
If (-Not ($NewDatacenter = Get-Datacenter $Datacenter -ErrorAction SilentlyContinue)){ 
	Write-Host "Adding $Datacenter"
	$NewDatacenter = New-Datacenter -Name $Datacenter -Location (Get-Folder Datacenters) 
}

# Create the initial cluster
if (-Not ($NewCluster = Get-Cluster $Cluster -ErrorAction SilentlyContinue)) { 
	Write-Host "Adding $Cluster"
	$NewCluster = New-Cluster -Name $Cluster -Location $NewDatacenter 
}

# For each of our hosts
$ESXHosts | Foreach {
	Write-Host "Adding $($_) to $($NewCluster)"
	# Add them to the cluster
	$AddedHost = Add-VMHost -Name $_ -Location $NewCluster -User $ESXUser -Password $ESXPWD -Force
	# Check to see if they have a VSAN enabled VMKernel
	$VMKernel = $AddedHost | Get-VMHostNetworkAdapter -VMKernel | Where {$_.PortGroupName -eq $VMKNetforVSAN }
	$IsVSANEnabled = $VMKernel | Where { $_.VsanTrafficEnabled}
	# If it isnt Enabled then Enable it
	If (-not $IsVSANEnabled) {
		Write-Host "Enabling VSAN Kernel on $VMKernel"
		$VMKernel | Set-VMHostNetworkAdapter -VsanTrafficEnabled $true -Confirm:$false | Out-Null
	} Else {
		Write-Host "VSAN Kernel already enabled on $VmKernel"
		$IsVSANEnabled | Select VMhost, DeviceName, IP, PortGroupName, VSANTrafficEnabled
	}
}
# Enable VSAN on the cluster and set to Automatic Disk Claim Mode
Write-Host "Enabling VSAN on $NewCluster"
$VSANCluster = $NewCluster | Set-Cluster -VsanEnabled:$true -VsanDiskClaimMode Manual -Confirm:$false -ErrorAction SilentlyContinue

$ESXHosts | Foreach {
	Write-Host "Finding disks for $($_)"
	# Find the blank SSDs for the current host
	$disks = Get-VMHost $_ | Get-VMHostDisk
	$SSDs = $disks | Where { $_.scsilun.extensiondata.ssd }
	$BlankSSDs = $SSDs | Where { -not $_.Extensiondata.Layout.Partition[0].partition }
	Write-Host "Blank SSDs"
	$BlankSSDsArray = ""
	$BlankSSDs | Foreach { $BlankSSDsArray += $_.scsilun.CanonicalName }
	$BlankSSDsArray
	
	# Find the blank Magnetic disks for the current host
	$HDDs = $disks | Where { -not $_.scsilun.extensiondata.ssd }
	$BlankHDDs = $HDDs | Where { -not $_.Extensiondata.Layout.Partition[0].partition }
	Write-Host "Blank HDDs"
	$BlankHDDsArray = ""
	$BlankHDDs | Foreach { $BlankHDDsArray += $_.scsilun.CanonicalName }
	$BlankHDDsArray
	
	New-VsanDiskGroup -VMHost $_ -SSDCanonicalName $BlankSSDsArray -DataDiskCanonicalName $BlankHDDsArray | Out-Null
}

If ($VSANCluster.VSANEnabled){
	Write-Host "VSAN cluster $($VSANCLuster.Name) created in $($VSANCluster.VSANDiskClaimMode) configuration"
	Write-Host "The following Hosts and Disk Groups now exist:"
	Get-VsanDiskGroup | Select VMHost, Name | FT -AutoSize
	Write-Host "The following VSAN Datastore now exists:"
	Get-Datastore | Where {$_.Type -eq "vsan"} | Select Name, Type, FreeSpaceGB, CapacityGB
} Else {
	Write-Host "Something went wrong, VSAN not enabled"
}

Creating a VSAN Cluster with PowerCLI

Recently there was a new fling released on the VMware Flings site, this enables us to use VSAN and VMware Flash Read Cache with PowerCLI, check out the site here for more details.

I wrote a post on the PowerCLI Blog which showed the cmdlets and some examples on how you might use these, recently I had the chance to put them to use when I needed to stand up a new VSAN cluster, I was able to easily build myself a test cluster with the help of Williams post here.

Once I had a couple of hosts and my fresh vCenter server, I used the following script to setup the Datacenter, Cluster, add the hosts, enable the VSAN VMKernel port and enable VSAN in automatic mode.  The cmdlets are very easy to use and I was amazed at how easy and quick it is to setup VSAN.

Output

VSAN

The script

import-module VMware.VimAutomation.Extensions
Connect-VIServer 172.16.78.191 -User root -Password vmware
$Datacenter = "DC01"
$Cluster = "VSAN Cluster"
$ESXHosts = "172.16.78.129", "172.16.78.130"
$ESXUser = "root"
$ESXPWD = "vmware"
$VMKNetforVSAN = "Management Network"

# If doesnt exist create the datacenter
If (-Not ($NewDatacenter = Get-Datacenter $Datacenter -ErrorAction SilentlyContinue)){ 
	Write-Host "Adding $Datacenter"
	$NewDatacenter = New-Datacenter -Name $Datacenter -Location (Get-Folder Datacenters) 
}

# Create the initial cluster
if (-Not ($NewCluster = Get-Cluster $Cluster -ErrorAction SilentlyContinue)) { 
	Write-Host "Adding $Cluster"
	$NewCluster = New-Cluster -Name $Cluster -Location $NewDatacenter 
}

# For each of our hosts
$ESXHosts | Foreach {
	Write-Host "Adding $($_) to $($NewCluster)"
	# Add them to the cluster
	$AddedHost = Add-VMHost -Name $_ -Location $NewCluster -User $ESXUser -Password $ESXPWD -Force
	# Check to see if they have a VSAN enabled VMKernel
	$VMKernel = $AddedHost | Get-VMHostNetworkAdapter -VMKernel | Where {$_.PortGroupName -eq $VMKNetforVSAN }
	$IsVSANEnabled = $VMKernel | Where { $_.VsanTrafficEnabled}
	# If it isnt Enabled then Enable it
	If (-not $IsVSANEnabled) {
		Write-Host "Enabling VSAN Kernel on $VMKernel"
		$VMKernel | Set-VMHostNetworkAdapter -VsanTrafficEnabled $true -Confirm:$false | Out-Null
	} Else {
		Write-Host "VSAN Kernel already enabled on $VmKernel"
		$IsVSANEnabled | Select VMhost, DeviceName, IP, PortGroupName, VSANTrafficEnabled
	}
}
# Enable VSAN on the cluster and set to Automatic Disk Claim Mode
Write-Host "Enabling VSAN on $NewCluster"
$VSANCluster = $NewCluster | Set-Cluster -VsanEnabled:$true -VsanDiskClaimMode Automatic -Confirm:$false -ErrorAction SilentlyContinue
If ($VSANCluster.VSANEnabled){
	Write-Host "VSAN cluster $($VSANCLuster.Name) created in $($VSANCluster.VSANDiskClaimMode) configuration"
	Write-Host "The following Hosts and Disk Groups now exist:"
	Get-VsanDiskGroup | Select VMHost, Name | FT -AutoSize
	Write-Host "The following VSAN Datastore now exists:"
	Get-Datastore | Where {$_.Type -eq "vsan"} | Select Name, Type, FreeSpaceGB, CapacityGB
} Else {
	Write-Host "Something went wrong, VSAN not enabled"
}