Create new vVol datastore on Flasharray
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[CmdletBinding()] | |
Param( | |
[Parameter(Position=0,mandatory=$true,ValueFromPipeline=$True)] | |
[VMware.VimAutomation.ViCore.Types.V1.Inventory.Cluster]$Cluster, | |
[Parameter(Position=1,mandatory=$true)] | |
[string]$FlashArray, | |
[Parameter(Position=2,ValueFromPipeline=$True,mandatory=$true)] | |
[System.Management.Automation.PSCredential]$Credentials, | |
[Parameter(Position=3,mandatory=$true)] | |
[string]$DatastoreName | |
) | |
import-module PureStoragePowerShellSDK2 | |
$FlashArray = Connect-Pfa2Array -EndPoint $FlashArray -Credential $Credentials -IgnoreCertificateError | |
Write-Host "Creating pod named $($DatastoreName)..." | |
$pod = New-Pfa2Pod -Name $DatastoreName | |
Write-Host "Creating protocol endpoint..." | |
$pe = New-Pfa2Volume -Name $($pod.name + "::" + $pod.name +"PE") -Subtype protocol_endpoint | |
$esxiHosts = $cluster |Get-VMHost | |
$fahosts = Get-Pfa2Host | |
Write-Host "Finding host group for cluster named $($Cluster.name)..." | |
foreach ($esxiHost in $esxiHosts) | |
{ | |
$iscsiadapter = $esxi | Get-VMHostHBA -Type iscsi | Where-Object {$_.Model -eq "iSCSI Software Adapter"} | |
$wwns = $esxi | Get-VMHostHBA -Type FibreChannel | Select-Object VMHost,Device,@{N="WWN";E={"{0:X}" -f $_.PortWorldWideName}} | Format-table -Property WWN -HideTableHeaders |out-string | |
$wwns = (($wwns.Replace("`n","")).Replace("`r","")).Replace(" ","") | |
$wwns = &{for ($i = 0;$i -lt $wwns.length;$i += 16) | |
{ | |
$wwns.substring($i,16) | |
}} | |
if ($null -ne $iscsiadapter) | |
{ | |
$iqn = $iscsiadapter.ExtensionData.IScsiName | |
foreach ($fahost in $fahosts) | |
{ | |
if ($fahost.iqns.count -ge 1) | |
{ | |
foreach ($fahostiqn in $fahost.iqns) | |
{ | |
if ($iqn.ToLower() -eq $fahostiqn.ToLower()) | |
{ | |
$faHostGroup = $fahost.HostGroup | |
break | |
} | |
} | |
} | |
if ($null -ne $faHostGroup) | |
{ | |
break | |
} | |
} | |
} | |
if (($null -ne $wwns) -and ($null -eq $faHostGroup)) | |
{ | |
foreach ($wwn in $wwns) | |
{ | |
foreach ($fahost in $fahosts) | |
{ | |
if ($fahost.wwns.count -ge 1) | |
{ | |
foreach($fahostwwn in $fahost.wwns) | |
{ | |
if ($wwn.ToLower() -eq $fahostwwn.ToLower()) | |
{ | |
$faHostGroup = $fahost.HostGroup | |
break | |
} | |
} | |
if ($null -ne $faHostGroup) | |
{ | |
break | |
} | |
} | |
if ($null -ne $faHostGroup) | |
{ | |
break | |
} | |
} | |
if ($null -ne $faHostGroup) | |
{ | |
break | |
} | |
} | |
} | |
if ($null -ne $faHostGroup) | |
{ | |
break | |
} | |
} | |
Write-Host "Connecting PE to host group named $($faHostGroup.name)..." | |
New-Pfa2Connection -HostGroupNames $faHostGroup.Name -VolumeNames $pe.Name |Out-Null | |
Write-Host "Refreshing VASA Provider container list..." | |
Get-VasaProvider -id (Get-VasaStorageArray -Id ("com.purestorage:" + (Get-Pfa2Array).id)).provider.id -Refresh | |
Write-Host "Mounting vVol Storage Container as a vVol datastore to cluster named $($Cluster.Name)..." | |
foreach ($esxi in $esxiHosts) | |
{ | |
Write-Host "Mounting on ESXi host $($esxi.NetworkInfo.HostName)..." | |
$datastoreSystem = Get-View -Id $esxi.ExtensionData.ConfigManager.DatastoreSystem | |
$spec = New-Object VMware.Vim.HostDatastoreSystemVvolDatastoreSpec | |
$spec.Name = $DatastoreName | |
$spec.ScId = ($("vvol:" + ($pod.id).replace("-",""))).insert(21,"-") | |
$foundDatastore = $esxi |get-datastore |Where-Object {$_.Type -eq "VVol"} |Where-Object {$_.ExtensionData.Info.VVolds.Scid -eq $spec.ScId} | |
if ($null -eq $foundDatastore) | |
{ | |
$datastore = Get-Datastore -Id ($datastoreSystem.CreateVvolDatastore($spec)) | |
} | |
} | |
return $datastore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment