I'm running into a bit of a pickle trying to automate creation of VVol datastores. The problem seems to be that when a storage container is created, its not immediately available for use. The following code works fine if you wait a minute before the foreach loop, but I'd like to be a bit more deterministic. What I think should happen is I should query the vSphere MOB for the $scid content which shows up as the "backing storage container" when you go through the process of creating the VVol datastore through the web client. However, I can't, for the life of me, find how to find it. The final use will be for vRO, but the IDE there is painful, so mocking up with PowerCLI first.
#Create Storage Container via SF API call
$SFMethodArgs = @{}
$SFMethodArgs.Add("name",$VVolSCName)
$SFAPIResult = Invoke-SFApi -Method "CreateStorageContainer" -Params $SFMethodArgs
<#
The storageContainer ID is not in the format VMware wants it
SolidFire Return: a6af2b22-d468-4d89-b73a-3f53c7390da0
VMware wants: vvol:a6af2b22d4684d89-b73a3f53c7390da0
#>
$SFscid = $SFAPIResult.Values.storageContainerID
$t = $SFscid.Split("-")
$scid1 = -join ($t[0..2])
$scid2 = -join ($t[3..4])
$scid = "vvol:"+$scid1+"-"+$scid2
#Create the VVolDatastoreSpec
$spec = New-Object VMware.Vim.HostDatastoreSystemVvolDatastoreSpec
#Set the name and source ID for the VVol Datastore
$spec.name = $VVolDSName
$spec.scId = $scid
#Build the VMHost DatastoreSystem for all hosts so we can mount the VVol to each host
$VMhosts = Get-Cluster $vSphereCluster | Get-VMHost
#Create the VVol datastore on each host in the cluster
foreach ($VMhost in $VMHosts) {
$vmhostDS = get-view $vmhost.ExtensionData.ConfigManager.DatastoreSystem
$vmhostHDS = $vmhostDS.MoRef.ToString()
$_this = Get-View -Id $vmhostHDS
Write-Host "Creating VVol datastore $($VVolDSName) on $($vmhost)..." -ForegroundColor DarkGray -NoNewline
$_this.CreateVvolDatastore($spec)
}
I can get the required data using get-datastore, but that only works if a datastore has already been created. Chicken and egg problem there ;-) The data I want is the URL field.
$ds = get-vmhost "ts-vh-07.ts.local" | get-datastore vrotest3
$ds.ExtensionData.info
VvolDS : VMware.Vim.HostVvolVolume
Name : vrotest3
Url : ds:///vmfs/volumes/vvol:d0acdc04835844b2-999c2511136ea43e/
FreeSpace : 276546135785472
MaxFileSize : 8000000491520
MaxVirtualDiskCapacity : 8000000491520
MaxMemoryFileSize : 9223372036854775807
Timestamp : 3/23/2017 4:10:28 PM
ContainerId :
get-datastore will give me the data I need, but only works for storage containers that have already had a VVol datastore bound to them.
Any help would be appreciated.