BACKGROUND:
Lavastorm provides a REST API to upload and update LXA’s without end-user intervention. While full documentation of this API can be found in the Lavastorm Administration Guide, this document demonstrates uploading and updating LXA’s using command-line tools.
These examples require a DOS or bash prompt set up for the Lavastorm environment per the Enterprise and Windows Server installation guides. The same prompt can be used throughout this demonstration.
The examples in this document are written using Git’s bash prompt for Microsoft Windows 10. Italics denote sample values.
LOGIN
To start, we must login via the /login/rest endpoint. This endpoint returns a user token that will be used in the next calls to upload or update the LXA.
curl -H "Content-Type: application/json" -X POST -d '{"username":"admin","password":"welcome"}' http://localhost:8610/login/rest
This call should return a token that looks like the following:
gfzLYHgiR%2FD7Phgirhi9T1iusr2IiDfzAZc56NjoDryJ1ihxgEOwtLrtheqGlwb%2F
Full documentation of this endpoint is available in section 9.1 of the LAE Administration Guide.
PUBLISH AN LXA FOR THE FIRST TIME:
In order to publish a new LXA, the LXA must be base64 encoded and then placed in a JSON request prior to publishing to Lavastorm. This section will step you through this process.
First, use the base64Encode.py file to base64 encode the LXA you want to publish. This can be done via the following command:
python base64encode.py example.lxa
This command will create a new file called filename.base64. In the above example, a file named example.lxa.base64 will be created.
Next, remove all whitespace from this file. The following tr command, available on Linux, will work for Windows and Linux environments:
tr -d ‘\r\n’ < example.lxa.base64 > example.lxa.base64.clean
From this clean file, a JSON document can be created to upload the LXA per section 9.2 of the LAE Administration Guide. It is important to pay attention to the path and name attributes. Since really long text lines can slow down many editors, I suggest creating one file for the header, one file for the footer, and using the cat command to join these two files together into a single JSON file.
Once that JSON file is created, upload it using the following command:
curl -H 'Content-Type: application/json' -X POST -d @uploadExample.json http://localhost:8610/schedule/rest/automation/put-object?ltk=token
Be sure to save the returned path as that path will be used to update this LXA in the future. The path should appear in a returned JSON object similar to the following: {"path":"deploy/lxa/Example"}.
UPDATE AN LXA
Updating an LXA is a two-step process outlined in section 9.8 of the LAE Administration Guide. First, the version of the current object must be retrieved. Then, the new LXA must be sent back to the server with the version of the previous LXA in the request JSON.
We will first get the version number of the LXA using the get-object endpoint as shown below. Be sure to provide the path you used when uploading the LXA.
curl -H 'Content-Type: application/json' -X POST -d '{"path":"deploy/lxa/Example"}' http://localhost:8610/schedule/rest/automation/get-object?ltk=token > updateExample.json
Next, base64 encode the LXA using the base64encode.py process outlined above. After cleaning out the newlines, replace the base64-encoded file in the returned JSON with the one that you just created.
Finally, update the LXA via the below put-object call:
curl -H 'Content-Type: application/json' -X POST -d @updatedExample.json http://localhost:8610/schedule/rest/automation/put-object?ltk=token
Comments
0 comments
Please sign in to leave a comment.