PureStorage.CBS.AVS.psm1
$ErrorActionPreference = "stop" Import-Module VMware.VimAutomation.Core Import-Module PureStoragePowerShellSDK2 <# AVSAttribute applied to a commandlet function indicates: - whether the SDDC should be marked as Building while the function executes. - default timeout for the commandlet, maximum: 3h. AVS SDDC in Building state prevents other changes from being made to the SDDC until the function completes/fails. #> class AVSAttribute : Attribute { [bool]$UpdatesSDDC = $false [TimeSpan]$Timeout AVSAttribute($timeoutMinutes) { $this.Timeout = New-TimeSpan -Minutes $timeoutMinutes } } . $PSScriptRoot/CommonUtil.ps1 . $PSScriptRoot/PureStorage.CBS.AVS.SPBM.ps1 . $PSScriptRoot/PureStorage.CBS.AVS.Replication.ps1 function Build-PCBSCluster { <# .SYNOPSIS Build or update settings for a cluster of ESXi servers .DESCRIPTION Build or update settings for a cluster of ESXi servers. Creates a hostgroup in Pure Cloud Block Store if it does not exists and updates iSCSI settings. Can be used when creating a new cluster or when adding hosts to a cluster. .PARAMETER ClusterName Cluster name .PARAMETER PureCloudBlockStoreAddress Pure Cloud Block Store IP address or FQDN .PARAMETER PureCloudBlockStoreCredential Pure Cloud BlockStore Credentials .EXAMPLE Build-PCBSCluster -ClusterName "mycluster" -PureCloudBlockStoreAddress $endpoint -PureCloudBlockStoreCredential (Get-Credential) #> [CmdletBinding()] [AVSAttribute(10, UpdatesSDDC = $false)] Param( [Parameter(Mandatory=$true)] [String]$ClusterName, [Parameter(Mandatory=$true)] [String]$PureCloudBlockStoreAddress, [Parameter(Mandatory=$true)] [PSCredential]$PureCloudBlockStoreCredential ) $cluster = Get-Cluster -Name $ClusterName if (-not $cluster) { throw "Could not find cluster '$ClusterName'..." } $fa = Connect-Pfa2Array -EndPoint $PureCloudBlockStoreAddress -Credential $PureCloudBlockStoreCredential -IgnoreCertificateError New-PCBSHostGroupfromVcCluster -FlashArray $fa -Cluster $cluster | Out-Null Remove-PCBSUnusedHosts -FlashArray $fa -Cluster $cluster | Out-Null $ESXHosts = $Cluster | Get-VMHost foreach ($ESXHost in $ESXHosts) { Write-Host "Removing static iSCSI targets for $ESXHost ..." Remove-PCBSStaticiSCSITargets -esxi $ESXHost Write-Host "Rescanning HBA for $ESXHost ..." Get-VMHostStorage -VMHost $ESXHosts -RescanAllHba | Out-Null } } function New-PCBSVVolDataStore { <# .SYNOPSIS Mount a vVol datastore on all of the hosts in the cluster. .DESCRIPTION Mount a vVol datastore on all of the hosts in the cluster. .PARAMETER ClusterName Cluster name .PARAMETER DatastoreName Datastore name .PARAMETER UseDefaultStore Indicates whether to use default root container .PARAMETER PureCloudBlockStoreAddress Pure Cloud Block Store IP address or FQDN .PARAMETER PureCloudBlockStoreCredential Pure Cloud BlockStore Credentials .EXAMPLE New-PCBSVVolDataStore -ClusterName "mycluster" -DatastoreName "myDatastore" -PureCloudBlockStoreAddress $endpoint -PureCloudBlockStoreCredential (Get-Credential) #> [CmdletBinding()] [AVSAttribute(10, UpdatesSDDC = $false)] Param( [Parameter(Mandatory=$true)] [String]$ClusterName, [Parameter(Mandatory=$false)] [String]$DatastoreName, [Parameter(Mandatory=$false)] [bool] $UseDefaultStore, [Parameter(Mandatory=$true)] [String]$PureCloudBlockStoreAddress, [Parameter(Mandatory=$true)] [PSCredential]$PureCloudBlockStoreCredential ) $Cluster = Get-Cluster -Name $ClusterName -ErrorAction Ignore if (-not $Cluster) { throw "Cluster $ClusterName does not exist." } $fa = Connect-Pfa2Array -EndPoint $PureCloudBlockStoreAddress -Credential $PureCloudBlockStoreCredential -IgnoreCertificateError $datastore = Mount-PCBSVvolDatastore -DatastoreName $DatastoreName -Cluster $Cluster -FlashArray $fa -FlashArrayCredential $PureCloudBlockStoreCredential -UseDefaultStore $UseDefaultStore if ("Available" -ne $datastore.State -or -not $datastore.Accessible) { throw "The datastore '$($datastore.Name)' is either not available or not acessible." } } function Remove-PCBSVVolDataStore { <# .SYNOPSIS UnMount a vVol datastore on all of the hosts in the cluster. .DESCRIPTION UnMount a vVol datastore on all of the hosts in the cluster. .PARAMETER ClusterName Cluster name .PARAMETER DatastoreName Datastore name .EXAMPLE Remove-PCBSVVolDataStore -ClusterName "mycluster" -DatastoreName "myDatastore" .NOTES General notes #> [CmdletBinding()] [AVSAttribute(10, UpdatesSDDC = $false)] Param( [Parameter(Mandatory=$true)] [String]$ClusterName, [Parameter(Mandatory=$true)] [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 ("VVOL" -ne $Datastore.Type) { throw "Datastore $DatastoreName is of type $($Datastore.Type). This cmdlet can only process VVol datastores" } $VMHosts = $Cluster | Get-VMHost foreach ($VMHost in $VMHosts) { Write-Host "Removing datastore $DatastoreName from $($VMHost.Name)..." Remove-Datastore -Datastore $Datastore -VMHost $VMHost -Confirm:$false -ErrorAction Stop } } function New-PCBSVASAProvider { <# .SYNOPSIS Register Pure Cloud Block Store VASA providers with vCenter .DESCRIPTION Register Pure Cloud Block Store VASA providers for all array controllers with vCenter. If a VASA provider has a certificate problem, it will be created .PARAMETER PureCloudBlockStoreAddress Pure Cloud Block Store IP address or FQDN .PARAMETER PureCloudBlockStoreCredential Pure Cloud BlockStore Credentials .EXAMPLE New-PCBSVASAProvider -PureCloudBlockStoreAddress $endpoint -PureCloudBlockStoreCredential (Get-Credential) #> [CmdletBinding()] [AVSAttribute(10, UpdatesSDDC = $false)] Param( [Parameter(Mandatory=$true)] [String]$PureCloudBlockStoreAddress, [Parameter(Mandatory=$true)] [PSCredential]$PureCloudBlockStoreCredential ) $FlashArray = Connect-Pfa2Array -EndPoint $PureCloudBlockStoreAddress -Credential $PureCloudBlockStoreCredential -IgnoreCertificateError $vasaProviders = Update-PCBSVASAProvider -FlashArray $FlashArray -FlashArrayCredential $PureCloudBlockStoreCredential $NamedOutputs = @{} $index = 0; foreach ($vasaProvider in $vasaProviders){ $NamedOutputs["CreatedVASAProvider$index"] = $vasaProvider.Name $index = $index+1 } Set-Variable -Name NamedOutputs -Value $NamedOutputs -Scope Global } function New-PCBSStoragePolicy { <# .SYNOPSIS Creates a new Pure Cloud Block Store vVol Storage Policy .DESCRIPTION Creates a new Pure Cloud Block Store vVol Storage Policy with specified capabilities .INPUTS Capabilities .OUTPUTS New storage policy .PARAMETER PolicyName Pure Cloud Block Store vVol Storage Policy name .PARAMETER PolicyDescription Pure Cloud Block Store vVol Storage Policy description .PARAMETER SourcePureCloudBlockStores Name of one or more Pure Cloud Block Store to use. Use comma as seperater if there are multiple names .PARAMETER ReplicationEnabled Replication capability rule. The input value could be yes, no or empty .PARAMETER ReplicationIntervalSeconds Replication capability rule. Protection group remote snapshot creation interval in seconds .PARAMETER ReplicationRetentionShortSeconds Replication capability rule. Protection group remote snapshot retention interval in seconds .PARAMETER ReplicationRuleLocalSnapshotEnabled Replication capability rule. The input value could be yes, no or empty .PARAMETER ReplicationRuleLocalSnapshotIntervalSeconds Replication capability rule. Protection group local snapshot creation interval in seconds .PARAMETER ReplicationRuleLocalSnapshotRetentionShortSeconds Replication capability rule. Protection group local snapshot retention interval in seconds .PARAMETER ReplicationConcurrency Replication capability rule. The number of target Pure Cloud Block Store to replicate to at once .PARAMETER TargetPureCloudBlockStores Replication capability rule. Names of specific Pure Cloud Block Store desired as replication targets. Use comma as seperater if there are multiple names .PARAMETER ConsistencyGroupName Replication capability rule. A Pure Cloud Block Store protection group name .PARAMETER PerVirtualDiskIOPSLimit QoS placement capability rule. IOPS limit get applied to per virtual disk .PARAMETER PerVirtualDiskIOPSLimitUnit QoS placement capability rule. IOPS limit unit (K, M, or -) .PARAMETER PerVirtualDiskBandwidthLimit QoS placement capability rule. Bandwidth limit get applied to per virtual disk .PARAMETER PerVirtualDiskBandwidthLimitUnit QoS placement capability rule. Bandwidth limit unit (KB/s, MB/s or GB/s) .PARAMETER VolumeTaggingKey Volume tagging placement capability. Volumes with this policy will be tagged with the key .PARAMETER VolumeTaggingValue Volume tagging placement capability. Volumes with this policy will be tagged with the value .PARAMETER VolumeTaggingCopyable Volume tagging placement capability. When set to yes, any volume copies of this volume will receive the tag .PARAMETER PlacementRuleLocalSnapshotIntervalSeconds Local snapshot protection placement capability. Snapshots will be taken in the specified interval in seconds .PARAMETER PlacementRuleLocalSnapshotRetentionShortSeconds Local snapshot protection placement capability. Snapshots will be retained for the timespan in seconds .PARAMETER PlacementRuleLocalSnapshotForAdditionalSnapshots Local snapshot protection placement capability. Optional additional retention: After the retention timespan specified above is up, a number of snapshots will be selected, evenly spaced out, from the last retention timespan. This parameter specifies the number of snapshots to select from the last retention timespan. These snapshots will be retained for a number of additional days (see parameter below). Leave this parameter as "0" if additional retention is not required. .PARAMETER PlacementRuleLocalSnapshotForAdditionalDays Local snapshot protection placement capability. Optional additional retention: This parameter specifies the number of days that additional snapshots should be retained. If a selection for "Retain additional snapshots" (see above) was made, this parameter must also be specified. Leave this parameter as "0" if additional retention is not required. .EXAMPLE New-PCBSStoragePolicy Creates the default SPBM policy that indicates a VM should be on a Pure Cloud Block Store using vVols. Default generated name and description. .EXAMPLE New-PCBSStoragePolicy -PolicyName myGreatPolicy Creates a SPBM policy with the specified name that indicates a VM should be on a Pure Cloud Block Store using vVols. Default generated description. .EXAMPLE New-PCBSStoragePolicy -PolicyName myGreatReplicationPolicy -ReplicationIntervalSeconds 7200 -ReplicationEnabled "yes" -ReplicationConcurrency 2 Creates a replication-type SPBM policy with the specified name that indicates a VM should be on a Pure Cloud Block Store using vVols, replicated every 2 hours to at least two other Pure Cloud Block Stores. Default generated description. .EXAMPLE New-PCBSStoragePolicy -PolicyName myGreatReplicationPolicy -SourcePureCloudBlockStores "MyArrayOne,MyArrayTwo" Creates a SPBM policy with the specified name that indicates a VM should be on the specific Pure Cloud Block Store using vVols. #> [CmdletBinding()] [AVSAttribute(10, UpdatesSDDC = $false)] Param( [String]$PolicyName, [String]$PolicyDescription, [string]$SourcePureCloudBlockStores, [string]$ReplicationEnabled, [int]$ReplicationIntervalSeconds = 0, [int]$ReplicationRetentionShortSeconds = 0, [string]$ReplicationRuleLocalSnapshotEnabled, [int]$ReplicationRuleLocalSnapshotIntervalSeconds = 0, [int]$ReplicationRuleLocalSnapshotRetentionShortSeconds = 0, [int]$ReplicationConcurrency, [string]$TargetPureCloudBlockStores, [String]$ConsistencyGroupName, [int]$PerVirtualDiskIOPSLimit, [String]$PerVirtualDiskIOPSLimitUnit, [int]$PerVirtualDiskBandwidthLimit, [String]$PerVirtualDiskBandwidthLimitUnit, [String]$VolumeTaggingKey, [String]$VolumeTaggingValue, [string]$VolumeTaggingCopyable, [int]$PlacementRuleLocalSnapshotIntervalSeconds = 0, [int]$PlacementRuleLocalSnapshotRetentionShortSeconds = 0, [int]$PlacementRuleLocalSnapshotForAdditionalSnapshots, [int]$PlacementRuleLocalSnapshotForAdditionalDays ) $params = @{ PolicyName = $PolicyName PolicyDescription = $PolicyDescription ReplicationEnabled = $ReplicationEnabled ReplicationIntervalSeconds = $ReplicationIntervalSeconds ReplicationRetentionShortSeconds = $ReplicationRetentionShortSeconds ReplicationConcurrency = $ReplicationConcurrency ConsistencyGroupName = $ConsistencyGroupName ReplicationRuleLocalSnapshotEnabled = $ReplicationRuleLocalSnapshotEnabled ReplicationRuleLocalSnapshotIntervalSeconds = $ReplicationRuleLocalSnapshotIntervalSeconds ReplicationRuleLocalSnapshotRetentionShortSeconds = $ReplicationRuleLocalSnapshotRetentionShortSeconds PerVirtualDiskIOPSLimit = $PerVirtualDiskIOPSLimit PerVirtualDiskIOPSLimitUnit = $PerVirtualDiskIOPSLimitUnit PerVirtualDiskBandwidthLimit = $PerVirtualDiskBandwidthLimit PerVirtualDiskBandwidthLimitUnit = $PerVirtualDiskBandwidthLimitUnit VolumeTaggingKey = $VolumeTaggingKey VolumeTaggingValue = $VolumeTaggingValue VolumeTaggingCopyable = $VolumeTaggingCopyable PlacementRuleLocalSnapshotIntervalSeconds = $PlacementRuleLocalSnapshotIntervalSeconds PlacementRuleLocalSnapshotRetentionShortSeconds = $PlacementRuleLocalSnapshotRetentionShortSeconds PlacementRuleLocalSnapshotForAdditionalSnapshots = $PlacementRuleLocalSnapshotForAdditionalSnapshots PlacementRuleLocalSnapshotForAdditionalDays = $PlacementRuleLocalSnapshotForAdditionalDays } if ($PSBoundParameters.ContainsKey('SourcePureCloudBlockStores')) { $params['SourceFlashArrays'] = $SourcePureCloudBlockStores } if ($PSBoundParameters.ContainsKey('TargetPureCloudBlockStores')) { $params['TargetFlashArrays'] = $TargetPureCloudBlockStores } New-PfaVvolStoragePolicy @params } function Remove-PCBSStoragePolicy { <# .SYNOPSIS Remove a Pure Cloud Block Store vVol Storage Policy .DESCRIPTION Remove a Pure Cloud Block Store vVol Storage Policy using policy name. The policy must be unused and belong to Pure .INPUTS SPBM policy name .PARAMETER PolicyName Pure Cloud Block Store vVol Storage Policy name .EXAMPLE Remove-PCBSStoragePolicy -PolicyName myPolicyName #> [CmdletBinding()] [AVSAttribute(10, UpdatesSDDC = $false)] Param( [Parameter(mandatory=$true)] [string]$PolicyName ) return (Remove-PfaVvolStoragePolicy -PolicyName $PolicyName) } function New-PCBSVmfsFromSnapshot { <# .SYNOPSIS Mounts a copy of a VMFS datastore to a VMware cluster from a Pure Cloud BlockStore snapshot. .DESCRIPTION Takes in a snapshot name, the corresponding Pure Cloud BlockStore, and a cluster. The VMFS copy will be resignatured and mounted. .PARAMETER ClusterName Cluster name .PARAMETER PureCloudBlockStoreAddress Pure Cloud Block Store IP address or FQDN .PARAMETER PureCloudBlockStoreCredential Pure Cloud BlockStore Credentials .PARAMETER DatastoreName Datastore name .EXAMPLE New-PCBSVmfsFromSnapshot -ClusterName myClusterName -SnapshotName mySnapshotName -PureCloudBlockStoreAddress $endpoint -PureCloudBlockStoreCredential (Get-Credential) Takes in a snapshot name, the corresponding Pure Cloud BlockStore, and a cluster. The VMFS copy will be resignatured and mounted. .EXAMPLE New-PCBSVmfsFromSnapshot -ClusterName myClusterName -SnapshotName mySnapshotName -DatastoreName myDataStoreName -PureCloudBlockStoreAddress $endpoint -PureCloudBlockStoreCredential (Get-Credential) Takes in a snapshot name, the corresponding Pure Cloud BlockStore, the specified datastore name, and a cluster. The VMFS copy with the specified name will be resignatured and mounted. .INPUTS Pure Cloud BlockStore connection, a snapshotName, and a cluster. .OUTPUTS Returns the new datastore. #> [CmdletBinding()] [AVSAttribute(10, UpdatesSDDC = $false)] Param ( [Parameter(Mandatory=$true)] [String]$ClusterName, [Parameter(Mandatory=$true)] [String]$SnapshotName, [Parameter(Mandatory=$false)] [String]$DatastoreName, [Parameter(Mandatory=$true)] [String]$PureCloudBlockStoreAddress, [Parameter(Mandatory=$true)] [PSCredential]$PureCloudBlockStoreCredential ) $Cluster = Get-Cluster -Name $ClusterName -ErrorAction Ignore if (-not $Cluster) { throw "Cluster $ClusterName does not exist." } $fa = Connect-Pfa2Array -EndPoint $PureCloudBlockStoreAddress -Credential $PureCloudBlockStoreCredential -IgnoreCertificateError New-PfaVmfsFromSnapshot -FlashArray $fa -Cluster $cluster -SnapName $SnapshotName -VolumeName $DatastoreName | Out-Null } function Start-PCBSFailover { <# .SYNOPSIS Issue test failover or failover operation against replication group .DESCRIPTION Issue test failover or failover operation against replication group. Must be run on a "Target" Replication Group. .PARAMETER ReplicationGroupID Replication Group Id to be used on failover .PARAMETER ClusterName Cluster name where failover VMs will be created .PARAMETER PowerOn (bool) Indicates whether to or not to power on created VMs .PARAMETER Failover (bool) Indicates whether to actually perform a failover(true) or to only perform a test failover(false) .EXAMPLE Start-PCBSFailover -ReplicationGroupID myGroupId -ClusterName myclustername Issues test failover on replication group specified by id "myGroupId", test VMs will be created under cluster "myclustername", and group replication state will be set to "InTest" .EXAMPLE Start-PCBSFailover -ReplicationGroupID myGroupId -ClusterName myclustername -PowerOn $true Issues test failover on replication group specified by id "myGroupId", test VMs will be created under cluster "myclustername", VMs created will be powered on, and group replication state will be set to "InTest" .EXAMPLE Start-PCBSFailover -ReplicationGroupID myGroupId -ClusterName myclustername -PowerOn $true Failover $true Issues Failover on replication group specified by id "myGroupId", new VMs will be created under cluster "myclustername", VMs created will be powered on, and group replication state will be set to "FailedOver" #> [CmdletBinding()] [AVSAttribute(10, UpdatesSDDC = $false)] Param( [Parameter(mandatory=$true)] [String]$ReplicationGroupID, [Parameter(mandatory=$true)] [String]$ClusterName, [Parameter(mandatory=$false)] [bool]$PowerOn, [Parameter(mandatory=$false)] [bool]$Failover ) Start-PCBSVvolReplicationGroupFailover -ReplicationGroupID $ReplicationGroupID -ClusterName $ClusterName -PowerOn $PowerOn -Failover $Failover } function Stop-PCBSFailoverTest { <# .SYNOPSIS Stops a test failover that was started on replication group .DESCRIPTION Stops a test failover that was started on replication group. Must be used on a "InTest" Replication Group .PARAMETER ReplicationGroupID Replication Group Id that was used on the test failover .EXAMPLE Stop-PCBSFailover -ReplicationGroupID myGroupId Stops a test failover that was started on replication group specified by id "myGroupId", test VMs will be stopped and deleted and group replication state will be set to "Target" #> [CmdletBinding()] [AVSAttribute(10, UpdatesSDDC = $false)] Param( [Parameter(mandatory=$true)] [String]$ReplicationGroupID ) Stop-PCBSVvolReplicationGroupFailoverTest -ReplicationGroupID $ReplicationGroupID } function Start-PCBSFailoverCleanup { <# .SYNOPSIS Cleans up the original source site after failing over to a new site. .DESCRIPTION Cleans up the original source site after failing over to a new site. Must be run on source site. Will stop and unregister VMs protected by replication group. .PARAMETER ReplicationGroupID Replication Group Id for source group used on the failover .EXAMPLE Start-PCBSFailoverCleanup -ReplicationGroupID myGroupId Will stop and unregister VMs protected by replication group identified by "myGroupId". #> [CmdletBinding()] [AVSAttribute(10, UpdatesSDDC = $false)] Param( [Parameter(mandatory=$true)] [String]$ReplicationGroupID, [Parameter(mandatory=$false)] [bool]$RemoveFromDisk ) Start-PCBSVvolCleanupSourceReplicationGroupForFailover -ReplicationGroupID $ReplicationGroupID -RemoveFromDisk $RemoveFromDisk } function Start-PCBSReprotect { <# .SYNOPSIS Reverse replication on a FailedOver replication group and reprotect by assigning a storage policy to affected objects .DESCRIPTION Reverse replication on a FailedOver replication group and reprotect by assigning a storage policy to affected objects. Must be used on a FailedOver Replication Group. .PARAMETER ReplicationGroupID Replication Group Id that was used on failover .PARAMETER PolicyName Policy Name to be used to reprotect objects .OUTPUTS Affected VMs names .EXAMPLE Start-PCBSReprotect -ReplicationGroupID myGroupId Reprotect replication group specified by id "myGroupId", and sets objects storage policy to the default "VVol No Requirements Policy" .EXAMPLE Start-PCBSReprotect -ReplicationGroupID myGroupId -PolicyName PolicyName Reprotect replication group specified by id "myGroupId", and sets objects storage policy to "PolicyName" #> [CmdletBinding()] [AVSAttribute(10, UpdatesSDDC = $false)] Param( [Parameter(mandatory=$true)] [String]$ReplicationGroupID, [Parameter(mandatory=$false)] [String]$PolicyName ) return Start-PCBSVvolReprotectReplicationGroup -ReplicationGroupID $ReplicationGroupID -PolicyName $PolicyName } |