Close all active Frame sessions
The Nutanix® Frame® Desktop-as-a-Service (DaaS) solution that allows administrators to create pools of non-persistent desktops and applications for use by internal and external users. When used on one of the public cloud infrastructures – AWS®, Azure® or GCP® clouds – this service can scale out very quickly and increase an organization's capacity to support a variety of use cases
WRITTEN BY
TABLE OF CONTENT
One use case provides applications for training or tradeshow/conference demonstration purposes on a temporary basis.This use case could become important to close all the active sessions on a Frame account to allow deprovisioning of the cloud resources. This blog will step you through how the Frame admin API can be used to accomplish this objective via a PowerShell script.
Concept of Operations
The concept of operations is pretty simple:
- Get the pool IDs of all the Frame production pools for the account
- Get a list of active sessions
- Close an active sessions if it is in a production pool
Prerequisites
For this script to operate, you will need the following values:
- Client ID and Client Secret: These are the credentials used to call the Frame Admin API. They can be obtained by following the Frame documentation How to Provision API Credentials. The permissions that you grant to the credentials will need to have administrative access to the Frame account that you are working with.
- Account ID: The account ID is the Universally Unique Identifier (UUID) of the Frame account in which you will update the elasticity settings. You can find that value by going to the Frame admin UI and choosing “Update” on the account in which you plan to change the elasticity parameters.
In your browser's location bar you will see something like:
https://frame.nutanix.com/frame/account/1f86e290-8cd2-4950-9c5a-9d3f7ed332e7/basic-info
Some REST basics
With the Frame admin API, we use REST calls to interact with the Frame control plane. Some of the calls are queries or requests for information and they use the HTTPS GET request to gather that information. Some of the REST calls ask Frame to perform something known as “mutations.” These calls use the HTTPS POST or DELETE request since they are intended to change something within the Frame control plane.
In PowerShell, the method type of request is sent as an argument in the HTTPS call:
$response = Invoke-RestMethod -Method Get -Uri $api -Headers $headers
To perform proper error handling, the developed script has two different functions:
- The Get-FrameAPICall function implements an HTTPS “GET” request and is used to gather information about the pools and sessions
- The Delete-FrameAPICall function implements an HTTPS “DELETE” request and is used to close the sessions
The script
After defining those functions, the main part of the script is pretty self explanatory. First, gather all the production pool IDs and put them in a list called $pools.
$req_string = "https://api.console.nutanix.com/v1/accounts/" + $acct_id + "/pools"
$res = Get-FrameAPICall -client_id $clnt_id -client_secret $clnt_secret -api $req_string
$pools=@()
foreach ($j in $res)
{
if ($j.kind -eq "production")
{
$pools += $j.external_id
}
}
Then you get a list of the active sessions.
$req_string = "https://api.console.nutanix.com/v1/accounts/" + $acct_id + "/active_sessions"
$res = Get-FrameAPICall -client_id $clnt_id -client_secret $clnt_secret -api $req_string
Now you loop through all active sessions and if the pool_id value matches an id in $pools, you close the session using Delete-FrameAPICall.
foreach ($i in $res)
{
# Check for each production pool_id
foreach ($j in $pools)
{
if (($i.id -ne $null) -and ($i.pool_id -eq $j))
{
Write-Host "Closing "$i.id
$req_string = "https://api.console.nutanix.com/v1/accounts/" + $acct_id + "/sessions/" + $i.id
$res = Delete-FrameAPICall -client_id $clnt_id -client_secret $clnt_secret -api $req_string
}
}
}
The sessions will close immediately and the user will get an administrative close dialog.
Conclusion
This relatively simple script shows the power of the Frame Admin API to query the Frame control plane for account information and use REST mutations to instruct the platform to perform an action within the Frame account. For a full list of the account endpoints, check out the Frame documentation found here.
Subscribe to our newsletter
Register for our newsletter now to unlock the full potential of Dizzion's Resource Library. Don't miss out on the latest industry insights – sign up today!
Dizzion values your privacy. By completing this form, you agree to the processing of your personal data in the manner indicated in the Dizzion Privacy Policy and consent to receive communications from Dizzion about our products, services, and events.