Creating automation script to generate ManageIQ authentication token

This topic describes how to create an automation script to generate a ManageIQ authentication token.

  1. Open the Automation Scripts application.
  2. On the navigation panel, click Create and select Script.
  3. On the Create Script pop-up, fill the fields as follows:
    • Script: Specify a name, for example, MANAGEIQ_AUTHTOKEN
    • Script Language: Search and select jython
    • Log Level: Search and select Debug
    • Version: Enter version, for example, 0.0
    • You can import the below script or paste it on the below script box, and click Create.
      from psdi.server import MXServer
      from java.util import HashMap
      from com.ibm.json.java import JSONObject
      from psdi.iface.router import Router
      from psdi.iface.mic import EndPointCache
      from java.lang import String
      from psdi.app.ticket import TicketRemote
      import sys,_imp
      from java.lang import System
      from psdi.mbo import MboRemote, MboSetRemote, SqlFormat, MboConstants
      from psdi.mbo import MboSetEnumeration
      from java.util import Calendar
      from org.python.core import PyTuple
      
      
      # get Endpoint/Handler. If not specified - use the default RBA_REST endpoint name
      credential_to_use = "MANAGEIQ_AUTH"
      print "using end point: ", credential_to_use
      
      handler = Router.getHandler(credential_to_use)
      
      print "credentials being used: ", credential_to_use
      # get the username, password and url from the endpoint mbo
      username = handler.getUserName();
      print "username = ", username
      
      endPointInfo = EndPointCache.getInstance().getEndPointInfo(credential_to_use)
      password  = endPointInfo.getProperty("PASSWORD").getValue()
      
      url = handler.getUrl() + "/api/auth"
      print "url =", url
      
      query = "_format=json"
      
      paramMap = {"URL":url, "username":username, "password":password}
      result = String(handler.invoke(paramMap, query))
      
      # We printed the json here to see what the format was to properly dig into the resultant object.
      # print "Got back: ", result
      jsnResp = JSONObject.parse(result)
      System.out.println('==========================================================')
      System.out.println(jsnResp)
      token = jsnResp.get("auth_token")
      System.out.println('==========================================================')
      
      System.out.println(token)
      #responseBody = description