APIs

YouTube

If you prefer to watch a video on this topic check out my YouTube channel.

thumbnail

Use Case

The customer wanted to use Aria Operations (AO) and ServiceNow (SNOW) to automate VM rightsizing, their requirements were below.

  1. AO creates SNOW incident for VM rightsizing
  2. SNOW runs business rules / workflows
  3. SNOW initiates VM rightsize action via AO
  4. AO communicates with vCenter to rightsize VM

Below is a visual representation

Usecase

In Part 2 we are focussing on the APIs for the customer’s use case:

  • SNOW to authenticate to AO (Obtain Bearer Token)
  • SNOW to request VM identifier based on VM friendly name
  • SNOW to send VM rightsize request to AO
  • SNOW to poll rightsize action to verify completion

APIOverview

Pre-requisites

  • AO Server (my lab is running v8.18.1 but earlier releases support these APIs)
  • Postman installed on workstation (optional)

Note: A SNOW instance is not required, this post covers rightsizing APIs

APIs APIs APIs

AO includes a Swagger interface for documentation and API testing . You can access the Swagger UI via your AO URL:

https://Ops-FQDN/suite-api/doc/swagger-ui.html

If you’ve played with APIs you may be familiar with Postman. This blog post will cover how to use the Swagger UI and Postman with AO APIs.

Note: I assume you know Postman and will not cover beginner steps

Auth API

POST API: https://ops-FQDN/suite-api/api/auth/token/acquire

Inputs:

  • Username
  • AuthSource
  • Password

Swagger

The Swagger UI contains inbuilt authorization and will cache the auth token in the browser session. I recommend doing this if testing APIs via Swagger.

  • Click the Authorize button

Authorize

  • Enter the appropriate inputs
  • Click Authorize
  • Click Close

The bearer token is now cached in the browser session.

Inputs

If you wanted to test the API via Swagger.

authapi2

Locate the API in the UI:

  • Click the Try it out button
  • Enter the inputs required in the userPassword section
  • Click the Execute button

authapi

The response body contains the auth token to use for subsequent API calls.

Token

Postman

I recommend importing my Postman Collection. Go to the variables section (tab visible after clicking on Aria Operations Rightsize APIs collection) and enter values for the following:

  • ariaOperations = Your AO FQDN
  • user = Username to Auth to AO
  • pass = Password for your Username
  • authSource = Authentication Source

Click Save when done

PostmanVariables

Locate Get Ops Auth Token on the left hand side under the Authenticate folder. The variables are referenced in the API call.

Postman-Auth

There is a post-response script which saves the bearer token as an environment variable.

SaveToken

Click the Send button

The token is visible in the response body.

Response

We now have our authentication token 👍

Adapter Kinds API

POST API:
https://Ops-FQDN/suite-api/api/adapterKinds/{adapterKindKey}/resourcekinds/{resourceKindKey}/resources

Inputs:

  • adapterKindKey = VMWARE
  • resourceKindKey = virtualmachine
  • resource = Your VM Friendly name

We will feed the VM friendly name into the adapter kinds API call to capture the VM identifier.

Swagger

AdapterKinds

Locate the API in the UI:

  • Click the API to expose the API details
  • Click the Try it out button
  • Enter the inputs required in the Parameters section
  • Click the Execute button

Parameters

The server response contains the unique identifier (scroll to the bottom).

Identifier

In my example b25e562f-0028-4cb9-88c7-0ae34e9fbade is the identifier for VM rightsizedemo.

Postman

Let’s go back to Postman variables and enter the inputs for the adapterKinds API call.

Postmanvars

Locate GetVM on the left hand side under the Adapter Kinds folder. The variables are referenced in the API call including our bearer Token.

AdapterKinds2

There is a post-response script to save the identifier as an environment variable

Script

Click the Send button

The identifier is visible in the response body (scroll to the bottom).

Response2

Awesome, we have our identifier 👌 Let’s prepare the rightsizing API call.

Actions API - Preparation

This API is where the magic happens 😎

At the time of writing AO has 140 actions that can be called via API. To list available actions use this API:

GET API: https://ops-FQDN/suite-api/api/actiondefinitions

ActionDefinitions

I’ve saved you the trouble of running the above API and parsing the results for rightsizing actions 😎

Available actions for VM rightsizing:

  • VMWARE-Set CPU Count and Memory For VM
  • VMWARE-Set CPU Count For VM
  • VMWARE-Set Memory For VM

I will use VMWARE-Set CPU Count and Memory For VM action for the remainder of this blog post.

We need to know the available parameters for this action.

POST API: https://ops-FQDN/suite-api/api/actions/{id}/query

Inputs:

  • contextResourceId = b25e562f-0028-4cb9-88c7-0ae34e9fbade
  • id = VMWARE-Set CPU Count and Memory For VM

Note: The resource id was obtained earlier via the adapterKinds API

Swagger

ActionQuery

Locate the API in the UI:

  • Click the API to expose the API details
  • Click the Try it out button
  • Enter the inputs required in the Parameters section
  • Click the Execute button

ActionParameters

The server response body section will contain the different input parameters (scroll to the bottom).

ActionInputResults

Postman

In the Postman collection I defined the actionId already VMWARE-Set CPU Count and Memory For VM

PostmanVariables

Locate Get Action Parameters on the left hand side under the Actions folder. The inputs required are provided via Postman variables.

GetActionParameters

Click the Send button

The server response body section will contain the different input parameters.

ActionParametersOutput

We are ready to perform the VM rightsizing API call 😬

Actions API - Initiate VM Rightsizing

POST API: https://Ops-FQDN/suite-api/api/actions/{id}

Inputs:

  • contextId = VMWARE-Set CPU Count and Memory For VM
  • contextResourceId = b25e562f-0028-4cb9-88c7-0ae34e9fbade
  • resourceId = b25e562f-0028-4cb9-88c7-0ae34e9fbade
  • actionId = VMWARE-Set CPU Count and Memory For VM
  • value = Enter value(s) to suit requirements for mem, cpu, poweroff & snapshot

The JSON output from the previous actions query API contained a lot of info. Below is the JSON required to feed into the Actions API.

{
  "contextId": "SetCPUCountAndMemoryforVM",
  "contextResourceId": [ "yourvmidentifier" ],
    "parameterGroup": [
      {
        "resourceId": "yourvmidentifier",
        "parameterValue": [
          {
            "name": "memory",
            "value": "yourmemvalue-mb"
          },
          {
            "name": "cpuCount",
            "value": "yourcpuvalue"
          },
          {
            "name": "powerOffAllowed",
            "value": "trueorfalse-yourvalue"
          },
          {
            "name": "snapshotRequired",
            "value": "trueorfalse-yourvalue"
          }
        ]
      }
    ]
}

Swagger

ActionRightsize

Locate the API in the UI:

  • Click the API to expose the API details
  • Click the Try it out button
  • Enter the inputs required in the Parameters section
  • Click the Execute button

ActionsInput

The server response body contains the task ID.

RightsizeResponse

The API below can be used to query our rightsizing task.

POST API: https://Ops-FQDN/suite-api/api/actions/{taskId}/status

status

Inputs:

  • taskId = 0d991b5e-713e-46c6-83b3-06d941104be0

Locate the API in the UI:

  • Click the API to expose the API details
  • Click the Try it out button
  • Enter the inputs required in the Parameters section
  • Click the Execute button

TaskInput

The server response body contains the state of the task and details.

TaskStatus

If we check vCenter the AO service account initiated the VM rightsizing actions:

vCenterEvents

Postman

Locate Perform Action on the left hand side under the Actions folder. The inputs required are provided via Postman variables.

Update the parameter values to meet requirements.

PMAction

There is a post-response script to save the taskId as an environment variable

TaskIdScript

Click the Send button

The server response body contains the task ID.

PMResult

Locate Get Task Status on the left hand side under the Actions folder. The inputs required are provided via Postman variables.

GetTask

Click the Send button

The server response body section will contain state of the task and details.

PMStatus

Conclusion

Still following along? Well done 👏

In Part 1 we covered how to generate a rightsizing incident in SNOW with a custom payload. In this post we covered the APIs SNOW can use to automate VM rightsizing.

The SNOW developer is usually responsible to orchestrate the demonstrated APIs into a SNOW workflow(s).

Hopefully you learned something about AO APIs, they are a key component when automating VM rightsizing actions.