Modules/licenses.psm1

# DELETE /rest/v1.0/dd-systems/{SYSTEM-ID}/licenses
function Remove-DDlicenses {
    [CmdletBinding()]
    param ( 
        [CmdletBinding()]
        [switch]$restore_to_eval,
        [string]
        $SYSTEM_ID = $Global:DD_UUID,
        $body = @{}
    )
    begin {
        $Response = @()
        $METHOD = "DELETE"
        $apiver = "rest/v2.0"
    }
    process {
        switch ($PsCmdlet.ParameterSetName) {
            default {
                $uri = "dd-systems/$($SYSTEM_ID)/licenses"
                $body.add('restore_to_eval', $restore_to_eval.IsPresent)
            }            
        }                                                          
        $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/v2.0/dd-systems/{SYSTEM-ID}/licenses


function Get-DDlicenses {
    [CmdletBinding()]
    param ( 
        [CmdletBinding()]
        [switch]$restore_to_eval,
        [string]
        $SYSTEM_ID = $Global:DD_UUID,
        $body = @{}
    )
    begin {
        $Response = @()
        $METHOD = "GET"
        $apiver = "rest/v2.0"
    }
    process {
        switch ($PsCmdlet.ParameterSetName) {
            default {
                $uri = "dd-systems/$($SYSTEM_ID)/licenses"
            }            
        }                                                          
        $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  -ExpandProperty license    
            } 
        }  
    }
}


<#
.SYNOPSIS
Update license information for DataDomain
.DESCRIPTION
   Cmdlet for update a DataDomain license information to elms
   - from a vile in /ddvar
   - from a client side file
.PARAMETER license_content_file
Specifies the a local file conataining the license information. Content get´s
applied to elms
.PARAMETER license_file
Specifies the filename in /ddvar to apply the agains elms
(need to be copied beforehand)
 
 
.EXAMPLE
Set-DDlicenses -license_file internal.lic
 
details code
------- ----
success 0
 
.EXAMPLE
Set-DDlicenses -license_content_file .\PPDD-pwsh\internal.lic
 
details code
------- ----
success 0
 
#>

function Set-DDlicenses {
    [CmdletBinding()]
    param ( 
        [CmdletBinding()]
        [Parameter(Mandatory = $true, ParameterSetName = 'elms_update_with_content' )]
        [System.IO.FileInfo]$license_content_file,       
        [Parameter(Mandatory = $true, ParameterSetName = 'elms_update_with_filename')]
        [string]$license_file,
        [string]$SYSTEM_ID = $Global:DD_UUID,
        $body = @{}
    )
    begin {
        $Response = @()
        $METHOD = "PUT"
        $apiver = "rest/v2.0"
        $uri = "dd-systems/$($SYSTEM_ID)/licenses"

    }
    process {
        switch ($PsCmdlet.ParameterSetName) {
            'elms_update_with_content' {
                $license_content = (Get-Content $license_content_file | Out-String )
                $body.Add('operation', 'elms_update_with_content')
                $body.Add('elms_unserved_license', @{'license_content' = $license_content })    
            }
            'elms_update_with_filename' {
                $body.Add('operation', 'elms_update_with_filename')
                $body.Add('elms_unserved_license', @{'license_file' = $license_file })    
            }           
        }
        $Global:DD_Headers.Add('Accept', 'Application/text')                                                          
        $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.status_group | Select-Object -ExcludeProperty links, link,  paging_info  
            } 
        }  
    }
}