param ( [parameter(Mandatory=$true, HelpMessage="Cluster (controller) IP or name.")] [string]$Cluster, [parameter(Mandatory=$true, HelpMessage="Volume name.")] [string]$VolumeName, [parameter(Mandatory=$true, HelpMessage="Storage Virtual Machine name.")] [string]$VserverName, [parameter(Mandatory=$true, HelpMessage="Aggregate name.")] [string]$AggregateName, [parameter(Mandatory=$true, HelpMessage="Initial size of the new volume in megabytes.")] [Alias("Size_Capacity")] [int]$Size, [parameter(Mandatory=$true, HelpMessage="Type of volume guarantee the new volume will use.")] [ValidateSet("none", "volume", "file")] [string]$SpaceGuarantee, [parameter(Mandatory=$false, HelpMessage="Junction path where the newly created volume will be mounted in the Storage Virtual Machine's namespace. This parameter is applicable and should be provided only when creating volumes with VolumeType as 'rw'")] [string]$JunctionPath, [parameter(Mandatory=$false, HelpMessage="Snapshot reserve of the volume.")] [int]$SnapshotReservePercentage = -1, [parameter(Mandatory=$false, HelpMessage="Volume state.")] [ValidateSet("online", "restricted", "offline")] [string]$State="online", [parameter(Mandatory=$false, HelpMessage="Volume type.")] [ValidateSet("rw", "ls", "dp", "dc")] [string]$VolumeType="rw", [parameter(Mandatory=$false, HelpMessage="Mode of operation of volume autosize. Valid modes are 'off', 'grow', and 'grow_shrink'. The default mode is 'off'. This parameter can be specified only for clusters running ONTAP version 8.2.0 and above.")] [ValidateSet("off", "grow", "grow_shrink")] [string]$AutosizeMode, [parameter(Mandatory=$false, HelpMessage="Volume maximum allowed size in megabytes. This should be higher than the volume size.")] [Alias("AutosizeMaxSize_Capacity")] [int]$AutosizeMaxSize, [parameter(Mandatory=$false, HelpMessage="Volume increment size in megabytes.")] [Alias("AutosizeIncrementSize_Capacity")] [int]$AutosizeIncrementSize, [parameter(Mandatory=$false, HelpMessage="Volume options.")] [string]$Options, [parameter(Mandatory=$false, HelpMessage="Volume auto delete options.")] [string]$AutoDeleteOptions, [parameter(Mandatory=$false, HelpMessage="Enables/disables deduplication.")] [bool]$Deduplication, [parameter(Mandatory=$false, HelpMessage="Snapshot Policy.")] [string]$SnapshotPolicy, [parameter(Mandatory=$false, HelpMessage="Export Policy to be associated with the volume.")] [string]$ExportPolicy, [parameter(Mandatory=$false, HelpMessage="Security Style.")] [ValidateSet("unix", "ntfs","mixed", "unified")] [string]$SecurityStyle, [parameter(Mandatory=$false, HelpMessage="Unix Permissions.")] [string]$UnixPermissions, [parameter(Mandatory=$false, HelpMessage="Configure compression on the volume.")] [ValidateSet("disabled","background","inline")] [string]$Compression, [parameter(Mandatory=$false, HelpMessage="Maximum size in megabytes to which any directory in this volume can grow.")] [int]$MaxDirectorySize, [parameter(Mandatory=$false, HelpMessage="UNIX user ID for the volume.")] [int]$UserId, [parameter(Mandatory=$false, HelpMessage="UNIX group ID for the volume.")] [int]$GroupId, [parameter(Mandatory=$false, HelpMessage="Name of the Anti-Virus On-Access policy.")] [string]$AntivirusOnAccessPolicy, [parameter(Mandatory=$false, HelpMessage="QoS policy group name that is to be associated with this volume in order to enforce Service Level Objectives (SLO). If you do not assign a QoS policy group to a volume, the system will not monitor and control the traffic to it. This parameter is only applicable for clusters running ONTAP version 8.2.0 (or onwards).")] [string]$PolicyGroupName, [parameter(Mandatory=$false, HelpMessage="Language for the volume. This parameter can be sepecified only for clusters running ONTAP version 8.2.0 and above.")] [ValidateSet("c","ar","cs","da","de","en","en_us","es","fi","fr","he","hr","hu","it","ja","ja_v1","ja_jp.pck","ja_jp.932","ja_jp.pck_v2","ko","no","nl","pl","pt","ro","ru","sk","sl","sv","tr","zh","zh.gbk","zh_tw","zh_tw.big5","c.utf_8","ar.utf_8","cs.utf_8","da.utf_8","de.utf_8","en.utf_8","en_us.utf_8","es.utf_8","fi.utf_8","fr.utf_8","he.utf_8","hr.utf_8","hu.utf_8","it.utf_8","ja.utf_8","ja_v1.utf_8","ja_jp.pck.utf_8","ja_jp.932.utf_8","ja_jp.pck_v2.utf_8","ko.utf_8","no.utf_8","nl.utf_8","pl.utf_8","pt.utf_8","ro.utf_8","ru.utf_8","sk.utf_8","sl.utf_8","sv.utf_8","tr.utf_8","zh.utf_8","zh.gbk.utf_8","zh_tw.utf_8","zh_tw.big5.utf_8" )] [string]$Language ) if($VolumeType -eq "ls") { throw "Volume of type 'LS' can not be created." } if($VolumeType -eq "dc") { throw "FlexCache DC volumes are not supported by this command" } if($VolumeType -eq "dp") { if($SnapshotPolicy) { if($SnapshotPolicy -ne "none") { throw "Snapshot policy must be 'none' for DP volumes" } } if ($JunctionPath) { throw "Junction path can be provided only for volumes of type 'rw'. 'dp' type of volumes can be mounted only after a SnapMirror initialization is completed." } } # connect to controller Connect-WfaCluster $Cluster $versionInfo = Get-NcSystemVersionInfo $version = $versionInfo.VersionTuple.ToString() $versionComparisionValue = Compare-OntapVersions $version "8.2.0" if ($Language -and $versionComparisionValue -lt 0) { throw "Language for the volume can be specified only on clusters running ONTAP version 8.2.0 and above." } if ($AutosizeMode -and $versionComparisionValue -lt 0) { throw "AutosizeMode for the volume can be specified only on clusters running ONTAP version 8.2.0 and above." } else { if ($versionComparisionValue -ge 0 -and !$AutosizeMode) { $AutosizeMode = "off" } } If ($versionComparisionValue -lt 0) { If ($AutosizeMaxSize -and ($AutosizeMaxSize -le $Size)) { # Untill 8.2.0 , max autosize needs to be higher than the volume size. throw "Volume's maximum allowed size should be higher than the volume size." } } else { If ($AutosizeMaxSize -and ($AutosizeMaxSize -lt $Size)) { # From 8.2.0 onwards, max autosize needs to be equal to or higher than the volume size. throw "Volume's maximum allowed size should be equal to or higher than the volume size." } } # Set SnapShot Amount & Retention $Policy = Get-NcSnapshotPolicy -Name $SnapshotPolicy if (!$Policy) { throw "Snapshot policy '" + $SnapShotPolicy + "' does not exist!!" } try { $expression = "New-NcVol -ErrorAction Stop -name " + $VolumeName + " -Aggregate " + $AggregateName+ " -SpaceReserve " + $SpaceGuarantee + " -State " + $State+ " -Size " + ([string] $Size + "m") + " -VserverContext " + $VserverName+ " -Type " + $VolumeType if($MaxDirectorySize) { # Convert MaxDirectorySize value from MBytes to Bytes $MaxDirectorySizeBytes = $MaxDirectorySize * 1024 * 1024 $expression = $expression + " -MaxDirectorySize " + $MaxDirectorySizeBytes } if($SecurityStyle) { $expression = $expression + " -SecurityStyle "+ $SecurityStyle } if($UnixPermissions) { $expression = $expression + " -UnixPermissions "+ $UnixPermissions } if($SnapshotPolicy) { $expression = $expression + " -SnapshotPolicy " + $SnapshotPolicy } if($ExportPolicy) { $expression = $expression + " -ExportPolicy " + $ExportPolicy } if($UserId) { $expression = $expression + " -UserId " + $UserId.ToString() } if($GroupId) { $expression = $expression + " -GroupId " + $GroupId.ToString() } if($AntivirusOnAccessPolicy) { $expression = $expression + " -AntivirusOnAccessPolicy " + $AntivirusOnAccessPolicy } if($PolicyGroupName) { # Include this parameter only if ONTAP version is equal to 8.2.0 or onwards. if ($versionComparisionValue -ge 0 ) { $expression = $expression + " -QosPolicyGroup " + $PolicyGroupName } } if($VolumeType -ne "rw") { $expression = $expression + " -JunctionPath `$null " } else { if(!$JunctionPath) { $JunctionPath="/$VolumeName" } $expression = $expression + " -JunctionPath " + $JunctionPath } if ($Language) { $expression = $expression + " -Language " + $Language } # Create a new volume Get-WFALogger -Info -message $("Creating a new volume: "+ $expression) Invoke-Expression $expression -ErrorAction Stop } catch { $msg = "Failed to create new volume: " + $VolumeName + ". Message: " + $_.Exception.Message; throw $msg } # Set options if($Options) { Get-WFALogger -Info -message $("Setting options " + $Options) foreach ($option in $Options.split(",")) { $option = $option.trim(); $pair = $option.split(" "); if($pair.Length -ne 2) { $msg = "Got wrong option pair '" + $option + "'. Options should be in key value format." throw $msg } try { Set-NcVolOption -Name $VolumeName -Key $pair[0] -Value $pair[1] -VserverContext $VserverName } catch { $msg = "Failed to set option. Key '" + $pair[0] + "' , value '" + $pair[1] + "'" throw $msg } } } # Set snapshot autodelete if($AutoDeleteOptions) { Get-WFALogger -Info -message $("Configuring auto delete options " + $AutoDeleteOptions) foreach ($option in $AutoDeleteOptions.split(",")) { $option = $option.trim(); $pair = $option.split(" "); if($pair.Length -ne 2) { $msg = "Got wrong autodelete option pair " + $option + ". Options should be in key value format." throw $msg } try { Set-NcSnapshotAutodelete -Name $VolumeName -Key $pair[0] -Value $pair[1] -VserverContext $VserverName } catch { $msg = "Failed to set autodelete option. Key '" + $pair[0] + "' , value '" + $pair[1] + "'" throw $msg } } } #Set volume auto size attributes try { $expression = "Set-NcVolAutosize -ErrorAction Stop -name " + $VolumeName + " -VserverContext " + $VserverName if ($AutosizeMaxSize) { $expression = $expression + " -MaximumSize " + ([string]$AutosizeMaxSize + "m") } if ($AutosizeIncrementSize) { $expression = $expression + " -IncrementSize " + ([string]$AutosizeIncrementSize + "m") } if ($AutosizeMode) { $expression = $expression + " -Mode " + $AutosizeMode } elseif ($AutosizeMaxSize -or $AutosizeIncrementSize) { if ($versionComparisionValue -lt 0) { $expression = $expression + " -Enabled " } else { $expression = $expression + " -Mode " + "grow_shrink" } } else { # both arguments have 0 - default values - valid situation } if ($AutosizeMode -or $AutosizeMaxSize -or $AutosizeIncrementSize) { # Set volume autosize attributes Get-WFALogger -Info -message $("Configuring volume autosize attributes: "+ $expression) Invoke-Expression $expression -ErrorAction Stop } } catch { $msg = "Failed to configure autosize attributes for volume " + $VolumeName + ". Message: " + $_.Exception.Message; throw $msg } #Set volume compression if($Compression -and $Compression -ne "disabled") { $ncSis = Get-NcSis -Name $VolumeName -VserverContext $VserverName if(!$ncSis -or $ncSis.State -eq "disabled") { Enable-NcSis -Name $VolumeName -VserverContext $VserverName } # Inline compression can only be set together with post process compression if($Compression -eq "inline") { Set-NcSis -Name $VolumeName -VserverContext $VserverName -Compression $true -InlineCompression $true -Schedule "-" } if($Compression -eq "background") { Set-NcSis -Name $VolumeName -VserverContext $VserverName -Compression $true -Schedule "-" } } # Set deduplication if($Deduplication) { Get-WFALogger -Info -message "Enabling deduplication" Enable-NcSis -Name $VolumeName -VserverContext $VserverName } # Set snapshot reserve percentage if($SnapshotReservePercentage -ne -1) { Get-WFALogger -Info -message $("Configuring snapshot reserve, percentage " + $SnapshotReservePercentage) Set-NcSnapshotreserve -Volume $VolumeName -Percentage $SnapshotReservePercentage -VserverContext $VserverName } #Defining the trap trap { Get-WFALogger -Info -message "Clearing the Reservation on this job for the Failed Command and the command which haven't been executed." $myWfaCreds = Get-WfaCredentials -Host "localhost" $workflowName = Get-WfaRestParameter "workflowName" $jobId = Get-WfaRestParameter "jobId" #Get the WFA http port $REGISTRY = "HKLM:\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\NA_WFA_SRV\Parameters\Java" $httpPort = (Get-ItemProperty $REGISTRY |select -ExpandProperty Options|where {$_ -match "-Dhttp.port"}).split("=")[1] $Url= 'http://localhost:' + $httpPort + '/rest/workflows?name=' + $WorkflowName #Get UUID of the workflow $uuid=(Invoke-RestMethod -Method get -Uri $url -Credential $myWfaCreds).collection.workflow.uuid #Prepare the new URL to clean reservation $Url2="http://localhost:" + $httpPort +"/rest/workflows/"+ $uuid + "/jobs/" + $jobId +"/reservation" #Invoke REST api. Invoke-RestMethod -Method Delete -Uri $Url2 -Credential $myWfaCreds Get-WfaLogger -Info -Messag "Reservation cleaned successfully" }