REST API Python Interface

Altair Accelerator software includes a Python module that provides an interface to the REST API.

The following is an example script that utilizes the Python interface:
import os,sys,requests, json
scriptPath = os.path.dirname(os.path.abspath(__file__))

from vov_rest_v3 import *

# You must use the web port for the base URL for V3 REST
nc_url = 'https://hexagon:9101'
password = "mysecret"

# Connect and get a valid JWT token using auth
conn = VOVRestV3()
conn.authorize( nc_url, password )

# Create a job
scriptPath = os.path.dirname(os.path.abspath(__file__))
logPath = os.path.join(scriptPath, "joblogs")
os.makedirs(logPath, 0o700, True)
logFilePath = os.path.join(logPath, f'job_{str(os.getpid())}.log')
print(f'\nJob log path = {logFilePath}')
jobPayload = { 
    "command": "sleep 1",
    "env": "BASE",
    "resources": "linux64",
    "group": "/time/users",
    "preemptable": 1,
    "jpp": "fastest",
    "fstokens": 1,
    "rundir": ".",
    "logfile": logFilePath
res = conn.submitRequest(method="POST", url=nc_url + "/api/v3/jobs", jsonData=jobPayload)
jobid = json.loads(res)["jobid"]
print(f'\nNew Job ID = {jobid}')

# Query jobs
query = { 
  "select": "id,statusnc,name",
  "from": "jobs",
  "order": "ID desc"
res = conn.submitRequest(method="GET", url=nc_url + "/api/v3/query", queryParams=query)
rowlist = json.loads(res)["rows"]
print('\nThe job list is:')
for row in rowlist:
The Python interface has two requirements:
  1. Python 3
  2. The requests module (can be installed via easy_install: sudo python3 -m easy_install requests).
The script is then called with the full URL path of the API, as described in the previous section. Both HTTP and HTTPS are supported by the Python interface library, but since you are transmitting user credentials, it is STRONGLY recommend to set up and use HTTPS. You must use the web port for the URL. The V3 REST API does not work over the VOV port:
If you are not using HTTPs, you may want to add the following before using the REST API:
Job log path = /home/myuser/pyclient/joblogs/job_28107.log

New Job ID = 11480

The job list is:
['000011480', 'Running', 'vw sleep 1 > /home/myuser/pyclient/joblogs/job_28107.log']
The output of the above script will be similar to:
Job log path = /home/myuser/pyclient/joblogs/job_28107.log
New Job ID = 11480
The job list is:
['000011480', 'Running', 'vw sleep 1 > /home/myuser/pyclient/joblogs/job_28107.log']

The V3 Python interface requires authentication, which you pass in as part of call to authorize(). The V3 REST API uses an OAuth2 JWT token which is passed back in response to a valid username and password. The V3 Python interface keeps this JWT on the object and uses it for subsequent submitRequest() calls. If JWT token is good for 8 hours.

If you’d like to persist the JWT token for use in multiple Python scripts, you can call getJWT() to get the token string, and call setJWT() instead of authorize() to use the JWT in another VOVRestV3 instance.