Public/New-UnityPool.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
Function New-UnityPool {

  <#
      .SYNOPSIS
      Creates a new storage pool.
      .DESCRIPTION
      Creates a new storage pool. Storage pools are the groups of disks on which you create storage resources like LUN or filesystems.
      You need to have an active session with the array.
      .NOTES
      Written by Erwan Quelin under MIT licence - https://github.com/equelin/Unity-Powershell/blob/master/LICENSE
      .LINK
      https://github.com/equelin/Unity-Powershell
      .PARAMETER Session
      Specify an UnitySession Object.
      .PARAMETER Name
      Name of the pool.
      .PARAMETER Description
      Description of the pool.
      .PARAMETER virtualDisk
      Virtual Disks only with associated parameters to add to the pool. See examples for details.
      .PARAMETER raidGroup
      Parameters to add RAID groups to the pool (disk group, number of disks, RAID level, stripe length). See examples for details.
      .PARAMETER isFASTCacheEnabled
      Specify whether to enable FAST Cache on the storage pool.
      .PARAMETER isFASTVpScheduleEnabled
      Specify whether to enable scheduled data relocations for the pool.
      .PARAMETER alertThreshold
      For thin provisioning, specify the threshold, as a percentage, when the system will alert on the amount of subscription space used.
      .PARAMETER isHarvestEnabled
      Indicate whether the system should check the pool full high water mark for autodelete.
      .PARAMETER poolSpaceHarvestHighThreshold
      Specify the pool full high watermark for the storage pool.
      .PARAMETER poolSpaceHarvestLowThreshold
      Specify the pool full low watermark for the storage pool.
      .PARAMETER isSnapHarvestEnabled
      Indicate whether the system should check the snapshot space used high water mark for auto-delete.
      .PARAMETER snapSpaceHarvestHighThreshold
      Specify the snapshot space used high watermark to trigger auto-delete on the storage pool.
      .PARAMETER snapSpaceHarvestLowThreshold
      Specify the snapshot space used low watermark to trigger auto-delete on the storage pool.
      .PARAMETER Confirm
      If the value is $true, indicates that the cmdlet asks for confirmation before running. If the value is $false, the cmdlet runs without asking for user confirmation.
      .PARAMETER WhatIf
      Indicate that the cmdlet is run only to display the changes that would be made and actually no objects are modified.
      .EXAMPLE
      New-UnityPool -Name 'POOL01' -virtualDisk @{"id"='vdisk_1';"tier"='Extreme_Performance'},@{"id"='vdisk_2';"tier"='Capacity'}

      Create pool named 'POOL01' with virtual disks 'vdisk_1' and 'vdisk_2'. Virtual disks are assigned to the Extreme Performance and Capacity tier. Apply to Unity VSA only.
      .EXAMPLE
      New-UnityPool -Name 'POOL01' -raidGroup @{"id"='dg_11';"numDisks"= 15; 'raidType'='RAID5'; 'stripeWidth'='5'}

      Create pool named 'POOL01' with with 15 disks from diskgroup ID 'dg_11'.RAID protection is a 'RAID5' with a stripe width of 5 (4+1). Apply to physical deployment only.
  #>


  [CmdletBinding(SupportsShouldProcess = $True,ConfirmImpact = 'High',DefaultParameterSetName="RaidGroup")]
  Param (
    #Default Parameters
    [Parameter(Mandatory = $false,HelpMessage = 'EMC Unity Session')]
    $session = ($global:DefaultUnitySession | where-object {$_.IsConnected -eq $true}),
    
    #UnityPool
    [Parameter(Mandatory = $true,Position = 1,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True,HelpMessage = 'Pool Name')]
    [String[]]$Name,
    [Parameter(Mandatory = $false,HelpMessage = 'Pool Description')]
    [String]$Description,
    [Parameter(Mandatory = $true,ParameterSetName="VirtualDisk",HelpMessage = 'Parameters to add virtual disks to the pool')]
    [array]$virtualDisk,
    [Parameter(Mandatory = $true,ParameterSetName="RaidGroup",HelpMessage = 'Parameters to add RAID groups to the pool')]
    [array]$raidGroup,
    [Parameter(Mandatory = $false,HelpMessage = 'Threshold at which the system will generate alerts about the free space in the pool')]
    [Int]$alertThreshold,
    [Parameter(Mandatory = $false,HelpMessage = 'Pool used space high threshold at which the system will automatically starts to delete snapshots in the pool, specified as a percentage with .01% granularity')]
    [Long]$poolSpaceHarvestHighThreshold,
    [Parameter(Mandatory = $false,HelpMessage = 'Pool used space low threshold under which the system will automatically stop deletion of snapshots in the pool, specified as a percentage with .01% granularity')]
    [Long]$poolSpaceHarvestLowThreshold,
    [Parameter(Mandatory = $false,HelpMessage = 'Snapshot used space high threshold at which the system automatically starts to delete snapshots in the pool, specified as a percentage with .01% granularity.')]
    [Long]$snapSpaceHarvestHighThreshold,
    [Parameter(Mandatory = $false,HelpMessage = 'Snapshot used space low threshold below which the system will stop automatically deleting snapshots in the pool, specified as a percentage with .01% granularity.')]
    [Long]$snapSpaceHarvestLowThreshold,
    [Parameter(Mandatory = $false,HelpMessage = 'Is Harvest Enabled?')]
    [Bool]$isHarvestEnabled,
    [Parameter(Mandatory = $false,HelpMessage = 'Is Snapshot Harvest Enabled')]
    [Bool]$isSnapHarvestEnabled,
    [Parameter(Mandatory = $false,HelpMessage = 'Is FAST Cache Enabled?')]
    [Bool]$isFASTCacheEnabled,
    [Parameter(Mandatory = $false,HelpMessage = 'Is FAST Vp Schedule Enabled?')]
    [Bool]$isFASTVpScheduleEnabled
  )

  Begin {
    Write-Debug -Message "[$($MyInvocation.MyCommand)] Executing function"

    ## Variables
    $URI = '/api/types/pool/instances'
    $Type = 'Pool'
    $StatusCode = 201

    $tier = @{
      "Extreme_Performance" = "10"
      "Performance" = "20"
      "Capacity" = "30"
    }

    $Raid =@{
      "None" = "0"
      "RAID5" = "1"
      "RAID0" = "2"
      "RAID1" = "3"
      "RAID3" = "4"
      "RAID10" = "7"
      "RAID6" = "10"
      "Mixed" = "12"
      "Automatic" = "48879"
    }
  }

  Process {
    Foreach ($sess in $session) {

      Write-Debug -Message "Processing Session: $($sess.Server) with SessionId: $($sess.SessionId)"

      Foreach ($n in $Name) {

        #### REQUEST BODY

        # Creation of the body hash
        $body = @{}

        # Name parameter
        $body["name"] = "$($n)"

        # Description parameter
        If ($Description) {
              $body["description"] = "$($Description)"
        }

        If ($virtualDisk) {

          # addPoolUnitParameters parameter
          $body["addPoolUnitParameters"] = @()

          Foreach ($vdisk in $virtualDisk) {
            $addPoolUnitParameters = @{}
            $addPoolUnitParameters["poolUnit"] = @{}

            $poolUnit = @{}
            $poolUnit["id"] = "$($vdisk['id'])"

            $tierType = "$($tier["$($vdisk['tier'])"])"

            $addPoolUnitParameters["poolUnit"] = $poolUnit
            $addPoolUnitParameters["tierType"] = $tierType

            $body["addPoolUnitParameters"] += $addPoolUnitParameters
          }
        }

        If ($raidGroup) {

          # addRaidGroupParameters parameter
          $body["addRaidGroupParameters"] = @()

            Foreach ($rg in $raidGroup) {
              $addRaidGroupParameters = @{}
              $addRaidGroupParameters["dskGroup"] = @{}

                $diskGroup = @{}
                $diskGroup["id"] = "$($rg['id'])"

              $addRaidGroupParameters["dskGroup"] = $diskGroup

              $addRaidGroupParameters["numDisks"] = "$($rg['numDisks'])"
              $addRaidGroupParameters["raidType"] = "$($raid["$($rg['raidType'])"])"
              $addRaidGroupParameters["stripeWidth"] = "$($rg['stripeWidth'])"
              
              $body["addRaidGroupParameters"] += $addRaidGroupParameters
            }
        }

        If ($alertThreshold) {
              $body["alertThreshold"] = "$($alertThreshold)"
        }

        If ($poolSpaceHarvestHighThreshold) {
              $body["poolSpaceHarvestHighThreshold"] = "$($poolSpaceHarvestHighThreshold)"
        }

        If ($poolSpaceHarvestLowThreshold) {
              $body["poolSpaceHarvestLowThreshold"] = "$($poolSpaceHarvestLowThreshold)"
        }

        If ($snapSpaceHarvestHighThreshold) {
              $body["snapSpaceHarvestHighThreshold"] = "$($snapSpaceHarvestHighThreshold)"
        }

        If ($snapSpaceHarvestLowThreshold) {
              $body["snapSpaceHarvestLowThreshold"] = "$($snapSpaceHarvestLowThreshold)"
        }

        If ($PSBoundParameters.ContainsKey('isHarvestEnabled')) {
              $body["isHarvestEnabled"] = $isHarvestEnabled
        }

        If ($PSBoundParameters.ContainsKey('isSnapHarvestEnabled')) {
              $body["isSnapHarvestEnabled"] = $isSnapHarvestEnabled
        }

        If ($PSBoundParameters.ContainsKey('isFASTCacheEnabled')) {
              $body["isFASTCacheEnabled"] = $isFASTCacheEnabled
        }

        If ($PSBoundParameters.ContainsKey('isFASTVpScheduleEnabled')) {
              $body["isFASTVpScheduleEnabled"] = $isFASTVpScheduleEnabled
        }

        ####### END BODY - Do not edit beyond this line

        #Show $body in verbose message
        $Json = $body | ConvertTo-Json -Depth 10
        Write-Verbose $Json  

        If ($Sess.TestConnection()) {

          ##Building the URL
          $URL = 'https://'+$sess.Server+$URI
          Write-Verbose "URL: $URL"

          #Sending the request
          If ($pscmdlet.ShouldProcess($Sess.Name,"Create $Type $n")) {
            $request = Send-UnityRequest -uri $URL -Session $Sess -Method 'POST' -Body $Body
          }

          Write-Verbose "Request status code: $($request.StatusCode)"

          If ($request.StatusCode -eq $StatusCode) {

            #Formating the result. Converting it from JSON to a Powershell object
            $results = ($request.content | ConvertFrom-Json).content

            Write-Verbose "$Type with the ID $($results.id) has been created"

            Get-UnityPool -Session $Sess -ID $results.id
          } # End If ($request.StatusCode -eq $StatusCode)
        } # End If ($Sess.TestConnection())
      } # End Foreach
    } # End Foreach ($sess in $session)
  } # End Process
} # End Function