Modules/data-movement.psm1

# Get /rest/v1.0/dd-systems/{SYSTEM-ID}/data-movement
function Get-DDDataMovement {
    [CmdletBinding()]
    param ( 
        [CmdletBinding()]
        [Parameter(Mandatory = $true, ParameterSetName = 'byID', ValueFromPipelineByPropertyName = $true)]
        [string]$id,                  
        [Parameter(Mandatory = $false, ParameterSetName = 'byID')]
        [Parameter(Mandatory = $false, ParameterSetName = 'default')]
 
        [string]
        $SYSTEM_ID = $Global:DD_UUID,
        [Parameter(Mandatory = $false, ParameterSetName = 'default')]
        $body = @{}
    )
    begin {
        $Response = @()
        $METHOD = "GET"
    }
    process {
        switch ($PsCmdlet.ParameterSetName) {
            default {
                $apiver = "api/v2"
                $uri = "dd-systems/$($SYSTEM_ID)/data-movement"
            }
            'byID' {
                $body = @{}
                $apiver = "rest/v1.0"
                $uri = "dd-systems/$($SYSTEM_ID)/data-movement/$ID"
            }               
        }
        $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.status | Select-Object -ExcludeProperty links, link, -Property *, @{N = "start"; E = { (Get-Date 01.01.1970) + ([System.TimeSpan]::fromseconds($_.start_time)) } }, @{N = "end"; E = { (Get-Date 01.01.1970) + ([System.TimeSpan]::fromseconds($_.end_time)) } }
            }
            'byID' {
                $response  | Select-Object -Property * -ExcludeProperty link
            }           
        } 
       
    }
}
# GET /rest/v1.0/dd-systems/{SYSTEM-ID}/data-movement-policies/{ID}

function Get-DDDataMovementPolicies {
    [CmdletBinding()]
    param ( 
        [CmdletBinding()]
        [Parameter(Mandatory = $true, ParameterSetName = 'byID', ValueFromPipelineByPropertyName = $true)]
        [string]$id,                  
        [Parameter(Mandatory = $false, ParameterSetName = 'byID')]
        [Parameter(Mandatory = $false, ParameterSetName = 'default')]
        [string]
        $SYSTEM_ID = $Global:DD_UUID,
        [Parameter(Mandatory = $false, ParameterSetName = 'default')]
        $body = @{}
    )
    begin {
        $Response = @()
        $METHOD = "GET"
    }
    process {
        switch ($PsCmdlet.ParameterSetName) {
            default {
                $apiver = "rest/v1.0"
                $uri = "dd-systems/$($SYSTEM_ID)/data-movement-policies"
            }
            'byID' {
                $body = @{}
                $apiver = "rest/v1.0"
                $uri = "dd-systems/$($SYSTEM_ID)/data-movement-policies/$ID"
            }               
        }
        $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.data_movement_policies | Select-Object -ExcludeProperty links, link, -Property *, @{N = "start"; E = { (Get-Date 01.01.1970) + ([System.TimeSpan]::fromseconds($_.start_time)) } }, @{N = "end"; E = { (Get-Date 01.01.1970) + ([System.TimeSpan]::fromseconds($_.end_time)) } }
            }
            'byID' {
                $response  | Select-Object -Property * -ExcludeProperty link
            }           
        } 
       
    }
}

# Get /rest/v1.0/dd-systems/{SYSTEM-ID}/data-movement/stats/mtrees
function Get-DDDataMovementStats {
    [CmdletBinding()]
    param ( 
        [CmdletBinding()]
        [Parameter(Mandatory = $true, ParameterSetName = 'files')]
        [switch]$files,    
        [Parameter(Mandatory = $true, ParameterSetName = 'mtrees')]
        [switch]$mtrees,
        [string]
        $SYSTEM_ID = $Global:DD_UUID,
        $body = @{}
    )
    begin {
        $Response = @()
        $METHOD = "GET"
    }
    process {
        switch ($PsCmdlet.ParameterSetName) {
            'files' {
                $apiver = "api/v2"
                $uri = "dd-systems/$($SYSTEM_ID)/data-movement/stats/files"
            }
            'mtrees' {
                $apiver = "rest/v1.0"
                $uri = "dd-systems/$($SYSTEM_ID)/data-movement/stats/mtrees"
            }               
        }
        $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.status | Select-Object -ExcludeProperty links, link, -Property *, @{N = "start"; E = { (Get-Date 01.01.1970) + ([System.TimeSpan]::fromseconds($_.start_time)) } }, @{N = "end"; E = { (Get-Date 01.01.1970) + ([System.TimeSpan]::fromseconds($_.end_time)) } }
            }
        } 
       
    }
}
# PUT /rest/v1.0/dd-systems/{SYSTEM-ID}/data-movement

function Set-DDDataMovement {
    [CmdletBinding()]
    param ( 
        [CmdletBinding()]
        [Parameter(Mandatory = $false, ParameterSetName = 'start')]
        [switch]$start,
        [Parameter(Mandatory = $false, ParameterSetName = 'start')]
        [string[]]$mtrees,
        [Parameter(Mandatory = $false, ParameterSetName = 'start')]
        [string]$cloud_unit,
        $SYSTEM_ID = $Global:DD_UUID
    )
    begin {
        $Response = @()
        $METHOD = "PUT"
    }
    process {
        $apiver = "rest/v1.0"
        $uri = "dd-systems/$($SYSTEM_ID)/data-movement"
        $json = @{ operation = $PsCmdlet.ParameterSetName }
        switch ($PsCmdlet.ParameterSetName) {
            default {
            }
            'start' {

                if ($mtrees -or $cloud_unit) {
                    $json.Add('start_options', @{})
                    if ($cloud_unit) {
                        $json.start_options.Add('cloud_unit', $cloud_unit)
                    }
                    if ($mtrees) {
                        $json.start_options.Add('mtrees', ($mtrees -join ";"))
                    }
                }
            }
        }        
        $json = $json | ConvertTo-Json   
        Write-Verbose ($json | out-string)   
        $parameters = @{
            uri           = $uri          
            apiver        = $apiver
            Method        = $METHOD
            body          = $json
            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  | Select-Object   -ExcludeProperty link, links # , ddboost_options # -ExpandProperty ddboost_options
            }         
        } 
    }
}


<#
 {
  "description": "Data Movement modify operations",
  "required": [
    "operation"
  ],
  "type": "object",
  "properties": {
    "operation": {
      "description": "Data Movement modify operations",
      "enum": [
        "start",
        "stop",
        "suspend",
        "resume",
        "recall_start",
        "throttle_set",
        "throttle_reset",
        "schedule_set",
        "schedule_remove"
      ],
      "type": "string"
    },
    "start_options": {
      "description": "Data Movement start Options.",
      "type": "object",
      "properties": {
        "mtrees": {
          "description": "Mtree names seperated by semicolon(;)",
          "type": "string"
        },
        "cloud_unit": {
          "description": "Cloud unit name to start data-movement on.",
          "type": "string"
        }
      }
    },
    "stop_options": {
      "description": "Data Movement stop Options.",
      "type": "object",
      "properties": {
        "path": {
          "description": "Stop recall of the given file path.",
          "type": "string"
        },
        "to_tier": {
          "description": "Data Movement stop tier options",
          "enum": [
            "active",
            "cloud",
            "all"
          ],
          "type": "string"
        }
      }
    },
    "recall_path": {
      "type": "string"
    },
    "throttle": {
      "description": "Data Movement throttle value to set (supported values: 100,75,50,25)",
      "format": "int32",
      "minimum": 0,
      "type": "integer"
    },
    "schedule": {
      "description": "Data Movement schedule.",
      "type": "object",
      "properties": {
        "days": {
          "type": "string"
        },
        "time_hour": {
          "type": "string"
        },
        "time_min": {
          "type": "string"
        },
        "repeat_every_n_weeks": {
          "format": "int32",
          "minimum": 0,
          "type": "integer"
        }
      }
    }
  }
}
 #>