Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Get/Revoke-CVClientLicense functions #14

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Modules/Commvault.CommCell/Commvault.CommCell.psd1
Binary file not shown.
244 changes: 244 additions & 0 deletions Modules/Commvault.CommCell/Commvault.CommCell.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,250 @@ function Get-CVClient {
}


function Get-CVClientLicense {
<#
.SYNOPSIS
Method to get licenses for a client.
.DESCRIPTION
Method to get licenses for a client.
.PARAMETER Name
Get licenses on client specified by Name.
.PARAMETER Id
Get licenses on client specified by Id.
.EXAMPLE
Get-CVClientLicences -Name 'carbonwincs1'
.OUTPUTS
[PsCustomObject] containing details of the license and the plaform type
.NOTES
Author: Craig Tolley
Based on API Documentation at https://documentation.commvault.com/commvault/v11/article?p=47685.htm
#>
[CmdletBinding(DefaultParameterSetName = 'ByName')]
[OutputType([PSCustomObject])]
param(
[Alias('Client')]
[Parameter(Mandatory = $True, ParameterSetName = 'ByName', ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
[ValidateNotNullorEmpty()]
[String] $Name,

[Alias('ClientId')]
[Parameter(Mandatory = $True, ParameterSetName = 'ById', ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
[ValidateNotNullorEmpty()]
[Int32] $Id
)

begin { Write-Debug -Message "$($MyInvocation.MyCommand): begin"

try {
$sessionObj = Get-CVSessionDetail $MyInvocation.MyCommand.Name
$endpointSave = $sessionObj.requestProps.endpoint
}
catch {
throw $_
}
}

process { Write-Debug -Message "$($MyInvocation.MyCommand): process"

try {
$sessionObj.requestProps.endpoint = $endpointSave

if ($PSCmdlet.ParameterSetName -eq 'ByName') {
$clientObj = (Get-CVClient -Name $Name)
if ($null -ne $clientObj) {
$Id = $clientObj.clientId
}
else {
Write-Information -InformationAction Continue -MessageData "INFO: $($MyInvocation.MyCommand): client not found having name [$Name]"
return
}
}

$sessionObj.requestProps.endpoint = $sessionObj.requestProps.endpoint -creplace ('{clientId}', $Id)
$headerObj = Get-CVRESTHeader $sessionObj

$body = ''
$payload = @{ }
$payload.Add('headerObject', $headerObj)
$payload.Add('body', $body)
$validate = 'licensesInfo'

$response = Submit-CVRESTRequest $payload $validate

if ($response.IsValid) {
Write-Output $response.Content.licensesInfo
}

else {
Write-Information -InformationAction Continue -MessageData "INFO: $($MyInvocation.MyCommand): license information not found for client Id [$Id]"
}

}
catch {
throw $_
}
}

end { Write-Debug -Message "$($MyInvocation.MyCommand): end"
}
}


function Revoke-CVClientLicense {
<#
.SYNOPSIS
Method to release licenses from a client.
.DESCRIPTION
Method to release licenses from a client.
.PARAMETER Name
Release licenses on client specified by Name.
.PARAMETER Id
Release licenses on client specified by Id.
.PARAMETER LicensesToRelease
Collection of licenses to release. Details of licenses and format can be found from running Get-CVClientLicense
.PARAMETER Force
Switch to Force override of default 'WhatIf' confirmation behavior.
.EXAMPLE
$licenses = Get-CVClientLicences -Name 'carbonwincs1'
Revoke-CvClientLicenses -Name 'carbonwincs1' -LicensesToRelease $licenses
.PARAMETER Force
Switch to Force override of default 'WhatIf' confirmation behavior.
.OUTPUTS
Outputs errorMessage and errorCode. Error code 0 is success.
.NOTES
Author: Craig Tolley
Based on API Documentation at https://documentation.commvault.com/commvault/v11/article?p=92013.htm
#>
[CmdletBinding(DefaultParameterSetName = 'ByName', SupportsShouldProcess = $True, ConfirmImpact = 'High')]
Param (
[Alias('Client')]
[Parameter(Mandatory = $True, ParameterSetName = 'ByName', ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
[ValidateNotNullorEmpty()]
[String] $Name,

[Alias('ClientId')]
[Parameter(Mandatory = $True, ParameterSetName = 'ById', ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
[ValidateNotNullorEmpty()]
[Int32] $Id,

[Parameter(Mandatory = $True, ParameterSetName = 'ByName')]
[Parameter(Mandatory = $True, ParameterSetName = 'ById')]
[System.Object] $LicensesToRelease,

[switch]$Force
)

begin { Write-Debug -Message "$($MyInvocation.MyCommand): begin"

try {
$sessionObj = Get-CVSessionDetail $MyInvocation.MyCommand.Name
$endpointSave = $sessionObj.requestProps.endpoint
}
catch {
throw $_
}
}

process { Write-Debug -Message "$($MyInvocation.MyCommand): process"

try {
$sessionObj.requestProps.endpoint = $endpointSave

if ($PSCmdlet.ParameterSetName -eq 'ById' ) {
$sessionObj.requestProps.endpoint = $sessionObj.requestProps.endpoint -creplace ('{clientId}', $Id)
}
else {
$clientObj = Get-CVClient -Name $Name
if ($null -eq $clientObj) {
Write-Information -InformationAction Continue -MessageData "INFO: $($MyInvocation.MyCommand): client not found having name [$Name]"
return
}
$Id = $clientObj.clientId
}

<#
{
"isClientLevelOperation": true,
"licensesInfo": [{
"platformType": 1,
"license": {
"appType": 33,
"licenseName": "Server File System - Windows File System"
}
}],
"clientEntity": {
"clientId": "client001"
}
}
#>

$body = @{}

$client = @{}
$client.Add('clientId', $Id)
$body.Add('clientEntity', $client)

$licensesinfos = @()
ForEach ($l in $LicensesToRelease) {
$licenseinfo = @{}
$licenseinfo.Add("platformType",$LicensesToRelease.platformType)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The payload here is incorrect platformType is populated with array of integers for multiple licenses . Instead of $LicensesToRelease replace it with the $l.platformType.


$license = @{}
$license.Add("appType",$l.license.appType)
$license.Add("licenseName",$l.license.licenseName)
$licenseinfo.Add("license",$license)

$licensesinfos += $licenseinfo
}

$body.Add("licensesInfo",$licensesinfos)
$body = ($body | ConvertTo-Json -Depth 10)

$headerObj = Get-CVRESTHeader $sessionObj
$payload = @{ }
$payload.Add('headerObject', $headerObj)
$payload.Add('body', $body)
$validate = 'errorCode'
$body
if ($PSCmdlet.ParameterSetName -eq 'ById' ) {
if ($Force -or $PSCmdlet.ShouldProcess($Id)) {
$response = Submit-CVRESTRequest $payload $validate
}
else {
$response = Submit-CVRESTRequest $payload $validate -DryRun
}
}
else {
if ($Force -or $PSCmdlet.ShouldProcess($clientObj.clientName)) {
$response = Submit-CVRESTRequest $payload $validate
}
else {
$response = Submit-CVRESTRequest $payload $validate -DryRun
}
}

if ($response.IsValid) {
Write-Output $response.Content
}
else {
if ($PSCmdlet.ParameterSetName -eq 'ById' ) {
Write-Information -InformationAction Continue -MessageData "INFO: $($MyInvocation.MyCommand): release client license request failed for client id[$Id]"
}
else {
Write-Information -InformationAction Continue -MessageData "INFO: $($MyInvocation.MyCommand): release client license request failed for client name [$($clientObj.clientName)]"
}
}
}
catch {
throw $_
}
}

end { Write-Debug -Message "$($MyInvocation.MyCommand): end"
}
}


function Get-CVClientGroup {
<#
.SYNOPSIS
Expand Down
Binary file modified Modules/Commvault.RESTSession/Commvault.RESTSession.psd1
Binary file not shown.
19 changes: 19 additions & 0 deletions Modules/Commvault.RESTSession/Commvault.RESTSession.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,25 @@ function GetAPIDetail ([String] $Request) {

}

'Get-CVClientLicense' = @{


Description = 'Get client licenses from CommServe'
Endpoint = 'Client/{clientId}/License'
Method = 'Get'
Body = ''

}

'Revoke-CVClientLicense' = @{

Description = 'Release a license from a client'
Endpoint = 'Client/License/Release'
Method = 'Post'
Body = ''

}

'Add-CVClientGroup' = @{

Description = 'Add new client group on CommServe'
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ Sample Package Function Table
-----------------------------
- Function: Get-CVClient in Module: Commvault.CommCell
- Function: Get-CVClientGroup in Module: Commvault.CommCell
- Function: Get-CVClientLicense in Module: Commvault.CommCell
- Function: Get-CVVersionInfo in Module: Commvault.CommCell
- Function: Get-CVAlert in Module: Commvault.CommCell
- Function: Get-CVSubclient in Module: Commvault.CommCell
- Function: Revoke-CVClientLicense in Module: Commvault.CommCell
- Function: Set-CVClient in Module: Commvault.CommCell
- Function: Set-CVClientGroup in Module: Commvault.CommCell
- Function: Backup-CVClientFileSystem in Module: Commvault.FileSystem
Expand Down