Resources

Arrow Image

Blog & News

Arrow Image

Close all active Frame sessions

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

News & Blog

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:

  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.

About the Author

David Horvath

Senior Solutions Architect

William Wong is the VP of Service Delivery for Dizzion, responsible for service delivery (professional and managed services), solutions architecture, and support. He works actively with customers to transform their business and operations leveraging DaaS in a hybrid and multi-cloud world. Before joining Dizzion as part of the Frame spinout from Nutanix, William was Head of Enterprise Solutions at Frame and following Nutanix's acquisition of Frame in 2018, Director of Solutions Architecture (Frame) at Nutanix. Prior to his work in DaaS, William led the development and adoption of innovative Internet software solutions and services, including Internet-based credit card and check processing and eCommerce platforms. William spent over 30 years at Cancer Commons, NetDeposit, Hewlett-Packard, VeriFone, and multiple Internet, payment, and eCommerce startups in executive management, program management, engineering management, and executive advisory positions. William received his B.S., M.S., and Ph.D. in Electrical Engineering from Stanford University.

More about the author

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!