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 = 'default')]
      
       [string]
       $SYSTEM_ID = $Global:DD_UUID,
       $body = @{size= 9999}
    )
    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
 
.example
Get-AVAclients -recursive -body @{fields = "id,name,domainFqdn"}
 
 
id name domainFqdn
-- ---- ----------
6b93fcb902b2365dd52f774b13d782d8c02e5025 avemaster.home.labbuildr.com /MC_SYSTEM
35bc9c1307b085d502d61e39a16521d27e0a2052 ave_vproxy1.home.labbuildr.com /clients
090ba46da2e10d10911110f11b21b432b6ebb762 mba.home.labbuildr.com /clients
b110c4ac0f1641b537879aca7e507a2493eebaf0 openhab2.home.labbuildr.com /clients
dad27693519375d4184179c21dead76f3cddf967 ubnt2in1 /clients
bcd8cff5b95b0fcfa09295b610cab949f30a6c7b pfSense /vcsa1.home.labbuildr.com/VirtualMachines
28a5140dd48b7ddef6e66b2d0242f29bde154463 sqlsinglenode /vcsa1.home.labbuildr.com/VirtualMachines
#>

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
         }      
      } 
       
   }
}
<#
{
  "description": "Mtree creation parameters",
  "required": [
    "name"
  ],
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    },
    "tenant_unit": {
      "type": "string"
    },
    "quota_config": {
      "description": "Quota configuration",
      "type": "object",
      "properties": {
        "hard_limit": {
          "description": "Hard_limit should be greater than or equal to 1 MiB = 1,048,576. For modification, if hard_limit is 0, it means resetting hard_limit.",
          "format": "int64",
          "minimum": 0,
          "type": "integer"
        },
        "soft_limit": {
          "description": "Soft_limit should be greater than or equal to 1 MiB = 1,048,576. For modification, if hard_limit is 0, it means resetting soft_limit.",
          "format": "int64",
          "minimum": 0,
          "type": "integer"
        }
      }
    }
  }
}
#>