Skip to content

Commit 71f809c

Browse files
committed
vVol core support
finished vVol cmdlets. VASA and vVol DS left.
1 parent 3212272 commit 71f809c

2 files changed

Lines changed: 33 additions & 230 deletions

File tree

PureStorage.FlashArray.VMware.VVol/PureStorage.FlashArray.VMware.VVol.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
NestedModules = @()
8383

8484
# Functions to export from this module
85-
FunctionsToExport = 'Get-PfaVvolVol','Update-PfaVvolVmVolumeGroup','Get-VvolUuidFromVmdk','Get-PfaVolumeNameFromVvolUuid','Get-PfaSnapshotFromVvolVmdk','Copy-PfaVvolVmdkToNewVvolVmdk','Copy-PfaSnapshotToExistingVvolVmdk','Copy-PfaSnapshotToNewVvolVmdk','Copy-PfaVvolVmdkToExistingVvolVmdk','New-PfaSnapshotOfVvolVmdk','Get-VmdkFromWindowsDisk','New-PfaVasaProvider','Get-PfaVasaProvider','Remove-PfaVasaProvider','Mount-PfaVvolDatastore','Initialize-PfaVVols'
85+
FunctionsToExport = 'Get-PfaVvolVol','Update-PfaVvolVmVolumeGroup','Get-VvolUuidFromVmdk','Get-PfaVolumeNameFromVvolUuid','Get-PfaSnapshotFromVvolVmdk','Copy-PfaVvolVmdkToNewVvolVmdk','Copy-PfaSnapshotToExistingVvolVmdk','Copy-PfaSnapshotToNewVvolVmdk','Copy-PfaVvolVmdkToExistingVvolVmdk','New-PfaSnapshotOfVvolVmdk','Get-VmdkFromWindowsDisk','New-PfaVasaProvider','Get-PfaVasaProvider','Remove-PfaVasaProvider','Mount-PfaVvolDatastore'
8686

8787
# Cmdlets to export from this module
8888
CmdletsToExport = '*'

PureStorage.FlashArray.VMware.VVol/PureStorage.FlashArray.VMware.VVol.psm1

Lines changed: 32 additions & 229 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ function Get-PfaVvolVol{
179179
Creation Date: 05/26/2019
180180
Purpose/Change: Updated for new connection mgmt
181181
.EXAMPLE
182-
PS C:\ New-PfaConnection -endpoint flasharray-m20-2 -credentials (get-credential) -defaultArray
183-
PS C:\ get-vm myVM | get-harddisk | Get-VvolUuidFromVmdk
182+
PS C:\ $fa = New-PfaConnection -endpoint flasharray-m20-2 -credentials (get-credential) -defaultArray
183+
PS C:\ Get-PfaVvolVol -vm (get-vm myVM) -flasharray $fa
184184
185-
Pass in one or more vVol hard disks and return the corresponding vVol UUIDs
185+
Returns the relevant vVol volumes on the array and their corresponding volume group
186186
187187
*******Disclaimer:******************************************************
188188
This scripts are offered "as is" with no warranty. While this
@@ -338,28 +338,8 @@ function Get-PfaVolumeNameFromVvolUuid{
338338
}
339339
foreach ($fa in $flasharray)
340340
{
341-
$faSession = new-PfaRestSession -flasharray $fa
342-
$purevip = $fa.EndPoint
343-
#Pull tags that match the volume with that UUID
344-
try {
345-
add-type @"
346-
using System.Net;
347-
using System.Security.Cryptography.X509Certificates;
348-
public class TrustAllCertsPolicy : ICertificatePolicy {
349-
public bool CheckValidationResult(
350-
ServicePoint srvPoint, X509Certificate certificate,
351-
WebRequest request, int certificateProblem) {
352-
return true;
353-
}
354-
}
355-
"@
356-
}
357-
Catch {}
358-
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
359-
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
360-
$volumeTags = Invoke-RestMethod -Method Get -Uri "https://$($purevip)/api/$($fa.apiversion)/volume?tags=true&filter=value='${vvolUUID}'" -WebSession $faSession -ErrorAction Stop
341+
$volumeTags = New-PfaRestOperation -resourceType "volume" -restOperationType GET -queryFilter "?tags=true&filter=value=`'$($vvolUUID)`'" -flasharray $fa -SkipCertificateCheck
361342
$volumeName = $volumeTags |where-object {$_.key -eq "PURE_VVOL_ID"}
362-
remove-PfaRestSession -faSession $faSession -flasharray $fa
363343
if ($null -eq $volumeName)
364344
{
365345
$Global:CurrentFlashArray = $null
@@ -428,17 +408,10 @@ function Get-PfaSnapshotFromVvolVmdk {
428408
{
429409
$fa = get-PfaConnectionOfDatastore -datastore $datastore -flasharrays $flasharray -ErrorAction Stop
430410
}
431-
$faSession = new-PfaRestSession -flasharray $fa
432-
$purevip = $fa.EndPoint
433411
$vvolUuid = Get-VvolUuidFromVmdk -vmdk $vmdk
434-
$faVolume = get-PfaVolumeNameFromVvolUuid -flasharray $fa -vvolUUID $vvolUuid
435-
$volumeSnaps = Invoke-RestMethod -Method Get -Uri "https://${purevip}/api/$($fa.apiversion)/volume/${faVolume}?snap=true" -WebSession $faSession -ErrorAction Stop
436-
$snapNames = @()
437-
foreach ($volumeSnap in $volumeSnaps)
438-
{
439-
$snapNames += $volumeSnap.name
440-
}
441-
return $snapNames
412+
$faVolume = get-PfaVolumeNameFromVvolUuid -flasharray $fa -vvolUUID $vvolUuid
413+
$volumeSnaps = New-PfaRestOperation -resourceType "volume/$($faVolume)" -restOperationType GET -queryFilter "?snap=true" -flasharray $fa -SkipCertificateCheck
414+
return $volumeSnaps.Name
442415
}
443416
function Copy-PfaVvolVmdkToNewVvolVmdk {
444417
<#
@@ -495,7 +468,7 @@ function Copy-PfaVvolVmdkToNewVvolVmdk {
495468
$newHardDisk = New-HardDisk -Datastore $datastore -CapacityGB $vmdk.CapacityGB -VM $targetVm
496469
$newVvolUuid = get-vvolUuidFromVmdk -vmdk $newHardDisk
497470
$newFaVolume = get-PfaVolumeNameFromVvolUuid -flasharray $fa -vvolUUID $newVvolUuid
498-
New-PfaVolume -Array $fa -Source $faVolume -Overwrite -VolumeName $newFaVolume |Out-Null
471+
New-PfaRestOperation -resourceType "volume/$($newFaVolume)" -restOperationType POST -flasharray $fa -jsonBody "{`"overwrite`":true,`"source`":`"$($faVolume)`"}" -SkipCertificateCheck -ErrorAction Stop |Out-Null
499472
return $newHardDisk
500473
}
501474
function Copy-PfaSnapshotToExistingVvolVmdk {
@@ -551,25 +524,20 @@ function Copy-PfaSnapshotToExistingVvolVmdk {
551524
}
552525
$vvolUuid = get-vvolUuidFromHardDisk -vmdk $vmdk
553526
$faVolume = get-PfaVolumeNameFromVvolUuid -flasharray $fa -vvolUUID $vvolUuid
554-
$foundSnap = Get-PfaVolumeSnapshot -Array $fa -SnapshotName $snapshotName
555-
if ($null -eq $foundSnap)
527+
$snapshotSize = New-PfaRestOperation -resourceType "volume/$($snapshotName)" -restOperationType GET -queryFilter "?snap=true&space=true" -flasharray $fa -SkipCertificateCheck
528+
if ($vmdk.ExtensionData.capacityinBytes -ne $snapshotSize.size)
556529
{
557-
throw "The snapshot either does not exist, or is not on the same array as the target vVol."
558-
}
559-
$snapshotSize = Get-PfaSnapshotSpaceMetrics -Array $fa -Name $snapshotName
560-
if ($vmdk.ExtensionData.capacityinBytes -eq $snapshotSize.size)
561-
{
562-
New-PfaVolume -Array $fa -Source $snapshotName -Overwrite -VolumeName $faVolume |Out-Null
563-
}
564-
elseif ($vmdk.ExtensionData.capacityinBytes -lt $snapshotSize.size) {
530+
if ($vmdk.ExtensionData.capacityinBytes -lt $snapshotSize.size)
531+
{
565532
$vmdk = Set-HardDisk -HardDisk $vmdk -CapacityKB ($snapshotSize.size / 1024) -Confirm:$false
566-
$vmdk = New-PfaVolume -Array $fa -Source $snapshotName -Overwrite -VolumeName $faVolume
567-
533+
}
534+
else
535+
{
536+
throw "The target vVol hard disk is larger than the snapshot size and VMware does not allow hard disk shrinking."
537+
}
568538
}
569-
else {
570-
throw "The target vVol hard disk is larger than the snapshot size and VMware does not allow hard disk shrinking."
571-
}
572-
return $vmdk
539+
New-PfaRestOperation -resourceType "volume/$($faVolume)" -restOperationType POST -flasharray $fa -jsonBody "{`"overwrite`":true,`"source`":`"$($snapshotName)`"}" -SkipCertificateCheck -ErrorAction Stop |Out-Null
540+
return ($datastore |Get-HardDisk |Where-Object {$_.FileName -eq $vmdk.Filename})
573541
}
574542
function Copy-PfaSnapshotToNewVvolVmdk {
575543
<#
@@ -641,19 +609,19 @@ function Copy-PfaSnapshotToNewVvolVmdk {
641609
catch {
642610
throw "You must either pass in a FlashArray, a vVol datastore, or configure a default FlashArray connection."
643611
}
644-
$arrayID = (Get-PfaArrayAttributes -Array $flasharray).id
612+
$arrayID = (New-PfaRestOperation -resourceType array -restOperationType GET -flasharray $flasharray -SkipCertificateCheck).id
645613
$datastore = $targetVm| Get-VMHost | Get-Datastore |where-object {$_.Type -eq "VVOL"} |Where-Object {$_.ExtensionData.info.vvolDS.storageArray[0].uuid.substring(16) -eq $arrayID} |Select-Object -First 1
646614
}
647615
elseif (($null -ne $flasharray) -and ($null -eq $datastore))
648616
{
649-
$arrayID = (Get-PfaArrayAttributes -Array $flasharray).id
617+
$arrayID = (New-PfaRestOperation -resourceType array -restOperationType GET -flasharray $flasharray -SkipCertificateCheck).id
650618
$datastore = $targetVm| Get-VMHost | Get-Datastore |where-object {$_.Type -eq "VVOL"} |Where-Object {$_.ExtensionData.info.vvolDS.storageArray[0].uuid.substring(16) -eq $arrayID} |Select-Object -First 1
651619
}
652-
$snapshotSize = Get-PfaSnapshotSpaceMetrics -Array $flasharray -Name $snapshotName -ErrorAction Stop
620+
$snapshotSize = New-PfaRestOperation -resourceType "volume/$($snapshotName)" -restOperationType GET -queryFilter "?snap=true&space=true" -flasharray $flasharray -SkipCertificateCheck
653621
$newHardDisk = New-HardDisk -Datastore $datastore -CapacityKB ($snapshotSize.size / 1024 ) -VM $targetVm
654622
$newVvolUuid = get-vvolUuidFromHardDisk -vmdk $newHardDisk
655623
$newFaVolume = get-PfaVolumeNameFromVvolUuid -flasharray $flasharray -vvolUUID $newVvolUuid
656-
New-PfaVolume -Array $flasharray -Source $snapshotName -Overwrite -VolumeName $newFaVolume |Out-Null
624+
New-PfaRestOperation -resourceType "volume/$($newFaVolume)" -restOperationType POST -flasharray $flasharray -jsonBody "{`"overwrite`":true,`"source`":`"$($snapshotName)`"}" -SkipCertificateCheck -ErrorAction Stop |Out-Null
657625
return $newHardDisk
658626
}
659627
function Copy-PfaVvolVmdkToExistingVvolVmdk {
@@ -735,17 +703,17 @@ function Copy-PfaVvolVmdkToExistingVvolVmdk {
735703
$sourceFaVolume = get-PfaVolumeNameFromVvolUuid -flasharray $targetFlasharray -vvolUUID $vvolUuid
736704
$vvolUuid = get-vvolUuidFromHardDisk -vmdk $targetVmdk
737705
$targetFaVolume = get-PfaVolumeNameFromVvolUuid -flasharray $targetFlasharray -vvolUUID $vvolUuid
738-
if ($targetVmdk.CapacityKB -eq $sourceVmdk.CapacityKB)
706+
if ($targetVmdk.CapacityKB -ne $sourceVmdk.CapacityKB)
739707
{
740-
New-PfaVolume -Array $targetFlasharray -Source $sourceFaVolume -Overwrite -VolumeName $targetFaVolume |Out-Null
741-
}
742-
elseif ($targetVmdk.CapacityKB -lt $sourceVmdk.CapacityKB) {
708+
if ($targetVmdk.CapacityKB -lt $sourceVmdk.CapacityKB)
709+
{
743710
$targetVmdk = Set-HardDisk -HardDisk $targetVmdk -CapacityKB $sourceVmdk.CapacityKB -Confirm:$false
744-
New-PfaVolume -Array $targetFlasharray -Source $sourceFaVolume -Overwrite -VolumeName $targetFaVolume |Out-Null
745-
}
746-
else {
711+
}
712+
else {
747713
throw "The target VVol hard disk is larger than the snapshot size and VMware does not allow hard disk shrinking."
714+
}
748715
}
716+
New-PfaRestOperation -resourceType "volume/$($targetFaVolume)" -restOperationType POST -flasharray $targetFlasharray -jsonBody "{`"overwrite`":true,`"source`":`"$($sourceFaVolume)`"}" -SkipCertificateCheck -ErrorAction Stop |Out-Nul
749717
}
750718
else {
751719
throw "The source VVol VMDK and target VVol VMDK are not on the same array."
@@ -828,10 +796,10 @@ function New-PfaSnapshotOfVvolVmdk {
828796
$faVolume = get-PfaVolumeNameFromVvolUuid -flasharray $fa -vvolUUID $vvolUuid -ErrorAction Stop
829797
if (($null -eq $suffix) -or ($suffix -eq ""))
830798
{
831-
$snapshot = New-PfaVolumeSnapshots -Array $fa -Sources $faVolume -ErrorAction Stop
799+
$snapshot = New-PfaRestOperation -resourceType "volume" -restOperationType POST -flasharray $fa -jsonBody "{`"snap`":true,`"source`":[`"$($faVolume)`"],`"suffix`":`"$($suffix)`"}" -SkipCertificateCheck -ErrorAction Stop
832800
}
833801
else {
834-
$snapshot = New-PfaVolumeSnapshots -Array $fa -Sources $faVolume -Suffix $suffix -ErrorAction Stop
802+
$snapshot = New-PfaRestOperation -resourceType "volume" -restOperationType POST -flasharray $fa -jsonBody "{`"snap`":true,`"source`":[`"$($faVolume)`"]}" -SkipCertificateCheck -ErrorAction Stop
835803
}
836804
$allSnaps += $snapshot
837805
$Global:CurrentFlashArray = $fa
@@ -973,11 +941,6 @@ function New-PfaVasaProvider {
973941
[Parameter(ParameterSetName='AllFlashArrays',Position=2,mandatory=$true)]
974942
[switch]$allFlashArrays
975943
)
976-
$powerCLIVersionCheck = (Get-Module -name VMware.PowerCLI -ListAvailable).Version |Where-Object {($_.Major -ge 11) -and ($_.Minor -ge 3)}
977-
if ($null -eq $powerCLIVersionCheck)
978-
{
979-
throw "You must be running PowerCLI 11.3.0 or later for this cmdlet to work. Please run update-module VMware.PowerCLI or update manually."
980-
}
981944
if ($null -eq $flasharray)
982945
{
983946
if ($allFlashArrays -ne $True)
@@ -1400,167 +1363,7 @@ function Mount-PfaVvolDatastore {
14001363
}
14011364
return $datastore
14021365
}
1403-
function Initialize-PfaVVols {
1404-
<#
1405-
.SYNOPSIS
1406-
Configures a VMware environment from scratch for Pure Storage FlashArray VVols.
1407-
.DESCRIPTION
1408-
Configures iSCSI, host groups, registers VASA, installs the vSphere Plugin, mounts VVol datastore to specified cluster
1409-
.INPUTS
1410-
FlashArray FQDN/IP and credentials, a vCenter cluster or clusters
1411-
.OUTPUTS
1412-
Returns the VVol datastore
1413-
.EXAMPLE
1414-
PS C:\ Connect-ViServer -Server myvCenter.purestorage.com
1415-
PS C:\ Initialize-PfaVVols -flasharray myFlashArray.purestorage.com -allClusters
1416-
1417-
Description. Configures VVols for a FlashArray for all clusters in a vCenter.
1418-
.EXAMPLE
1419-
PS C:\ Connect-ViServer -Server myvCenter.purestorage.com
1420-
PS C:\ $cluster = get-cluster myCluster
1421-
PS C:\ Initialize-PfaVVols -flasharray myFlashArray.purestorage.com -cluster $cluster
1422-
1423-
Description. Configures VVols for a FlashArray for the cluster called myCluster in a vCenter.
1424-
.EXAMPLE
1425-
PS C:\ Connect-ViServer -Server myvCenter.purestorage.com
1426-
PS C:\ Initialize-PfaVVols -flasharray myFlashArray.purestorage.com -allClusters -iscsi
1427-
1428-
Description. Configures VVols for a FlashArray for all clusters in a vCenter and specifies iSCSI as the connection protocol.
1429-
.NOTES
1430-
Version: 1.0
1431-
Author: Cody Hosterman https://codyhosterman.com
1432-
Creation Date: 07/25/2019
1433-
Purpose/Change: First release
1434-
1435-
*******Disclaimer:******************************************************
1436-
This scripts are offered "as is" with no warranty. While this
1437-
scripts is tested and working in my environment, it is recommended that you test
1438-
this script in a test lab before using in a production environment. Everyone can
1439-
use the scripts/commands provided here without any written permission but I
1440-
will not be liable for any damage or loss to the system.
1441-
************************************************************************
1442-
#>
14431366

1444-
[CmdletBinding()]
1445-
Param(
1446-
[Parameter(Position=0,ValueFromPipeline=$True,mandatory=$true)]
1447-
[string]$flasharray,
1448-
1449-
[Parameter(Position=1,ValueFromPipeline=$True)]
1450-
[System.Management.Automation.PSCredential]$credentials,
1451-
1452-
[Parameter(Position=2,ValueFromPipeline=$True)]
1453-
[VMware.VimAutomation.ViCore.Types.V1.Inventory.Cluster[]]$cluster,
1454-
1455-
[Parameter(Position=3,ValueFromPipeline=$True)]
1456-
[switch]$allClusters,
1457-
1458-
[Parameter(Position=4)]
1459-
[switch]$iscsi,
1460-
1461-
[Parameter(Position=5)]
1462-
[switch]$fc,
1463-
1464-
[Parameter(Position=6)]
1465-
[string]$datastoreName
1466-
)
1467-
if ($null -eq $global:defaultviserver)
1468-
{
1469-
$vcenter = Read-Host "Please enter in a vCenter server address"
1470-
Connect-VIServer -Server $vcenter
1471-
}
1472-
if (($iscsi -eq $true) -and ($fc -eq $true))
1473-
{
1474-
throw "Please only specify iSCSI or FC or neither. If neither is specified the cmdlet will query the array for protocol support."
1475-
}
1476-
if (($null -ne $cluster) -and ($allClusters -eq $true))
1477-
{
1478-
throw "Please either only pass in specific clusters OR use the -allClusters parameter. Not both."
1479-
}
1480-
if (($null -eq $cluster) -and ($allClusters -eq $false))
1481-
{
1482-
$clusterName = Read-Host "Please enter a cluster name to mount the VVol datastore"
1483-
$cluster = Get-Cluster $clusterName -ErrorAction Stop
1484-
}
1485-
if ($allClusters -eq $True)
1486-
{
1487-
$cluster = Get-Cluster
1488-
}
1489-
if ($null -eq $credentials)
1490-
{
1491-
$credentials = Get-Credential -Message "Please enter in FlashArray administrative credentials"
1492-
}
1493-
Write-Progress -Activity "Connecting to FlashArray" -status "Connecting..." -percentComplete 0
1494-
$fa = New-PfaArray -EndPoint $flasharray -Credentials $credentials -IgnoreCertificateError -ErrorAction Stop
1495-
if (($iscsi -eq $false) -and ($fc -eq $false))
1496-
{
1497-
$foundFC = $null
1498-
$foundFC = Get-PfaAllHardwareAttributes -Array $fa |Where-Object {$_.name -like "*FC*"}
1499-
if ($null -eq $foundFC)
1500-
{
1501-
$iscsi = $True
1502-
}
1503-
else
1504-
{
1505-
$fc = $True
1506-
}
1507-
}
1508-
Write-Progress -Activity "Connecting to FlashArray" -status "Connected." -percentComplete 20
1509-
if ($fc -eq $true)
1510-
{
1511-
write-warning "Fibre Channel is the selected protocol. This script does not configure zoning, so ensure that this is completed."
1512-
}
1513-
$percentComplete = (21 - (20/$cluster.count))
1514-
foreach ($workingCluster in $cluster)
1515-
{
1516-
Write-Progress -Activity "Creating host group(s)" -status $workingCluster.name -percentComplete ($percentComplete + (20/$cluster.count))
1517-
new-pfaHostGroupfromVcCluster -cluster $workingCluster -iscsi:$iscsi -fc:$fc -flasharray $fa -ErrorAction Stop |Out-Null
1518-
$percentComplete = $percentComplete + (20/$cluster.count)
1519-
}
1520-
Write-Progress -Activity "Creating host group(s)" -status "Created." -percentComplete 40
1521-
#vSphere Plugin installation
1522-
Write-Progress -Activity "Installing vSphere Plugin" -status "Installing..." -percentComplete 41
1523-
try
1524-
{
1525-
$pureplugins = get-pfavsphereplugin -source Pure1 -html
1526-
if ($null -eq $pureplugins)
1527-
{
1528-
install-pfavSpherePlugin -flasharray $fa -ErrorAction stop -Confirm:$false|Out-Null
1529-
}
1530-
else
1531-
{
1532-
install-pfavSpherePlugin -source "Pure1" -html -ErrorAction stop -Confirm:$false|Out-Null
1533-
}
1534-
Write-Progress -Activity "Installing vSphere Plugin" -status "Installed." -percentComplete 60
1535-
}
1536-
catch
1537-
{
1538-
Write-Warning $_
1539-
}
1540-
1541-
#Register VASA
1542-
Write-Progress -Activity "Registering VASA Providers" -status "Registering..." -percentComplete 61
1543-
New-PfaVasaProvider -flasharray $fa -credentials $credentials |Out-Null
1544-
Write-Progress -Activity "Registering VASA Providers" -status "Registered." -percentComplete 80
1545-
Write-Progress -Activity "Mounting VVol Datastore" -status "Mounting..." -percentComplete 81
1546-
if ($datastoreName -eq "")
1547-
{
1548-
$datastoreName = ((Get-PfaArrayAttributes -Array $fa).array_name + "-VVolDS" )
1549-
}
1550-
$percentComplete = (81 - (20/$cluster.count))
1551-
foreach ($workingCluster in $cluster)
1552-
{
1553-
Write-Progress -Activity "Mounting VVol Datastore" -status "Mounting on cluster $($workingCluster.Name)..." -percentComplete ($percentComplete + (20/$cluster.count))
1554-
$datastore = Mount-PfaVvolDatastore -flasharray $fa -cluster $workingCluster -datastoreName $datastoreName
1555-
$percentComplete = $percentComplete + (20/$cluster.count)
1556-
if (($percentComplete + (20/$cluster.count)) -ge 100)
1557-
{
1558-
$percentComplete = 99 - (20/$cluster.count)
1559-
}
1560-
}
1561-
Write-Progress -Activity "Mounting VVol Datastore" -status "Mounted on cluster(s)." -percentComplete 100
1562-
return $datastore
1563-
}
15641367
function checkDefaultFlashArray{
15651368
if ($null -eq $Global:DefaultFlashArray)
15661369
{

0 commit comments

Comments
 (0)