«

»

Monitor Era Operation Progress – Calm & Era Integration

I’m getting more and more questions about integrations to Nutanix Era from overlying self-service, automation and orchestration services/tools. It’s a perfect match since integrations to Era is one of my responsibilities these days so keep the questions coming:)

There is another blog post which covers Era progress monitoring via ServiceNow available here.

In this blog post i will share a Nutanix Calm script you can use to monitor Era operations. This can be any operation you trigger via the Era API including e.g.:

  • Provisioning
  • Delete
  • Refresh
  • Clone
  • Snapshot
  • Log CatchUp

I have seen solutions just including a process delay after an external task has been started. The delay has been an estimate of how long an operation will take and this might work but it’s way better to create a script with a loop which constantly checks the operation progress and status. By doing that you’re not dependent on a certain delay time and you will have the overall process move on immediately after an operation is completed. In addition you’ll also catch potential errors which might occur.

In this example i have put this monitoring script in the Nutanix Calm Blueprint Service -> Postgres -> VM -> Pre-create section and it’s part of a Calm Postgres Single Instance DB provisioning blueprint.

The Calm Task is configured according to:

The only variables you need to adjust/change before you can start using the script are:

  • era_cred – which is a Calm Credential where you have specified username and password for an Era user.
  • era_ip – IP address or FQDN of your Era server
  • OPERATIONS_ID – The Era operations ID for the operation you’d like to monitor. The operationId is included in the Era API response when submitting an operation, just extract the operationId and store it in a Calm variable.

The below script will run for 90 minutes and every minute it will request a status update. Output looks like this:

Monitoring Script

# Import requests
import requests
# Set creds and headers
era_user = '@@{era_creds.username}@@'
era_password = '@@{era_creds.secret}@@'
# Set headers
headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
# Set URL and URI
eramonitorurl = "https://@@{era_ip}@@/era/v0.9/operations/@@{OPERATIONS_ID}@@"
#print eramonitorurl
#
headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
#
print("Monitor DB provisioning progress")
# Create loop which runs for 60 minutes
for x in range(90):
 print "Waiting for 60 seconds before next provisioning status check."
 sleep (60)
 eramonitor = requests.get(
  eramonitorurl,
  headers=headers,
  auth=(era_user, era_password),
  verify=False
 )
 if json.loads(eramonitor.content)['status'] == "3" or json.loads(eramonitor.content)['status'] == "4" or json.loads(eramonitor.content)['status'] == "9" or json.loads(eramonitor.content)['status'] == "11" or json.loads(eramonitor.content)['status'] == "15":
  print "Failure identified based on deployment status being:", json.loads(eramonitor.content)['status']
  print "With failure message:", json.loads(eramonitor.content)['message']
  # Reason for exiting 0 when failure occurs is that we need the Calm blueprint to cleanup things in other systems 
  exit(0)
 elif json.loads(eramonitor.content)['percentageComplete'] == "100" and json.loads(eramonitor.content)['status'] == "5" :
  print "Success identified with deployment status:", json.loads(eramonitor.content)['status'], "and deployment progress percentage:", json.loads(eramonitor.content)['percentageComplete']
  break
 else:
  print "Still waiting for deployment process to be completed, now at",json.loads(eramonitor.content)['percentageComplete'],"percentage completion"
  print ""
#

———————————————————————————