Skip to main content

Close all active Frame sessions

· 4 min read
David Horvath

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

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:

  1. Get the pool IDs of all the Frame production pools for the account
  2. Get a list of active sessions
  3. 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.

Choose Update after clicking on the kabob on the far right

Choose "Update" after clicking on the kabob on the far right

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:

  1. The Get-FrameAPICall function implements an HTTPS “GET” request and is used to gather information about the pools and sessions
  2. 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.

Session close dialog

Session 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.

Author

David Horvath

More content created by

David Horvath
David Horvath is a senior solutions architect with Frame. He has been a part of the Frame team for almost five years and prior to that spent 20 years consulting on various information technology projects with the U.S. intelligence community.

© 2024 Dizzion, Inc. All rights reserved. Frame, the Frame logo and all Dizzio product, feature and service names mentioned herein are registered trademarks of Dizzion, Inc. in the United States and other countries. All other brand names mentioned herein are for identification purposes only and may be the trademarks of their respective holder(s). This post may contain links to external websites that are not part of Dizzion. Dizzion does not control these sites and disclaims all responsibility for the content or accuracy of any external site. Our decision to link to an external site should not be considered an endorsement of any content on such a site. Certain information contained in this post may relate to or be based on studies, publications, surveys and other data obtained from third-party sources and our own internal estimates and research. While we believe these third-party studies, publications, surveys and other data are reliable as of the date of this post, they have not independently verified, and we make no representation as to the adequacy, fairness, accuracy, or completeness of any information obtained from third-party sources.