Modules/protocols.psm1

<# GET
/rest/v1.0/dd-systems/{SYSTEM-ID}/protocols/ddboost
Get the DDBoost configuration
#>


function Get-DDProtocols {
   [CmdletBinding()]
   param ( 
      [CmdletBinding()]
      [Parameter(Mandatory = $true, ParameterSetName = 'nfs')]
      [switch]$nfs,
      [Parameter(Mandatory = $true, ParameterSetName = 'ddboost')]
      [switch]$ddboost,  
      [Parameter(Mandatory = $true, ParameterSetName = 'cifs')]
      [switch]$cifs,                    
      [Parameter(Mandatory = $false)]
      [string]
      $SYSTEM_ID = $Global:DD_UUID,
      $body = @{}
   )
   begin {
      $Response = @()
      $METHOD = "GET"
   }
   process {
      switch ($PsCmdlet.ParameterSetName) {
         'cifs' {
            $apiver = "rest/v1.0"
            $uri = "dd-systems/$($SYSTEM_ID)/protocols/cifs"
         }
         'ddboost' {
            $apiver = "rest/v1.0"
            $uri = "dd-systems/$($SYSTEM_ID)/protocols/ddboost"
         }   
         'nfs' {
            $apiver = "api/v2"
            $uri = "dd-systems/$($SYSTEM_ID)/protocols/nfs"        
         }       
      }
      $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) {
         'byID' {
            write-output $response 
         }
         default {
            write-output $response | select-object -ExcludeProperty link, links
         } 
      }   
   }
}




function Get-DDCifsShares {
   [CmdletBinding()]
   param ( 
      [CmdletBinding()]                 
      [Parameter(Mandatory = $false)]
      [string]
      $SYSTEM_ID = $Global:DD_UUID,
      $body = @{}
   )
   begin {
      $Response = @()
      $METHOD = "GET"
   }
   process {
      switch ($PsCmdlet.ParameterSetName) {
         default {
            $apiver = "rest/v1.0"
            $uri = "dd-systems/$($SYSTEM_ID)/protocols/cifs/shares"
         }    
      }
      $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 {
            write-output $response
         } 
      }   
   }
}


#/rest/v1.0/dd-systems/{SYSTEM-ID}/protocols/ddboost/storage-units
function Get-DDBoostStorageUnits {
   [CmdletBinding()]
   param ( 
      [CmdletBinding()]
      [Parameter(Mandatory = $true, ParameterSetName = 'byID')]
      [string]$id,                 
      [Parameter(Mandatory = $false, ParameterSetName = 'byID')]
      [Parameter(Mandatory = $false, ParameterSetName = 'default')]

      [string]
      $SYSTEM_ID = $Global:DD_UUID,
      $body = @{}
   )
   begin {
      $Response = @()
      $METHOD = "GET"
   }
   process {
      switch ($PsCmdlet.ParameterSetName) {
         'default' {
            $apiver = "rest/v1.0"
            $uri = "dd-systems/$($SYSTEM_ID)/protocols/ddboost/storage-units"
         }
         'byID' {
            $apiver = "api/v3"
            $uri = "dd-systems/$($SYSTEM_ID)/protocols/ddboost/storage-units/$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) {
         'byID' {
            $response[-1]  | Select-Object -Property * -ExcludeProperty link
         }   
         'default' {
            $Response.storage_units | Select-Object -ExcludeProperty link
         } 
      }   
   }
}


function Get-DDNfsExports {
   [CmdletBinding()]
   param ( 
      [CmdletBinding()]
      [Parameter(Mandatory = $true, ParameterSetName = 'byID')]
      [string]$id,
      [Parameter(Mandatory = $false, ParameterSetName = 'byID')]
      [switch]$clients,                 
      [Parameter(Mandatory = $false, ParameterSetName = 'byID')]
      [Parameter(Mandatory = $false, ParameterSetName = 'default')]

      [string]
      $SYSTEM_ID = $Global:DD_UUID,
      $body = @{}
   )
   begin {
      $Response = @()
      $METHOD = "GET"
   }
   process {
      switch ($PsCmdlet.ParameterSetName) {
         default {
            $apiver = "rest/v2.0"
            $uri = "dd-systems/$($SYSTEM_ID)/protocols/nfs/exports"
         }
         'byID' {
            $apiver = "rest/v2.0"
            $uri = "dd-systems/$($SYSTEM_ID)/protocols/nfs/exports/$ID"
            if ($clients.IsPresent) {
               $uri = Join-Path $uri "clients"
            }
         }               
      }
      $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.exports | Select-Object -ExcludeProperty links
         }
         'byID' {
            if ($clients) { 
               $response  | Select-Object -Property * -ExcludeProperty links, link, clients -ExpandProperty clients -ErrorAction SilentlyContinue
            }
            else {
               $response | Select-Object -Property * -ExcludeProperty links
            }         
         }           
      } 
      
   }
}


#PUT /api/v2/dd-systems/{SYSTEM-ID}/protocols/nfs


function Set-DDnfsservice {
   [CmdletBinding()]
   param ( 
      [CmdletBinding()]
      [Parameter(Mandatory = $false, ParameterSetName = 'protocol')]
      [switch]$nfsv3,
      [Parameter(Mandatory = $false, ParameterSetName = 'protocol')]
      [switch]$nfsv4,
      $SYSTEM_ID = $Global:DD_UUID,
      $body = @{}
   )
   begin {
      $Response = @()
      $METHOD = "PUT"
   }
   process {
      $apiver = "api/v2"
      $uri = "dd-systems/$($SYSTEM_ID)/protocols/nfs"
      $json = @{}
      switch ($PsCmdlet.ParameterSetName) {
         default {
            $json.Add('v3Status', $nfsv3.IsPresent)
            $json.Add('v4Status', $nfsv4.IsPresent)
         }
      }         
      $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
         }         
      } 
   }
}



## PUT /rest/v1.0/dd-systems/{SYSTEM-ID}/protocols/ddboost

<#
.Synopsis
Sets the Boost Protocol
.Example
Enable DDBoost
Set-DDboostservice -enable
 
.Example
Set DDBoost Options
Set-DDboostservice -distributed_segment_processing enabled -virtual_synthetics enabled -global_authentication_mode none -global_encryption_strength none | fl
 
ddboost_status : enabled
ddboost_options : {@{key=distributed_segment_processing; value=enabled}, @{key=virtual_synthetics; value=enabled},
                                   @{key=global_authentication_mode; value=none}, @{key=global_encryption_strength; value=none}}
ddboost_file_replication_options : {@{key=low_bw_optim; value=enabled}, @{key=encryption; value=disabled}, @{key=authentication_mode;
                                   value=anonymous}, @{key=ip_version; value=ipv4}}
 
 
 
.Example
Set the ddboost_file_replication_options
Set-DDboostservice -low_bw_optim enabled -encryption disabled -ip_version ipv4 -authentication_mode anonymous | fl
 
ddboost_status : enabled
ddboost_options : {@{key=distributed_segment_processing; value=enabled}, @{key=virtual_synthetics; value=enabled},
                                   @{key=global_authentication_mode; value=none}, @{key=global_encryption_strength; value=none}}
ddboost_file_replication_options : {@{key=low_bw_optim; value=enabled}, @{key=encryption; value=disabled}, @{key=authentication_mode;
                                   value=anonymous}, @{key=ip_version; value=ipv4}}
 
 
                                   .Example
 
#>



function Set-DDboostservice {
   [CmdletBinding()]
   param ( 
      [CmdletBinding()]
      [Parameter(Mandatory = $true, ParameterSetName = 'enable')]
      [switch]$enable,
      [Parameter(Mandatory = $true, ParameterSetName = 'disable')]
      [switch]$disable,
      [Parameter(Mandatory = $true, ParameterSetName = 'reset_options')]
      [switch]$reset_options,
      [Parameter(Mandatory = $true, ParameterSetName = 'reset_file_replication_options')]
      [switch]$reset_file_replication_options,
      [Parameter(Mandatory = $true, ParameterSetName = 'destroy')]
      [switch]$destroy,      
      [Parameter(Mandatory = $false, ParameterSetName = 'set_options')]
      [string][ValidateSet('enabled', 'disabled')]$fc,
      [Parameter(Mandatory = $false, ParameterSetName = 'set_options')]
      [string][ValidateSet('enabled', 'disabled')]$virtual_synthetics,
      [Parameter(Mandatory = $false, ParameterSetName = 'set_options')]
      [string][ValidateSet('enabled', 'disabled')]$distributed_segment_processing,
      [Parameter(Mandatory = $false, ParameterSetName = 'set_options')]
      [string][ValidateSet("none",
         "two_way",
         "two_way_password")]$global_authentication_mode,
      [Parameter(Mandatory = $false, ParameterSetName = 'set_options')]
      [string][ValidateSet("none",
         "medium",
         "high")]$global_encryption_strength, 
      ## ddboost_file_replication_options
      [Parameter(Mandatory = $false, ParameterSetName = 'set_file_replication_options')]
      [string][ValidateSet('enabled', 'disabled')]$low_bw_optim,
      [Parameter(Mandatory = $false, ParameterSetName = 'set_file_replication_options')]
      [string][ValidateSet('enabled', 'disabled')]$encryption,
      [Parameter(Mandatory = $false, ParameterSetName = 'set_file_replication_options')]
      [string][ValidateSet('ipv4', 'ipv6')]$ip_version,
      [Parameter(Mandatory = $false, ParameterSetName = 'set_file_replication_options')]
      [string][ValidateSet("one-way",
         "two-way",
         "anonymous")]$authentication_mode,


      
      $SYSTEM_ID = $Global:DD_UUID,
      $body = @{}
   )
   begin {
      $Response = @()
      $METHOD = "PUT"
   }
   process {
      $apiver = "rest/v1.0"
      $uri = "dd-systems/$($SYSTEM_ID)/protocols/ddboost"
      $json = @{ operation = $PsCmdlet.ParameterSetName }
      switch ($PsCmdlet.ParameterSetName) {
         default {
         }
         'set_options' {
            $json.add('ddboost_options', @())
            if ($fc) {
               $json.ddboost_options += @{
                  'option' = 'fc'
                  'value'  = $fc
               }
            }
            if ($virtual_synthetics) {
               $json.ddboost_options += @{
                  'option' = 'virtual_synthetics'
                  'value'  = $virtual_synthetics
               }
               
            }   
            if ($distributed_segment_processing) {
               $json.ddboost_options += @{
                  'option' = 'distributed_segment_processing'
                  'value'  = $distributed_segment_processing
               }
               
            } 
            if ($global_authentication_mode) {
               $json.ddboost_options += @{
                  'option' = 'global_authentication_mode'
                  'value'  = $global_authentication_mode
               }
               
            }              
            if ($global_encryption_strength) {
               $json.ddboost_options += @{
                  'option' = 'global_encryption_strength'
                  'value'  = $global_encryption_strength
               }
            } 
            
            #encryption
            #global_encryption_strength
            #ip_version
            #authentication_mode
         }

         'set_file_replication_options' {
            $json.add('ddboost_file_replication_options', @())  
            if ($low_bw_optim) {
               $json.ddboost_file_replication_options += @{
                  'option' = 'low_bw_optim'
                  'value'  = $low_bw_optim
               }
            } 
            if ($encryption) {
               $json.ddboost_file_replication_options += @{
                  'option' = 'encryption'
                  'value'  = $encryption
               }          
            }
            if ($ip_version) {
               $json.ddboost_file_replication_options += @{
                  'option' = 'ip_version'
                  'value'  = $ip_version
               }          
            } 
            if ($authentication_mode) {
               $json.ddboost_file_replication_options += @{
                  'option' = 'authentication_mode'
                  'value'  = $authentication_mode
               }          
            }     
         } 
      }        
      $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
         }         
      } 
   }
}


# Get /rest/v1.0/dd-systems/{SYSTEM-ID}/protocols/ddboost/clients


function Get-DDBoostClients {
   [CmdletBinding()]
   param ( 
      [CmdletBinding()]
      [Parameter(Mandatory = $false, ParameterSetName = 'default')]
      [string]
      $SYSTEM_ID = $Global:DD_UUID,
      $body = @{}
   )
   begin {
      $Response = @()
      $METHOD = "GET"
   }
   process {
      switch ($PsCmdlet.ParameterSetName) {
         default {
            $apiver = "rest/v1.0"
            $uri = "dd-systems/$($SYSTEM_ID)/protocols/ddboost/clients"
         }               
      }
      $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.clients | Select-Object -ExcludeProperty link
         } 
      }   
   }
}

# POST /rest/v1.0/dd-systems/{SYSTEM-ID}/protocols/ddboost/clients


function New-DDBoostClient {
   [CmdletBinding()]
   param ( 
      [CmdletBinding()]
      [Parameter(Mandatory = $true, ParameterSetName = 'client' )]         
      [string][alias('name')]$client_name,
      [Parameter(Mandatory = $false, ParameterSetName = 'client' )]         
      [string][ValidateSet("medium",
         "high")]$encryption_strength,
      [Parameter(Mandatory = $false, ParameterSetName = 'client' )]         
      [string][ValidateSet("anonymous",
         "one_way",
         "two_way",
         "two_way_password",
         "kerberos")]$authentication_mode,      
      [string]
      $SYSTEM_ID = $Global:DD_UUID,
      $body = @{}
   )
   begin {
      $Response = @()
      $METHOD = "POST"
      $apiver = "rest/v1.0"
   }
   process {
      $uri = "dd-systems/$($SYSTEM_ID)/protocols/ddboost/clients"
      $body.Add('name', $client_name)
      $body.Add('client_options', @())
      if ($authentication_mode) {
         $body.client_options += @{option = "authentication_mode"
            value                         = $authentication_mode
         } 
      }
      if ($encryption_strength) {
         $body.client_options += @{option = "encryption_strength"
            value                         = $encryption_strength
         } 
      }     
      $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/v1.0/dd-systems/{SYSTEM-ID}/protocols/ddboost/clients/{ID}
function Set-DDBoostClient {
   [CmdletBinding()]
   param ( 
      [CmdletBinding()]
      [Parameter(Mandatory = $true, ParameterSetName = 'client' )]         
      [string][alias('client_id')]$id,
      [Parameter(Mandatory = $false, ParameterSetName = 'client' )]         
      [string][ValidateSet("medium",
         "high")]$encryption_strength,
      [Parameter(Mandatory = $false, ParameterSetName = 'client' )]         
      [string][ValidateSet("anonymous",
         "one_way",
         "two_way",
         "two_way_password",
         "kerberos")]$authentication_mode,      
      [string]
      $SYSTEM_ID = $Global:DD_UUID,
      $body = @{}
   )
   begin {
      $Response = @()
      $METHOD = "PUT"
      $apiver = "rest/v1.0"
   }
   process {
      $uri = "dd-systems/$($SYSTEM_ID)/protocols/ddboost/clients/$ID"
      $body.Add('operation', "set_options")
      $body.Add('client_options', @())
      if ($authentication_mode) {
         $body.client_options += @{option = "authentication_mode"
            value                         = $authentication_mode
         } 
      }
      if ($encryption_strength) {
         $body.client_options += @{option = "encryption_strength"
            value                         = $encryption_strength
         } 
      }     
      $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}/protocols/ddboost/clients/{ID}

function Remove-DDBoostClient {
   [CmdletBinding()]
   param ( 
      [CmdletBinding()]
      [Parameter(Mandatory = $true, ParameterSetName = 'byID')]
      [string][alias('client_id')]$id,   
      [string]
      $SYSTEM_ID = $Global:DD_UUID,
      $body = @{}
   )
   begin {
      $Response = @()
      $METHOD = "DELETE"
      $apiver = "rest/v1.0"
   }
   process {
      switch ($PsCmdlet.ParameterSetName) {
         default {
            $uri = "dd-systems/$($SYSTEM_ID)/protocols/ddboost/clients/$ID"
         }            
      }                                                          
      $body = $body | ConvertTo-Json
      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 links, link, paging_info      
         } 
      }  
   }
}

# GET /rest/v1.0/dd-systems/{SYSTEM-ID}/protocols/ddboost/users

function Get-DDBoostUsers {
   [CmdletBinding()]
   param ( 
      [CmdletBinding()]
      [Parameter(Mandatory = $false, ParameterSetName = 'default')]
      [string]
      $SYSTEM_ID = $Global:DD_UUID,
      $body = @{}
   )
   begin {
      $Response = @()
      $METHOD = "GET"
   }
   process {
      switch ($PsCmdlet.ParameterSetName) {
         default {
            $apiver = "rest/v1.0"
            $uri = "dd-systems/$($SYSTEM_ID)/protocols/ddboost/users"
         }               
      }
      $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.user | Select-Object -ExcludeProperty link, links
         } 
      }   
   }
}

# PUT /rest/v1.0/dd-systems/{SYSTEM-ID}/protocols/ddboost/users
<#
{
  "description": "DDBoost user modify parameters",
  "required": [
    "operation",
    "user"
  ],
  "type": "object",
  "properties": {
    "operation": {
      "description": "Assign or unassign a user as a DDBoost user",
      "enum": [
        "assign",
        "unassign"
      ],
      "type": "string"
    },
    "user": {
      "description": "Data Access user name",
      "type": "string"
    }
  }
}#>

<#
.Synopsis
Assign or unassign a user as a DDBoost user
.Parameter user
"Data Access user name"
.Parameter assign
Assign a user as a DDBoost user
.Parameter unassign
Unassign a user as a DDBoost user
#>

function Set-DDBoostUser {
   [CmdletBinding()]
   param ( 
      [CmdletBinding()]
      [Parameter(Mandatory = $true, ParameterSetName = 'unassign' )]         
      [switch]$unassign,
      [Parameter(Mandatory = $true, ParameterSetName = 'assign' )]         
      [switch]$assign,
      [Parameter(Mandatory = $true, ParameterSetName = 'assign' )]         
      [Parameter(Mandatory = $true, ParameterSetName = 'unassign')]
      [string][alias('user_name')]$user,       
      [string]$SYSTEM_ID = $Global:DD_UUID,
      $body = @{}
   )
   begin {
      $Response = @()
      $METHOD = "PUT"
      $apiver = "rest/v1.0"
   }

   process {
      $body = @{}
      $uri = "dd-systems/$($SYSTEM_ID)/protocols/ddboost/users"
      switch ($PsCmdlet.ParameterSetName) {
         default {
            $body.Add('operation', $PsCmdlet.ParameterSetName)
            $body.add('user', $user)
         }
      }
      $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
         }      
      } 
       
   }
}



# POST /rest/v2.0/dd-systems/{SYSTEM-ID}/protocols/nfs/exports
function New-DDNfsExport {
   [CmdletBinding()]
   param ( 
      [CmdletBinding()]
      [Parameter(Mandatory = $false, ParameterSetName = 'export' )]
      [Parameter(Mandatory = $false, ParameterSetName = 'export_with_clients' )]
      [Parameter(Mandatory = $false, ParameterSetName = 'export_with_client_defaults' )]         
      [string][alias('name')]$export_name,
      [Parameter(Mandatory = $true, ParameterSetName = 'export_with_client_defaults' )]    
      [Parameter(Mandatory = $true, ParameterSetName = 'export' )]
      [Parameter(Mandatory = $true, ParameterSetName = 'export_with_clients' )]
      [string][alias('path')]$export_path,
      [Parameter(Mandatory = $true, ParameterSetName = 'export_with_client_defaults' )]         
      [Parameter(Mandatory = $true, ParameterSetName = 'export_with_clients' )]
      [string[]][alias('clients')]$client_names, 
      [Parameter(Mandatory = $false, ParameterSetName = 'export_with_clients' )]
      [string[]][ValidateSet(
         'rw',
         'ro',
         'root_squash',
         'no_root_squash',
         'no_all_squash',
         'all_squash',
         'default_root_squash',
         'force_mimimum_root_squash',      
         'secure',
         'insecure',
         'version=3',
         'version=4',
         'version=3:4'
      )]      
      [alias('options')]$client_options,
      [Parameter(Mandatory = $false, ParameterSetName = 'export_with_clients' )]
      [ValidateSet(
         'sys',
         'krb5',
         'krb5i',
         'krb5p'
      )]      
      [alias('sec')][string[]]$security,      
      [Parameter(Mandatory = $true, ParameterSetName = 'export_with_client_defaults' )]      
      [alias('default_options')][switch]$default_client_options,      
      [Parameter(Mandatory = $false, ParameterSetName = 'export_with_clients' )]
      [int][ValidateRange(0, 65635)]$anongid,              
      [string]
      $SYSTEM_ID = $Global:DD_UUID,
      $body = @{}
   )
   begin {
      $Response = @()
      $METHOD = "POST"
      $apiver = "rest/v2.0"
   }
   process {
      $uri = "dd-systems/$($SYSTEM_ID)/protocols/nfs/exports"
      $body.Add('export_path', $export_path)
      if ($export_name) {
         $body.Add('export_name', $export_name)
      }
      switch ($PsCmdlet.ParameterSetName) {
         'export_with_clients' { 
            Write-Verbose "adding clients"
            $body.Add('clients', @{'client_name' = $client_names })
            If ($default_client_options) {
               $client_options = 
               'sec=sys',
               'rw',
               'ro',
               'root_squash',
               'no_all_squash',
               'default_root_squash',
               'force_mimimum_root_squash',      
               'secure',
               'version=3'
            }
            if (!$client_options) {
               $client_options_add = @()
            }
            else {
               $client_options_add = $client_options
            }   
            if ($anongid) {
               $client_options_add += "anongid=$anongid"
               Write-Verbose ($client_options_add | Out-String)

            }
            if ($security) {
               $client_options_add += "sec=" + ($security -join ':')
            }

            $body.clients.add('client_options', ($client_options_add -join ","))
         }
      }
      $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}/protocols/nfs/exports/{ID}
<#
version Select the appropriate version or versions of NFS, which can be 3, 4, 3:4, or all.
ro Enable read-only permission.
rw Enable read and write permissions (default value).
root_squash Map requests from uid or gid 0 to the anonymous uid/gid.
no_root_squash Turn off root squashing.
NOTE: no_root_squash is the default value.
all_squash Map all user requests to the anonymous uid/gid.
no_all_squash Turn off the mapping of all user requests to the anonymous uid/gid (default value).
default_root_squ
ash
force_minimum_r
oot_squash
secure Require that requests originate on an Internet port that is less than IPPORT_RESERVED (1024) (default
value).
insecure Turn off the secure option.
anongid=id Set an explicit user ID for the anonymous account. The ID is an integer bounded from 0 to 65635.
sec Set sec equal to one or more of the following options to activate different types of authentication
security options. The default for sec is sys.
sys: Allow unauthenticated connections. Select to not use authentication. This is the default.
krb5: Allow Kerberos-5 NFS authenticated connections.
krb5i: (krb5 integrity) Allow connections that checksum NFS arguments and results.
krb5p: (krb5 privacy) Allow connections that encrypt NFS arguments and results.
 
{
  "description": "NFS export creation parameters",
  "required": [
    "export_path"
  ],
  "type": "object",
  "properties": {
    "export_name": {
      "description": "Export name",
      "type": "string"
    },
    "export_path": {
      "description": "Full path",
      "type": "string"
    },
    "tenant_unit": {
      "description": "Tenant unit",
      "type": "string"
    },
    "clients": {
      "description": "NFS export client information",
      "required": [
        "client_name"
      ],
      "type": "object",
      "properties": {
        "client_name": {
          "description": "Client name[s]",
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string"
          }
        },
        "client_options": {
          "description": "comma separated list of NFS options such as \"rw,no_root_squash,no_all_squash,secure\"",
          "type": "string"
        }
      }
    },
    "referrals": {
      "description": "NFS export referral information",
      "required": [
        "referral_name"
      ],
      "type": "object",
      "properties": {
        "referral_name": {
          "type": "string"
        },
        "remote_servers": {
          "description": "List of remote servers\"",
          "type": "array",
          "minItems": 0,
          "items": {
            "type": "string"
          }
        },
        "remote_path": {
          "type": "string"
        }
      }
    }
  }
}#>