chrischrischris
Enthusiast
Enthusiast

vRA 8.9: How to change a deployment lease using PowerShell?

Hi all,

vRA 8.9: How to change a deployment lease using PowerShell?

 

Thanks!

-Chris

Tags (2)
0 Kudos
1 Reply
emacintosh
Hot Shot
Hot Shot

It may be helpful to provide more details on where/how you plan to run the script and what exactly you need help with.  Do you know powershell and just need the API details?  Or are you unfamiliar with powershell but know you need a powershell script?

That said, here is the function we use.  It should return a job that you can then check to see the status.  

This is just to provide you an idea of how the API works...not a plug-in-play solution.  We wrap this up in another script that sets the lease and then checks the job endpoint until it successful or fails.

Note that the expirationDate is in the format of "'YYYY-MM-DDTHH:MM:SSZ'"

function set-vraDeploymentLease {
    param (
        [Parameter(Mandatory)]
        [string] $base,

        [Parameter(Mandatory)]
        [string] $token,

        [Parameter(Mandatory)]
        [string] $deploymentId,

        [string] $expirationDate
    )

    $uri = "$base/deployment/api/deployments/$deploymentId/requests"

    $headers = @{
        "Authorization" = "Bearer $token"
        "Content-Type" = "application/json"
    }

    # if no expirationDate is passed, an existing expiration will be removed
    if($expirationDate) {
        $inputs = @{
            "Lease Expiration Date" = $expirationDate
        }
         $body = @{
        "actionId" = "Deployment.ChangeLease"
        "inputs" = $inputs
        } | convertto-json
    }
    else {
        $body = @{
        "actionId" = "Deployment.ChangeLease"
        "Lease Expiration Date" = ""
        } | convertto-json
    }
        
    try {
        $response = invoke-restmethod -method Post -uri $uri -headers $headers -body $body
        write-output $response
    }
    catch {
        throw $_
    }
}

 

0 Kudos