VMware Cloud Community
nmbgdc
Enthusiast
Enthusiast

How do I check the Cluster Capacity to put the host in maintenance mode?

Hi Guys,

I am trying to write the script to check the available capacity in cluster before putting the host in maintenance mode so that all VM can be vMotion in cluster successfully, but i don't know the correct parameter though I have written the below code and  I am not sure whether this will work in case of memory over commitment clusters.

Here is the script

param(
[String] $vcenter_host,
[String] $vcenter_username,
[String] $vcenter_password,
[String] $cluster_name,
[String] $source_host
)


Connect-VIServer -Server $vcenter_fqdn -User $vcenter_username -Pass $vcenter_password -Force >$null
##Clusters Host's Total Memory except the source host
$vmhost = get-cluster $cluster_name | Get-VMhost | sort-object name
$totalmem = [math]::Round(($vmhost | ?{$_.name -ne $source_host} | Measure-Object -Property MemoryTotalGB -sum).sum,2)
write-host Total cluster Memory is $totalmem

##clsuters Host's Usage Memory
$totalusage = [math]::Round(($vmhost | Measure-Object -Property MemoryUsageGB -sum).sum,2)
write-host Total cluster memory is used $totalusage

##Check clsuters Host's Free Memory
$totalclrfreemem = $totalmem - $totalusage
write-host Total cluster free memory available $totalclrfreemem

##Source Host Memory Usage
$shm =(get-cluster $cluster_name | Get-VMHost $source_host).MemoryUsageGB
$totalsrcusagemem = $shm - 8
write-host Total source used memory $totalsrcusagemem

##Check if source VMs capcicity can accomodate in cluster Incase of vMotion
if ($totalclrfreemem -gt $totalsrcusagemem -or $totalclrfreemem -eq $totalsrcusagemem) {
write-host Cluster Capacity is available to migrate the source Host VMs
break }
else {
write-host Cluster Capacity is not available to migrate the source Host VMs
break
}


0 Kudos
2 Replies
LucD
Leadership
Leadership

No, this will not work in the case of memory overcommitment.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

nmbgdc
Enthusiast
Enthusiast

Thanks for your reply.

So any pointers which will work incase of memory over commitment.

 

Thanks

 

0 Kudos