volumes.psm1


$volumeDefaultProps = ('name', 'index', 'vol-size', 'logical-space-in-use', 'naa-name', 'creation-time', 'iops')
# to out in a file
# Add-Content out.txt $vals

# startMeasureTime
# stopMeasureTime 'volume mod includes'
.(commonLib)         
       
##################### Completers templates #####################
<#
 
[Argumentcompleter( { doComplete $args 'volumes' name })]
[Argumentcompleter( { doComplete $args 'volumes' prop })]
[Argumentcompleter( { doComplete $args 'volumes' filter })]
 
initCommand
 
if($Full){ $Property = '' }
 
$result = formatOutPut $Property $result
 
finalizeCommand
return $result
 
#>


Function Get-XtremVolumes {
  <#
     .DESCRIPTION
      Displays the list of all Volumes and their defined parameters.
 
      .PARAMETER Properties
      Array of properties requested from this call.
 
      .PARAMETER Filter
      Array of filters for this call.
 
      .EXAMPLE
      Get-XtremVolumes -Filters "vol-type:eq:regular"
 
      .EXAMPLE
      Get-XtremVolumes -prop name,vol-size
 
      .EXAMPLE
      Get-XtremVolumes -Full
 
      .PARAMETER ShowRest
      Return an object represents the REST operation including URI , Method and JSON
 
      .EXAMPLE
      Get-XtremVolumes
  #>
 
    [cmdletbinding()]
    [Alias('xmsVolumeList')]
    Param( 
        [parameter()]                                    
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [parameter()]
        [Alias("Properties")]
        [Argumentcompleter( { doComplete $args 'volumes' prop })]    
        [array]$Property = $volumeDefaultProps,
        [parameter()]
        [Alias("Filters")]
        [Argumentcompleter( { doComplete $args 'volumes' filter })]  
        [array]$Filter,
        [Parameter()]
        [object]$Session = (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest,
        [Parameter()]
        [switch]$Full = $false
    )
    initCommand          

    $Route = '/types/volumes'

    if($Full){ $Property = '' }

    $result = NewXtremRequest -Method GET -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Properties $Property -ObjectSelection $ObjectSelection -Filters $Filter -ShowRest:$ShowRest.IsPresent -Multi -Full:$Full.IsPresent

    $result = formatOutPut $Property $result

    finalizeCommand
    return $result
}

Function Get-XtremVolume {
   <#
     .DESCRIPTION
      Displays details of the selected Volume. Use completer: [TAB] to circle or [Ctrl]+[Space] to view/select values.
 
      .PARAMETER VolName
      Volume's name or index number. Use [TAB] to circle or [Ctrl]+[Space] to view/select values.
 
      .PARAMETER Properties
      Array of properties requested from this call. Use [TAB] to circle or [Ctrl]+[Space] to view/select values.
 
      .PARAMETER ShowRest
      Return an object represents the REST operation including URI , Method and JSON
 
      .EXAMPLE
      Get-XtremVolume -VolName testvol
 
      .EXAMPLE
      Get-XtremVolume -VolName testvol -properties name,vol-size
  #>
   
    [cmdletbinding()]
    [Alias('xmsVolumeGet')]
    Param (
        [Alias("Name","Index")]
        [parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
        [Argumentcompleter( { doComplete $args 'volumes' name })] 
        $VolName,
        [Alias("Properties")]
        [Argumentcompleter( { doComplete $args 'volumes' prop })] 
        [array]$Property,
        [Parameter()]
        [switch]$ShowRest,
        [parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter()]
        [object]$Session = (Get-XtremDefaultSession)
    )
    initCommand
    $Route = '/types/volumes'
    $Route, $GetProperty = SetParametersForRequest $Route $VolName
    
    $result = NewXtremRequest -Method GET -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName  -GetProperty $GetProperty -Properties $Property -ShowRest:$ShowRest.IsPresent

    $result = formatOutPut $Property $result

    finalizeCommand
    return $result
}
  
Function New-XtremVolume {
 <#
     .DESCRIPTION
      Enables you to create a new Volume.
 
      .PARAMETER VolName
      Volume name.
 
      .PARAMETER VolumeSize
      Volume disk space size in: M(MB)/G(GB)/T(TB)/P(PB).
 
      .PARAMETER Lbsize
      Logical block size in bytes
 
      .PARAMETER SmallIoAlerts
      Enable or disable small input/output Alerts.
 
      .PARAMETER UnalignedIoAlerts
      Enable or disable unaligned I/O Alerts
 
      .PARAMETER AlignmentOffset
      The alignment offset for Volumes of 512 LB size is between 0 and 7. If omitted, the offset value is 0. Volumes of logical
      block size 4096 must not be defined with an offset.
 
      .PARAMETER VaaiTpAlerts
      Enable or disable VAAI TP Alerts.
 
      .PARAMETER TagList
      Tag ID list, list of ids: name or index
 
      .PARAMETER ManagmentLocked
      Swtich to Set managment locked on the new volume.
 
        .PARAMETER QoSEnabledMode
      QosEnabledMode
 
      .PARAMETER QoSPolicyId
      QoSPolicyId
 
      .PARAMETER Properties
      Array of properties requested from this call.
 
      .PARAMETER ShowRest
      Return an object represents the REST operation including URI , Method and JSON
 
      .EXAMPLE
      New-XtremVolume -volname testvol -volsize 1048m
  #>

    [CmdletBinding()]
    [Alias('xmsVolumeCreate')]
    Param(
        [Alias("Name","Index")]
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
        [Argumentcompleter( { doComplete $args 'volumes' name })]
        [ValidatePattern("^[^\[\]&\(\)`";,<>'/]+$")] 
        [String]$VolName,
        [Parameter(Mandatory=$true,Position=1)]
        [String]$VolSize,
        [Parameter()]
        [String]$LbSize,
        [Parameter()]
        [System.Nullable[Int]]$AlignmentOffset,
        [Parameter()]
        [ValidateSet('enabled','disabled')]
        [String]$SmallIoAlert,
        [Parameter()]
        [ValidateSet('enabled','disabled')]
        [String]$UnalignedIoAlerts,
        [Parameter()]
        [ValidateSet('enabled','disabled')]
        [String]$VaaiTpAlerts,
        [Parameter()]
        [array]$TagList,
        [Parameter()]
        [switch]$ManagmentLocked,
        [Parameter()]
        [ValidateSet('enabled','disabled','monitor_only')]
        [String]$QoSEnabledMode,
        [Parameter()]
        [Argumentcompleter( { doComplete $args 'qos-policies' name })] 
        $QoSPolicyId,
        [Parameter()]
        [switch]$ShowRest,
        [Parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter()]
        [object]$Session = (Get-XtremDefaultSession)
    )
    initCommand 
    $Route = '/types/volumes'
    $BodyList = @{}

    $IsClusterX2 = $false;

    $ClusterType = $Session.GetXtremInternalClusterType($XtremClusterName)
    if ($ClusterType -eq 'X2')    {
        $IsClusterX2 = $true;
    }

    AddIfExists -name "cluster-id" -value $XtremClusterName -list $BodyList
    AddIfExists -name "vol-name" -value $volName -list $BodyList
    AddIfExists -name "vol-size" -value $volSize -list $BodyList
    AddIfExists -name "lb-size" -value $LBSize -list $BodyList
    AddIfExists -name "alignment-offset" -value $AlignmentOffset -list $BodyList
    AddIfExists -name "small-io-alerts" -value $SmallIoAlerts -list $BodyList
    AddIfExists -name "unaligned-io-alerts" -value $UnalignedIoAlerts -list $BodyList
    AddIfExists -name "vaai-tp-alerts" -value $VaaiTpAlerts -list $BodyList
    AddIfExists -name "tag-list" -value $TagList -list $BodyList
    AddIfExists -name "qos-enabled-mode" -value $QoSEnabledMode -list $BodyList
    AddIfExists -name "qos-policy-id" -value $QoSPolicyId -list $BodyList
    AddIfExists -name "created-by-external-client" -value 'PowerShell' -list $BodyList

    if ($ManagmentLocked.IsPresent -and $IsClusterX2) {
        AddIfExists -name "management-locked" -value "true" -list $BodyList
    }

    $Body = BuildXtremJson -list $BodyList

    $result = NewXtremRequest -Method POST -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Body $Body -ObjectSelection $ObjectSelection -ShowRest:$ShowRest.IsPresent

    finalizeCommand 
    return $result
}

Function Set-XtremVolume {
   <#
     .DESCRIPTION
      Enables you to modify properties of the selected Volume.
 
      .PARAMETER VolName
      Volume name or index number
 
      .PARAMETER UnalignedIoAlerts
      Enable or disable unaligned input/output Alerts.
 
      .PARAMETER SmallIoAlerts
      Enable or disable small input/output Alerts
 
      .PARAMETER VaaiTpAlerts
      Enable or disable VAAI TP Alerts.
 
      .PARAMETER VolAccess
      A Volume is created with write access rights. Volumes can be modified after being created and have their access levels' changed.
 
      .PARAMETER NewVolName
      New volume name.
 
      .PARAMETER VolumeSize
      Volume disk space size in: M(MB)/G(GB)/T(TB)/P(PB).
 
      .PARAMETER ManagmentLocked
      Set managment locked on the volume. can be True or False.
 
      .PARAMETER QoSEnabledMode
      QosEnabledMode
 
        .PARAMETER QoSPolicyId
      QoSPolicyId
       
      .PARAMETER RemoveQoSPolicy
      Remove associated QoS policy.
 
      .PARAMETER ShowRest
      Return an object represents the REST operation including URI , Method and JSON
 
      .EXAMPLE
      Set-XtremVolume -VolName testvol -SmallIoAlerts disabled
 
      .EXAMPLE
      Set-XtremVolume -xioname 10.4.45.24 -username admin -password Xtrem10 -volname testvol -volsize 1048m
 
  #>

    [CmdletBinding()]
    [Alias('xmsVolumeModify')]
    Param(
        [Parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Alias("Name","Index")]
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
        [Argumentcompleter( { doComplete $args 'volumes' name })] 
        $VolName,
        [Parameter()]
        [ValidateSet('enabled','disabled')]
        $SmallIoAlerts,
        [Parameter()]
        [ValidateSet('enabled','disabled')]
        $UnalignedIoAlerts,
        [Parameter()]
        [ValidateSet('enabled','disabled')]
        $VaaiTpAlerts,
        [Parameter()]
        [ValidateSet('write_access', 'read_access', 'no_access')]
        $VolAccess,
        [Parameter()]
        [ValidatePattern("^[^\[\]&\(\)`";,<>'/]+$")] 
        $NewVolName,
        [Parameter()]
        $VolSize,
        [Parameter()]
        [System.Nullable[Bool]]$ManagmentLocked,
        [Parameter()]
        [ValidateSet('enabled','disabled','monitor_only')]
        [String]$QoSEnabledMode,
        [Parameter()]
        [Argumentcompleter( { doComplete $args 'qos-policies' name })] 
        $QoSPolicyId,
        [Parameter()]
        [switch]$RemoveQoSPolicy,
        [Parameter()]
        [object]$Session = (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand 

    $Route = '/types/volumes'
    $Route, $GetProperty = SetParametersForRequest $Route $VolName

    $BodyList = @{}

    $IsClusterX2 = $false;
    
    $ClusterType = $Session.GetXtremInternalClusterType($XtremClusterName)
    
    if ($ClusterType -eq 'X2') {
        $IsClusterX2 = $true;
    }
    
    AddIfExists -name "cluster-id" -value $XtremClusterName -list $BodyList
    AddIfExists -name "vol-name" -value $NewVolName -list $BodyList
    AddIfExists -name "vol-size" -value $VolSize -list $BodyList
    AddIfExists -name "small-io-alerts" -value $SmallIoAlerts -list $BodyList
    AddIfExists -name "unaligned-io-alerts" -value $UnalignedIoAlerts -list $BodyList
    AddIfExists -name "vaai-tp-alerts" -value $VaaiTpAlerts -list $BodyList
    AddIfExists -name "vol-access" -value $VolAccess -list $BodyList
    AddIfExists -name "qos-enabled-mode" -value $QoSEnabledMode -list $BodyList
    AddIfExists -name "qos-policy-id" -value $QoSPolicyId -list $BodyList
    AddIfExists -name "remove-qos-policy" -value $RemoveQoSPolicy.IsPresent -list $BodyList
    
    if ($ManagmentLocked -ne $null -and $IsClusterX2) {
        if ($ManagmentLocked -eq $True) {
            AddIfExists -name "management-locked" -value "enabled" -list $BodyList
        } else {
            AddIfExists -name "management-locked" -value "disabled" -list $BodyList
        }
    }
    $Body = BuildXtremJson -list $BodyList

    $result = NewXtremRequest -Method PUT -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Body $Body -ObjectSelection $ObjectSelection -GetProperty $GetProperty -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}

#Deletes a Volume
Function Remove-XtremVolume {
  <#
     .DESCRIPTION
      Enables you to delete a Volume.
 
      .PARAMETER VolName
      Volume's name or index number.
 
      .PARAMETER ShowRest
      Return an object represents the REST operation including URI , Method and JSON
 
      .EXAMPLE
      Remove-XtremVolume -VolName testvol
  #>

    [CmdletBinding()]
    [Alias('xmsVolumeRemove')]
    Param(
        [Parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Alias("Name","Index")]
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
        [Argumentcompleter( { doComplete $args 'volumes' name })] 
        $VolName,
        [Parameter()]
        [bool]$Confirm =  (Get-XtremDefaultSession)._XtremCLIMode,
        [Parameter()]
        [object]$Session = (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    
    $confirmed = IsConfirmed $Confirm
    if (!$confirmed) {
        return
    }
    initCommand 

    $Route = '/types/volumes'
    $Route, $GetProperty = SetParametersForRequest $Route $VolName

    $result = NewXtremRequest -Method DELETE -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -GetProperty $GetProperty -ShowRest:$ShowRest.IsPresent
    
    finalizeCommand 
    return $result
}

Export-ModuleMember *-* -Alias *