By 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.
The concept of operations is pretty simple:
For this script to operate, you will need the following values:
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
The information between “account” and “basic-info” (in this example, 1f86e290-8cd2-4950-9c5a-9d3f7ed332e7) is the Account ID.
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:
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
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.
David Horvath is a senior solutions architect with Nutanix 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.
© 2022 Nutanix, Inc. All rights reserved. Nutanix, the Nutanix logo and all Nutanix product, feature and service names mentioned herein are registered trademarks or trademarks of Nutanix, Inc. in the United States and other countries. 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 Nutanix.com. Nutanix 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 been independently verified, and we make no representation as to the adequacy, fairness, accuracy, or completeness of any information obtained from third-party sources.
This post may contain express and implied forward-looking statements, which are not historical facts and are instead based on our current expectations, estimates and beliefs. The accuracy of such statements involves risks and uncertainties and depends upon future events, including those that may be beyond our control, and actual results may differ materially and adversely from those anticipated or implied by such statements. Any forward-looking statements included herein speak only as of the date hereof and, except as required by law, we assume no obligation to update or otherwise revise any of such forward-looking statements to reflect subsequent events or circumstances.