Modules/mtree.psm1
#GET /rest/v1.0/dd-systems/{SYSTEM-ID}/mtrees function Get-DDmtrees { [CmdletBinding()] param ( [CmdletBinding()] [Parameter(Mandatory = $true, ParameterSetName = 'byID', ValueFromPipelineByPropertyName = $true)] [string]$id, [Parameter(Mandatory = $false, ParameterSetName = 'byID')] [Parameter(Mandatory = $false, ParameterSetName = 'all')] [string] $SYSTEM_ID = $Global:DD_UUID, $body = @{size = 200 } ) begin { $Response = @() $METHOD = "GET" } process { switch ($PsCmdlet.ParameterSetName) { default { $apiver = "rest/v1.0" $uri = "dd-systems/$($SYSTEM_ID)/mtrees" } 'byID' { $apiver = "rest/v3.0" $uri = "dd-systems/$($SYSTEM_ID)/mtrees/$ID" $body = @{} } } $parameters = @{ uri = $uri apiver = $apiver Method = $METHOD body = $body RequestMethod = "REST" Verbose = $PSBoundParameters['Verbose'] -eq $true Debug = $PSBoundParameters['Debug'] -eq $true } try { $Response += Invoke-DDapirequest @Parameters } catch { Get-DDWebException -ExceptionMessage $_ break } write-verbose ($response | Out-String) } end { switch ($PsCmdlet.ParameterSetName) { default { $response.mtree | Select-Object -ExcludeProperty link } 'byID' { $response | Select-Object -Property * -ExcludeProperty link } } } } # get /rest/v3.0/dd-systems/{SYSTEM-ID}/stats/performances/mtrees/{ID} <# .SYNOPSIS .PARAMETER 1 .PARAMETER 2 .Example .Example .Example #> function Get-DDmtreesPerformances { [CmdletBinding()] param ( [CmdletBinding()] [Parameter(Mandatory = $true, ParameterSetName = 'byID', ValueFromPipelineByPropertyName = $true)] [string]$id, [Parameter(Mandatory = $false, ParameterSetName = 'byID')] [string] $SYSTEM_ID = $Global:DD_UUID, $body = @{} ) begin { $Response = @() $METHOD = "GET" } process { switch ($PsCmdlet.ParameterSetName) { default { $apiver = "rest/v3.0" $uri = "dd-systems/$($SYSTEM_ID)/mtrees" } 'byID' { $apiver = "rest/v3.0" $uri = "dd-systems/$($SYSTEM_ID)/stats/performances/mtrees/$ID" } } $parameters = @{ uri = $uri apiver = $apiver Method = $METHOD body = $body RequestMethod = "REST" Verbose = $PSBoundParameters['Verbose'] -eq $true Debug = $PSBoundParameters['Debug'] -eq $true } try { $Response += Invoke-DDapirequest @Parameters } catch { Get-DDWebException -ExceptionMessage $_ break } write-verbose ($response | Out-String) } end { switch ($PsCmdlet.ParameterSetName) { 'default' { $response | Select-Object -ExcludeProperty link } 'byID' { $response.mtree_show_perf_detail | Select-Object -Property @{N = "id"; E = { $id } }, * -ExcludeProperty links } } } } #POST/rest/v1.0/dd-systems/{SYSTEM-ID}/mtrees function New-DDMtree { [CmdletBinding()] param ( [CmdletBinding()] [Parameter(Mandatory = $true, ParameterSetName = 'default' )] [string][alias('name')]$mtree_name, [Parameter(Mandatory = $false, ParameterSetName = 'default' )] [string][alias('unit')]$tenant_unit, [Parameter(Mandatory = $false, ParameterSetName = 'default' )] [Int64][ValidateRange(0, 64000)]$hard_limit = 0, [Parameter(Mandatory = $false, ParameterSetName = 'default' )] [Int64][ValidateRange(0, 64000)]$soft_limit = 0, [string] $SYSTEM_ID = $Global:DD_UUID ) begin { $Response = @() $METHOD = "POST" $apiver = "rest/v1.0" } process { $body = @{} $uri = "dd-systems/$($SYSTEM_ID)/mtrees" $body.Add('name', $mtree_name) if ($tenant_unit) { $body.add('tenant_unit', $tenant_unit) } $body.Add('quota_config', @{}) $body.quota_config.Add('hard_limit', $hard_limit) $body.quota_config.Add('soft_limit', $soft_limit) $body = $body | ConvertTo-Json -Depth 4 Write-Verbose ($body | Out-String) $parameters = @{ uri = $uri apiver = $apiver Method = $METHOD body = $body RequestMethod = "REST" Verbose = $PSBoundParameters['Verbose'] -eq $true Debug = $PSBoundParameters['Debug'] -eq $true } try { $Response += Invoke-DDapirequest @Parameters } catch { Get-DDWebException -ExceptionMessage $_ break } write-verbose ($response | Out-String) } end { switch ($PsCmdlet.ParameterSetName) { default { $response | Select-Object -ExcludeProperty link, links } } } } # PUT /rest/v2.0/dd-systems/{SYSTEM-ID}/mtrees/{ID} function Set-DDMtree { [CmdletBinding()] param ( [CmdletBinding()] [Parameter(Mandatory = $true, ParameterSetName = 'retention' )] [Parameter(Mandatory = $true, ParameterSetName = 'default' )] [string][alias('mtree_id')]$id, [Parameter(Mandatory = $false, ParameterSetName = 'default' )] [string][alias('unit')]$tenant_unit, [Parameter(Mandatory = $false, ParameterSetName = 'default' )] [Int64][ValidateRange(0, 64000)]$hard_limit = 0, [Parameter(Mandatory = $false, ParameterSetName = 'default' )] [Int64][ValidateRange(0, 64000)]$soft_limit = 0, [Parameter(Mandatory = $false, ParameterSetName = 'retention' )] [switch]$retention, [Parameter(Mandatory = $false, ParameterSetName = 'retention' )] [string][ValidateSet('governance', 'compliance')]$retention_mode, [Parameter(Mandatory = $false, ParameterSetName = 'retention' )] [string][ValidateSet('set', 'reset')]$retention_lock_period_limit, [Parameter(Mandatory = $false, ParameterSetName = 'retention' )] [string][ValidateSet('min', 'max')]$retention_lock_period_limit_type = 'min', [Parameter(Mandatory = $false, ParameterSetName = 'retention' )] [int64]$retention_lock_period_limit_period = 0, [string] $SYSTEM_ID = $Global:DD_UUID ) begin { $Response = @() $METHOD = "PUT" $apiver = "rest/v2.0" } process { $body = @{} $uri = "dd-systems/$($SYSTEM_ID)/mtrees/$mtree_id" if ($tenant_unit) { $body.add('tenant_unit', $tenant_unit) } switch ($PsCmdlet.ParameterSetName) { default { $body.Add('quota_config', @{}) $body.quota_config.Add('hard_limit', $hard_limit) $body.quota_config.Add('soft_limit', $soft_limit) } 'retention' { $body.add('retention_lock', @{}) $body.retention_lock.Add('enable', $retention.IsPresent) $body.retention_lock.Add('mode', $retention_mode) if ($retention_lock_period_limit) { $body.add('retention_lock_period_limit', @{}) $body.retention_lock_period_limit.Add('limit_operation', $retention_lock_period_limit) $body.retention_lock_period_limit.Add('limit_value', $retention_lock_period_limit_period) $body.retention_lock_period_limit.Add('limit_type', $retention_lock_period_limit_type) } } } $body = $body | ConvertTo-Json -Depth 4 Write-Verbose ($body | Out-String) $parameters = @{ uri = $uri apiver = $apiver Method = $METHOD body = $body RequestMethod = "REST" Verbose = $PSBoundParameters['Verbose'] -eq $true Debug = $PSBoundParameters['Debug'] -eq $true } try { $Response += Invoke-DDapirequest @Parameters } catch { Get-DDWebException -ExceptionMessage $_ break } write-verbose ($response | Out-String) } end { switch ($PsCmdlet.ParameterSetName) { default { $response | Select-Object -ExcludeProperty link, links } } } } # DELETE /rest/v1.0/dd-systems/{SYSTEM-ID}/mtrees/{ID} function Remove-DDMtree { [CmdletBinding()] param ( [CmdletBinding()] [Parameter(Mandatory = $true, ParameterSetName = 'byID', ValueFromPipelineByPropertyName=$true)] [string][alias('mtree_id')]$id, [string] $SYSTEM_ID = $Global:DD_UUID ) begin { $Response = @() $METHOD = "DELETE" $apiver = "rest/v1.0" } process { switch ($PsCmdlet.ParameterSetName) { default { $uri = "dd-systems/$($SYSTEM_ID)/mtrees/$ID" } } $body = $body | ConvertTo-Json Write-Verbose ($body | Out-String) $parameters = @{ uri = $uri apiver = $apiver Method = $METHOD RequestMethod = "REST" Verbose = $PSBoundParameters['Verbose'] -eq $true Debug = $PSBoundParameters['Debug'] -eq $true } try { $Response += Invoke-DDapirequest @Parameters } catch { Get-DDWebException -ExceptionMessage $_ break } write-verbose ($response | Out-String) } end { switch ($PsCmdlet.ParameterSetName) { default { $response | Select-Object -ExcludeProperty links, link, paging_info } } } } <# .Synopsis .Example Get-DDMtreeStats -id %2Fdata%2Fcol1%2Fawsbackup -capacity_stats collection_time tier_capacity_usage tier_data_written --------------- ------------------- ----------------- 16.03.2021 11:00:00 {@{tier=active; logical_capacity=}, @{tier=cloud; logical_capacity=}} {@{tier=active; pre_comp_written=0; post_comp_written=0; compression_factor=0}, @{tier=cloud; pre_comp_written=0; post_comp_written=0; compression_factor=0}} 17.03.2021 11:00:00 {@{tier=active; logical_capacity=}, @{tier=cloud; logical_capacity=}} {@{tier=active; pre_comp_written=0; post_comp_written=0; compression_factor=0}, @{tier=cloud; pre_comp_written=0; post_comp_written=0; compression_factor=0}} 18.03.2021 11:00:00 {@{tier=active; logical_capacity=}, @{tier=cloud; logical_capacity=}} {@{tier=active; pre_comp_written=0; post_comp_written=0; compression_factor=0}, @{tier=cloud; pre_comp_written=0; post_comp_written=0; compression_factor=0}} 19.03.2021 11:00:00 {@{tier=active; logical_capacity=}, @{tier=cloud; logical_capacity=}} {@{tier=active; pre_comp_written=0; post_comp_written=0; compression_factor=0}, @{tier=cloud; pre_comp_written=0; post_comp_written=0; compression_factor=0}} 20.03.2021 11:00:00 {@{tier=active; logical_capacity=}, @{tier=cloud; logical_capacity=}} {@{tier=active; pre_comp_written=0; post_comp_written=0; compression_factor=0}, @{tier=cloud; pre_comp_written=0; post_comp_written=0; compression_factor=0}} 21.03.2021 11:00:00 {@{tier=active; logical_capacity=}, @{tier=cloud; logical_capacity=}} {@{tier=active; pre_comp_written=0; post_comp_written=0; compression_factor=0}, @{tier=cloud; pre_comp_written=0; post_comp_written=0; compression_factor=0}} 22.03.2021 11:00:00 {@{tier=active; logical_capacity=}, @{tier=cloud; logical_capacity=}} {@{tier=active; pre_comp_written=0; post_comp_written=0; compression_factor=0}, @{tier=cloud; pre_comp_written=0; post_comp_written=0; compression_factor=0}} .Example Get-DDMtreeStats -id %2Fdata%2Fcol1%2Fawsbackup data_interval retention_days resource_name ------------- -------------- ------------- day 366 capacity week 3661 capacity #> # Get /rest/v2.0/dd-systems/{SYSTEM-ID}/mtrees/{ID}/stats # GET /rest/v2.0/dd-systems/{SYSTEM-ID}/mtrees/{ID}/stats/capacity function Get-DDMtreeStats { [CmdletBinding()] param ( [CmdletBinding()] [Parameter(Mandatory = $true, ParameterSetName = 'mtree-stats')] [Parameter(Mandatory = $true, ParameterSetName = 'capacity')] [string][alias('mtree_id')]$id, [Parameter(Mandatory = $true, ParameterSetName = 'capacity')] [switch]$capacity_stats, [string] $SYSTEM_ID = $Global:DD_UUID, $body = @{} ) begin { $Response = @() $METHOD = "GET" } process { $apiver = "rest/v2.0" $uri = "dd-systems/$($SYSTEM_ID)/mtrees/$($id)/stats" switch ($PsCmdlet.ParameterSetName) { default { } 'capacity' { $uri = join-path $uri $PsCmdlet.ParameterSetName } } write-verbose ($body | Out-String) $parameters = @{ uri = $uri apiver = $apiver Method = $METHOD body = $body RequestMethod = "REST" Verbose = $PSBoundParameters['Verbose'] -eq $true } try { $Response += Invoke-DDapirequest @Parameters } catch { Get-DDWebException -ExceptionMessage $_ break } write-verbose ($response | Out-String) } end { switch ($PsCmdlet.ParameterSetName) { default { $response.stats | Select-Object -ExcludeProperty link, links, retention_info -ExpandProperty retention_info } 'capacity' { $response.stats_capacity | Select-Object -ExcludeProperty link,links,collection_epoch -Property @{N="collection_time";E={(Get-Date 01.01.1970)+([System.TimeSpan]::fromseconds($_.collection_epoch))}},* } } } } |