@@ -1260,196 +1260,6 @@ function Set-ClusterPfaiSCSI {
12601260 return $allEsxiiSCSItargets
12611261 }
12621262}
1263- function Initialize-PfaVcfWorkloadDomain {
1264- <#
1265- . SYNOPSIS
1266- Configures a workload domain for Pure Storage
1267- . DESCRIPTION
1268- Connects to each ESXi host, configures initiators on the FlashArray and provisions a VMFS. If something fails it will cleanup any changes.
1269- . INPUTS
1270- FQDNs or IPs of each host, valid credentials, a FlashArray connection, a datastore name and size.
1271- . OUTPUTS
1272- Returns host group.
1273- . NOTES
1274- Version: 2.0
1275- Author: Cody Hosterman https://codyhosterman.com
1276- Creation Date: 08/24/2020
1277- Purpose/Change: Core support
1278- . EXAMPLE
1279- PS C:\ $faCreds = get-credential
1280- PS C:\ New-PfaConnection -endpoint flasharray-m20-2 -credentials $faCreds -ignoreCertificateError -defaultArray
1281- PS C:\ $creds = get-credential
1282- PS C:\ Initialize-PfaVcfWorkloadDomain -esxiHosts "esxi-02.purecloud.com","esxi-04.purecloud.com" -credentials $creds -datastoreName "vcftest" -sizeInTB 16 -fc
1283-
1284- Creates a host group and hosts and provisions a 16 TB VMFS to the hosts over FC
1285- . EXAMPLE
1286- PS C:\ $faCreds = get-credential
1287- PS C:\ New-PfaConnection -endpoint flasharray-m20-2 -credentials $faCreds -ignoreCertificateError -defaultArray
1288- PS C:\ $creds = get-credential
1289- PS C:\ $allHosts = @()
1290- PS C:\ Import-Csv C:\hostList.csv | ForEach-Object {$allHosts += $_.hostnames}
1291- PS C:\ Initialize-PfaVcfWorkloadDomain -esxiHosts $allHosts -credentials $creds -datastoreName "vcftest" -sizeInTB 16 -fc
1292-
1293- Creates a host group and hosts and provisions a 16 TB VMFS to the hosts over FC. This takes in a csv file of ESXi host FQDNs with one csv header called hostnames
1294-
1295- *******Disclaimer:******************************************************
1296- This scripts are offered "as is" with no warranty. While this
1297- scripts is tested and working in my environment, it is recommended that you test
1298- this script in a test lab before using in a production environment. Everyone can
1299- use the scripts/commands provided here without any written permission but I
1300- will not be liable for any damage or loss to the system.
1301- ************************************************************************
1302- #>
1303-
1304- [CmdletBinding ()]
1305- Param (
1306-
1307- [Parameter (Position = 0 , mandatory = $true )]
1308- [string []]$EsxiHosts ,
1309-
1310- [Parameter (Position = 1 , ValueFromPipeline = $True , mandatory = $true )]
1311- [System.Management.Automation.PSCredential ]$Credentials ,
1312-
1313- [Parameter (Position = 1 , ValueFromPipeline = $True )]
1314- [PurePowerShell.PureArray ]$Flasharray ,
1315-
1316- [Parameter (Position = 2 , mandatory = $true )]
1317- [string ]$DatastoreName ,
1318-
1319- [Parameter (Position = 3 )]
1320- [int ]$SizeInGB ,
1321-
1322- [Parameter (Position = 4 )]
1323- [int ]$SizeInTB ,
1324-
1325- [Parameter (Position = 5 )]
1326- [switch ]$Fc
1327-
1328- )
1329- if ($fc -ne $true )
1330- {
1331- throw " Please indicate protocol type. Currently only -fc is a supported option."
1332- }
1333- $ErrorActionPreference = " stop"
1334- if (($sizeInGB -eq 0 ) -and ($sizeInTB -eq 0 ))
1335- {
1336- throw " Please enter a size in GB or TB"
1337- }
1338- elseif (($sizeInGB -ne 0 ) -and ($sizeInTB -ne 0 )) {
1339- throw " Please only enter a size in TB or GB, not both."
1340- }
1341- elseif ($sizeInGB -ne 0 ) {
1342- $volSize = $sizeInGB * 1024 * 1024 * 1024
1343- }
1344- else {
1345- $volSize = $sizeInTB * 1024 * 1024 * 1024 * 1024
1346- }
1347- if ($null -eq $flasharray )
1348- {
1349- $flasharray = checkDefaultFlashArray
1350- }
1351- $esxiConnections = @ ()
1352- for ($i = 0 ;$i -lt $esxiHosts.count ;$i ++ )
1353- {
1354- try {
1355- $esxiConnections += connect-viserver - Server $esxiHosts [$i ] - Credential ($Credentials ) - ErrorAction Stop
1356- }
1357- catch
1358- {
1359- $scriptCleanupStep = 0
1360- cleanup- pfaVcf
1361- }
1362- }
1363- $faHosts = @ ()
1364- for ($i = 0 ;$i -lt $esxiConnections.count ;$i ++ )
1365- {
1366- $foundHost = $null
1367- try {
1368- $foundHost = Get-PfaHostFromVmHost - esxi (get-vmhost $esxiConnections [$i ].name)
1369- if ($null -ne $foundHost )
1370- {
1371- if ($faHosts.count -ge 1 )
1372- {
1373- $scriptCleanupStep = 1
1374- }
1375- else
1376- {
1377- $scriptCleanupStep = 6
1378- }
1379- $esxiName = $esxiConnections [$i ].name
1380- cleanup- pfaVcf
1381- $newError = (" The host " + $esxiName + " already exists on the FlashArray. Ensure you entered the right host and/or array" )
1382- throw " "
1383- }
1384- }
1385- catch {
1386- if ($null -ne $newError )
1387- {
1388- throw $newError
1389- }
1390- }
1391- try {
1392- $faHosts += (New-PfaHostFromVmHost - esxi (get-vmhost $esxiConnections [$i ].name) - FC:$fc - ErrorAction Stop).name
1393- }
1394- catch
1395- {
1396- $scriptCleanupStep = 1
1397- cleanup- pfaVcf
1398- throw $_.Exception
1399- }
1400- }
1401- $groupName = (" vCF-WorkloadDomain-" + (get-random - Maximum 9999 - Minimum 1000 ))
1402- try {
1403- $hostGroup = New-PfaHostGroup - Array $flasharray - Hosts $fahosts - Name $groupName - ErrorAction Stop
1404- }
1405- catch
1406- {
1407- $scriptCleanupStep = 2
1408- cleanup- pfaVcf
1409- throw $_.Exception
1410- }
1411- try
1412- {
1413- $newVol = New-PfaVolume - Array $flasharray - Size $volSize - VolumeName $datastoreName - ErrorAction Stop
1414- }
1415- catch
1416- {
1417- $scriptCleanupStep = 3
1418- cleanup- pfaVcf
1419- throw $_.Exception
1420- }
1421- $Global :CurrentFlashArray = $flasharray
1422- try
1423- {
1424- New-PfaHostGroupVolumeConnection - Array $flasharray - VolumeName $newVol.name - HostGroupName $groupName - ErrorAction Stop| Out-Null
1425- }
1426- catch
1427- {
1428- $scriptCleanupStep = 4
1429- cleanup- pfaVcf
1430- throw $_.Exception
1431- }
1432- $newNAA = " naa.624a9370" + $newVol.serial.toLower ()
1433- $esxi = $esxiConnections | Select-Object - Last 1
1434- get-vmhost $esxi.name | Get-VMHostStorage - RescanAllHba | Out-Null
1435- try
1436- {
1437- $newVMFS = get-vmhost $esxi.name | new-datastore - name $datastoreName - vmfs - Path $newNAA - FileSystemVersion 6 - ErrorAction Stop
1438- }
1439- catch
1440- {
1441- $scriptCleanupStep = 5
1442- cleanup- pfaVcf
1443- throw $_.Exception
1444- }
1445- foreach ($esxiConnection in $esxiConnections )
1446- {
1447- get-vmhost $esxiConnection.name | Get-VMHostStorage - RescanAllHba | Out-Null
1448- }
1449- $scriptCleanupStep = 7
1450- cleanup- pfaVcf
1451- return $hostGroup
1452- }
14531263function New-PfaRestOperation {
14541264 <#
14551265 . SYNOPSIS
@@ -1599,46 +1409,6 @@ New-Alias -Name Set-clusterPureFAiSCSI -Value Set-clusterPfaiSCSI
15991409
16001410
16011411# ### helper functions
1602- function Cleanup-PfaVcf {
1603- if ($scriptCleanupStep -lt 6 )
1604- {
1605- if ($scriptCleanupStep -eq 5 )
1606- {
1607- Remove-PfaHostGroupVolumeConnection - Array $flasharray - VolumeName $datastoreName - HostGroupName $groupName | Out-Null
1608- }
1609- if ($scriptCleanupStep -ge 4 )
1610- {
1611- Remove-PfaVolumeOrSnapshot - Array $flasharray - Name $datastoreName | Out-Null
1612- Remove-PfaVolumeOrSnapshot - Array $flasharray - Name $datastoreName - Eradicate | Out-Null
1613- }
1614- if ($scriptCleanupStep -ge 1 )
1615- {
1616- foreach ($faHost in $faHosts )
1617- {
1618- Remove-PfaHost - Array $flasharray - Name $faHost | out-null
1619- }
1620- }
1621- if ($scriptCleanupStep -ge 3 )
1622- {
1623- remove-PfaHostGroup - Array $flasharray - Name $groupName | out-null
1624- }
1625- }
1626- if ($scriptCleanupStep -ge 0 )
1627- {
1628- if ($esxiConnections.count -eq 0 )
1629- {
1630- return
1631- }
1632- else
1633- {
1634- foreach ($esxiConnection in $esxiConnections )
1635- {
1636- $esxiConnection | disconnect-viserver - confirm:$false | out-null
1637- }
1638- }
1639- }
1640- return
1641- }
16421412function checkDefaultFlashArray {
16431413 if ($null -eq $Global :DefaultFlashArray )
16441414 {
0 commit comments