From 5506da595e6a57f8c4e7aeecab8d28d6c1ffc1f8 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 13 Jan 2025 13:01:16 +0530 Subject: [PATCH 1/4] Resize VMFS based Esan datastore --- Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psd1 | 1 + Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 | 62 ++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psd1 b/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psd1 index e635a9e..1c86f99 100644 --- a/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psd1 +++ b/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psd1 @@ -72,6 +72,7 @@ "Set-VmfsStaticIscsi", "New-VmfsDatastore", "Dismount-VmfsDatastore", + "Resize-ElasticSANDatastore", "Resize-VmfsVolume", "Restore-VmfsVolume", "Sync-VMHostStorage", diff --git a/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 b/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 index b5dc191..e971dff 100644 --- a/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 +++ b/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 @@ -453,6 +453,68 @@ function Dismount-VmfsDatastore { } } +<# + .DESCRIPTION + Expand existing ElasticSAN Datastore to new size. + + .PARAMETER ClusterName + Cluster name + + .PARAMETER DatastoreName + Datastore name + + .EXAMPLE + Resize-ElasticSANDatastore -ClusterName "myCluster" -DatastoreName "myDatastore" + + .INPUTS + vCenter cluster name and datastore name. + + .OUTPUTS + None. +#> +function Resize-ElasticSANDatastore { + [CmdletBinding()] + [AVSAttribute(10, UpdatesSDDC = $false, AutomationOnly = $true)] + Param ( + [Parameter( + Mandatory=$true, + HelpMessage = 'Cluster name in vCenter')] + [ValidateNotNull()] + [String] + $ClusterName, + + [Parameter( + Mandatory=$true, + HelpMessage = 'Name of ElasticSAN datastore to be expanded in vCenter')] + [ValidateNotNull()] + [String] + $DatastoreName + ) + + $Cluster = Get-Cluster -Name $ClusterName -ErrorAction Ignore + if (-not $Cluster) { + throw "Cluster $ClusterName does not exist." + } + + $Datastore = Get-Datastore -Name $DatastoreName -ErrorAction Ignore + if (-not $Datastore) { + throw "Datastore $DatastoreName does not exist." + } + + if ($Datastore.Type -ne "VMFS") { + throw "Datastore $DatastoreName is of type $($Datastore.Type). This cmdlet can only process ElasticSAN (VMFS) datastores." + } + + $NaaID = $Datastore.ExtensionData.Info.Vmfs.Extent.DiskName + if (-not $NaaID) { + throw "Failed to get NAA ID for datastore $DatastoreName." + + } + + Write-Host "Resizing ElasticSAN datastore $DatastoreName..." + Resize-VmfsVolume -ClusterName $ClusterName -DeviceNaaId $NaaID +} + <# .DESCRIPTION Expand existing VMFS volume to new size. From 391951e1123268284ff507dd8041deef16b9534b Mon Sep 17 00:00:00 2001 From: root Date: Wed, 15 Jan 2025 16:36:29 +0530 Subject: [PATCH 2/4] expand esan volume --- Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 | 104 ++++++++++----------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 b/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 index e971dff..8ba0386 100644 --- a/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 +++ b/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 @@ -455,24 +455,24 @@ function Dismount-VmfsDatastore { <# .DESCRIPTION - Expand existing ElasticSAN Datastore to new size. + Expand existing VMFS volume to new size. .PARAMETER ClusterName Cluster name - .PARAMETER DatastoreName - Datastore name + .PARAMETER DeviceNaaId + NAA ID of device associated with the existing VMFS volume .EXAMPLE - Resize-ElasticSANDatastore -ClusterName "myCluster" -DatastoreName "myDatastore" - + Resize-VmfsVolume -ClusterName "myClusterName" -DeviceNaaId $DeviceNaaId + .INPUTS - vCenter cluster name and datastore name. + vCenter cluster name and device NAA ID. .OUTPUTS None. #> -function Resize-ElasticSANDatastore { +function Resize-VmfsVolume { [CmdletBinding()] [AVSAttribute(10, UpdatesSDDC = $false, AutomationOnly = $true)] Param ( @@ -485,56 +485,68 @@ function Resize-ElasticSANDatastore { [Parameter( Mandatory=$true, - HelpMessage = 'Name of ElasticSAN datastore to be expanded in vCenter')] + HelpMessage = 'NAA ID of device associated with the existing VMFS volume')] [ValidateNotNull()] [String] - $DatastoreName + $DeviceNaaId ) + if (-not $DeviceNaaId) { + throw "Invalid Device ID $DeviceNaaId provided." + } + $Cluster = Get-Cluster -Name $ClusterName -ErrorAction Ignore if (-not $Cluster) { throw "Cluster $ClusterName does not exist." } - $Datastore = Get-Datastore -Name $DatastoreName -ErrorAction Ignore - if (-not $Datastore) { - throw "Datastore $DatastoreName does not exist." + $Esxi = $Cluster | Get-VMHost | Where-Object { ($_.ConnectionState -eq 'Connected') } | Select-Object -last 1 + $Cluster | Get-VMHost | Get-VMHostStorage -RescanAllHba | Out-Null + $Datastores = $Esxi | Get-Datastore -ErrorAction stop + foreach ($Datastore in $Datastores) { + $CurrentNaaId = $Datastore.ExtensionData.Info.Vmfs.Extent.DiskName + if ($CurrentNaaId -eq $DeviceNaaId) { + $DatastoreToResize = $Datastore + break + } } - if ($Datastore.Type -ne "VMFS") { - throw "Datastore $DatastoreName is of type $($Datastore.Type). This cmdlet can only process ElasticSAN (VMFS) datastores." + if (-not $DatastoreToResize) { + throw "Failed to re-size VMFS volume." } - $NaaID = $Datastore.ExtensionData.Info.Vmfs.Extent.DiskName - if (-not $NaaID) { - throw "Failed to get NAA ID for datastore $DatastoreName." - + foreach ($DatastoreHost in $DatastoreToResize.ExtensionData.Host.Key) { + Get-VMHost -id "HostSystem-$($DatastoreHost.value)" | Get-VMHostStorage -RescanAllHba -RescanVmfs -ErrorAction Stop -WarningAction SilentlyContinue | Out-Null } - Write-Host "Resizing ElasticSAN datastore $DatastoreName..." - Resize-VmfsVolume -ClusterName $ClusterName -DeviceNaaId $NaaID + $Esxi = Get-View -Id ($DatastoreToResize.ExtensionData.Host | Select-Object -last 1 | Select-Object -ExpandProperty Key) + $DatastoreSystem = Get-View -Id $Esxi.ConfigManager.DatastoreSystem + $ExpandOptions = $DatastoreSystem.QueryVmfsDatastoreExpandOptions($DatastoreToResize.ExtensionData.MoRef) + + Write-Host "Increasing the size of the VMFS volume..." + $DatastoreSystem.ExpandVmfsDatastore($DatastoreToResize.ExtensionData.MoRef, $ExpandOptions[0].spec) } <# .DESCRIPTION - Expand existing VMFS volume to new size. + Expand existing ElasticSAN Datastore to new size. .PARAMETER ClusterName Cluster name - .PARAMETER DeviceNaaId - NAA ID of device associated with the existing VMFS volume + .PARAMETER DatastoreName + Datastore name .EXAMPLE - Resize-VmfsVolume -ClusterName "myClusterName" -DeviceNaaId $DeviceNaaId - + Resize-ElasticSANDatastore -ClusterName "myCluster" -DatastoreName "myDatastore" + .INPUTS - vCenter cluster name and device NAA ID. + vCenter cluster name and datastore name. .OUTPUTS None. #> -function Resize-VmfsVolume { +function Resize-ElasticSANDatastore { [CmdletBinding()] [AVSAttribute(10, UpdatesSDDC = $false, AutomationOnly = $true)] Param ( @@ -547,46 +559,34 @@ function Resize-VmfsVolume { [Parameter( Mandatory=$true, - HelpMessage = 'NAA ID of device associated with the existing VMFS volume')] + HelpMessage = 'Name of ElasticSAN datastore to be expanded in vCenter')] [ValidateNotNull()] [String] - $DeviceNaaId + $DatastoreName ) - if (-not $DeviceNaaId) { - throw "Invalid Device ID $DeviceNaaId provided." - } - $Cluster = Get-Cluster -Name $ClusterName -ErrorAction Ignore if (-not $Cluster) { throw "Cluster $ClusterName does not exist." } - $Esxi = $Cluster | Get-VMHost | Where-Object { ($_.ConnectionState -eq 'Connected') } | Select-Object -last 1 - $Cluster | Get-VMHost | Get-VMHostStorage -RescanAllHba | Out-Null - $Datastores = $Esxi | Get-Datastore -ErrorAction stop - foreach ($Datastore in $Datastores) { - $CurrentNaaId = $Datastore.ExtensionData.Info.Vmfs.Extent.DiskName - if ($CurrentNaaId -eq $DeviceNaaId) { - $DatastoreToResize = $Datastore - break - } + $Datastore = Get-Datastore -Name $DatastoreName -ErrorAction Ignore + if (-not $Datastore) { + throw "Datastore $DatastoreName does not exist." } - if (-not $DatastoreToResize) { - throw "Failed to re-size VMFS volume." + if ($Datastore.Type -ne "VMFS") { + throw "Datastore $DatastoreName is of type $($Datastore.Type). This cmdlet can only process ElasticSAN (VMFS) datastores." } - foreach ($DatastoreHost in $DatastoreToResize.ExtensionData.Host.Key) { - Get-VMHost -id "HostSystem-$($DatastoreHost.value)" | Get-VMHostStorage -RescanAllHba -RescanVmfs -ErrorAction Stop -WarningAction SilentlyContinue | Out-Null + $NaaID = [string]$Datastore.ExtensionData.Info.Vmfs.Extent.DiskName + if (-not $NaaID) { + throw "Failed to get NAA ID for datastore $DatastoreName." + } - $Esxi = Get-View -Id ($DatastoreToResize.ExtensionData.Host | Select-Object -last 1 | Select-Object -ExpandProperty Key) - $DatastoreSystem = Get-View -Id $Esxi.ConfigManager.DatastoreSystem - $ExpandOptions = $DatastoreSystem.QueryVmfsDatastoreExpandOptions($DatastoreToResize.ExtensionData.MoRef) - - Write-Host "Increasing the size of the VMFS volume..." - $DatastoreSystem.ExpandVmfsDatastore($DatastoreToResize.ExtensionData.MoRef, $ExpandOptions[0].spec) + Write-Host "Resizing ElasticSAN datastore $DatastoreName..." + Resize-VmfsVolume -ClusterName $ClusterName -DeviceNaaId $NaaID } <# From c80c4b53928eca6055bf95ba23ccd37f3fd007d6 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 15 Jan 2025 16:43:34 +0530 Subject: [PATCH 3/4] expand esan volume --- Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 b/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 index 8ba0386..49ff07f 100644 --- a/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 +++ b/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 @@ -529,7 +529,7 @@ function Resize-VmfsVolume { <# .DESCRIPTION - Expand existing ElasticSAN Datastore to new size. + Expand existing ElasticSAN Datastore to new size. .PARAMETER ClusterName Cluster name From 84cadf9e65d3735a7690b773a9b8690aa160c853 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 28 Jan 2025 13:46:16 +0530 Subject: [PATCH 4/4] added comment fixes --- Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psd1 | 2 +- Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psd1 b/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psd1 index 1c86f99..88fc485 100644 --- a/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psd1 +++ b/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psd1 @@ -72,7 +72,7 @@ "Set-VmfsStaticIscsi", "New-VmfsDatastore", "Dismount-VmfsDatastore", - "Resize-ElasticSANDatastore", + "Resize-iSCSIDatastore", "Resize-VmfsVolume", "Restore-VmfsVolume", "Sync-VMHostStorage", diff --git a/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 b/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 index 49ff07f..7e0c718 100644 --- a/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 +++ b/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 @@ -529,7 +529,7 @@ function Resize-VmfsVolume { <# .DESCRIPTION - Expand existing ElasticSAN Datastore to new size. + Expand existing iSCSI Datastore to new size. .PARAMETER ClusterName Cluster name @@ -538,7 +538,7 @@ function Resize-VmfsVolume { Datastore name .EXAMPLE - Resize-ElasticSANDatastore -ClusterName "myCluster" -DatastoreName "myDatastore" + Resize-iSCSIDatastore -ClusterName "myCluster" -DatastoreName "myDatastore" .INPUTS vCenter cluster name and datastore name. @@ -546,9 +546,9 @@ function Resize-VmfsVolume { .OUTPUTS None. #> -function Resize-ElasticSANDatastore { +function Resize-iSCSIDatastore { [CmdletBinding()] - [AVSAttribute(10, UpdatesSDDC = $false, AutomationOnly = $true)] + [AVSAttribute(10, UpdatesSDDC = $false)] Param ( [Parameter( Mandatory=$true, @@ -559,7 +559,7 @@ function Resize-ElasticSANDatastore { [Parameter( Mandatory=$true, - HelpMessage = 'Name of ElasticSAN datastore to be expanded in vCenter')] + HelpMessage = 'Name of iSCSI datastore to be expanded in vCenter')] [ValidateNotNull()] [String] $DatastoreName @@ -576,7 +576,7 @@ function Resize-ElasticSANDatastore { } if ($Datastore.Type -ne "VMFS") { - throw "Datastore $DatastoreName is of type $($Datastore.Type). This cmdlet can only process ElasticSAN (VMFS) datastores." + throw "Datastore $DatastoreName is of type $($Datastore.Type). This cmdlet can only process iSCSI datastores." } $NaaID = [string]$Datastore.ExtensionData.Info.Vmfs.Extent.DiskName @@ -585,7 +585,7 @@ function Resize-ElasticSANDatastore { } - Write-Host "Resizing ElasticSAN datastore $DatastoreName..." + Write-Host "Resizing iSCSI datastore $DatastoreName..." Resize-VmfsVolume -ClusterName $ClusterName -DeviceNaaId $NaaID }