Accessing REST API calls with curl
IBM Spectrum LSF Application Center provides standard RESTful web services for application submission, data management, job information query, job actions, and more. The LSF Application Center web service API can be integrated with many languages
and methods. This example shows how to access the LSF Application Center REST API calls by using curl.
Before you begin
Before accessing the LSF Application Center through https, you must first establish a secure SSH tunnel from your local machine to the LSF management node.
-
Open a terminal on your local system.
-
Use the SSH command provided in your deployment logs (refer to the variable application_center_tunnel).
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ServerAliveInterval=5 -o ServerAliveCountMax=1 -L 8443:localhost:8443 -L 6080:localhost:6080 -L 8444:localhost:8444 -J ubuntu@<Bastion_Node_IP> lsfadmin@<Management_Node_IP>This command creates an encrypted tunnel that forwards the required ports (8443, 6080, and 8444) from the LSF management node to your local machine, enabling secure browser access to the Application Center GUI.
Connecting to LSF Application Center with curl
-
Open a new command line from your local device and run the following commands:
-
Define or export the following variables:
export SSL_INSECURE=1 export AC_HOST=localhost export AC_PORT=8443 export AC_USER=lsfadmin export AC_PASSWORD=<mynicepassword> -
Ping the cluster:
curl -k -X POST -H "Accept: application/json" https://$AC_HOST:$AC_PORT/platform/ws/ping -
Log in to the cluster:
curl -k -X POST -H "Accept: application/json" -H "Content-Type: application/xml" -d "<User><name>$AC_USER</name> <pass>$AC_PASSWORD</pass> </User>" https://$AC_HOST:$AC_PORT/platform/ws/logonThe output of this command contains the token that you need to run commands. The token is only valid for a particular time frame.
Example output:
{"csrftoken":"dbf6208a-0c01-4cb3-b6e1-9f75390311e5","token":"lsfadmin\"2022-05-25T20:53:12Z\"cn8FS6/FIXiVZc5vMpfPdoob9bosjk85u3lEPseqrWdX+DyWMPYkYgPOC5UJ+a4m87zyjHDq1DhjIZyYx1X47SFGRS4MRzeah94l+EpNBazKilXsG8cVuYyUgtz9M0J6\"PBNNTKLPN3JlyOpnCqI7cg=="} -
After you receive your token, you need to make two changes to it. First, add
"platform_token="at the beginning of the token, and second, replace the\"with#quote#. See the following example of an updated token:export MYTOKEN=platform_token=lsfadmin#quote#2022-05-25T20:53:12Z#quote#cn8FS6/FIXiVZc5vMpfPdoob9bosjk85u3lEPseqrWdX+DyWMPYkYgPOC5UJ+a4m87zyjHDq1DhjIZyYx1X47SFGRS4MRzeah94l+EpNBazKilXsG8cVuYyUgtz9M0J6#quote#PBNNTKLPN3JlyOpnCqI7cg== -
Get cluster information:
curl -k -X GET -H 'Content-Type: application/xml' -H "Cookie: $MYTOKEN" -H 'Accept:text/plain,application/xml,text/xml,multipart/mixed' -H 'Accept-Language:en-us' https://$AC_HOST:$AC_PORT/platform/ws/clusters/local -
Get the LSF Application Center version (Optional):
curl -k -X GET -H 'Content-Type: application/xml' -H "Cookie: $MYTOKEN" -H 'Accept:text/plain,application/xml,text/xml,multipart/mixed' -H 'Accept-Language:en-us' https://$AC_HOST:$AC_PORT/platform/ws/version -
List out the users (Optional):
curl -k -X GET -H 'Content-Type: application/xml' -H "Cookie: $MYTOKEN" -H 'Accept:text/plain,application/xml,text/xml,multipart/mixed' -H 'Accept-Language:en-us' https://$AC_HOST:$AC_PORT/platform/ws/users -
List groups ( ):
curl -k -X GET -H 'Content-Type: application/xml' -H "Cookie: $MYTOKEN" -H 'Accept:text/plain,application/xml,text/xml,multipart/mixed' -H 'Accept-Language:en-us' https://$AC_HOST:$AC_PORT/platform/ws/usergroups -
List host details (Optional):
curl -k -X GET -H 'Content-Type: application/xml' -H "Cookie: $MYTOKEN" -H 'Accept:text/plain,application/xml,text/xml,multipart/mixed' -H 'Accept-Language:en-us' https://$AC_HOST:$AC_PORT/platform/ws/hosts -
List existing jobs:
curl -k -X GET -H 'Content-Type: application/xml' -H "Cookie: $MYTOKEN" -H 'Accept:text/plain,application/xml,text/xml,multipart/mixed' -H 'Accept-Language:en-us' https://$AC_HOST:$AC_PORT/platform/ws/pacclient/jobs -
Get detailed job information by job ID (GET) (Optional):
curl -k -X GET -H 'Content-Type: application/xml' -H "Cookie: $MYTOKEN" -H 'Accept:text/plain,application/xml,text/xml,multipart/mixed' -H 'Accept-Language:en-us' https://$AC_HOST:$AC_PORT/platform/ws/jobs/<job ID> -
Get basic and detailed job information by job attributes (GET) (Optional):
curl -k -X GET -H 'Content-Type: application/xml' -H "Cookie: $MYTOKEN" -H 'Accept:text/plain,application/xml,text/xml,multipart/mixed' -H 'Accept-Language:en-us' https://$AC_HOST:$AC_PORT/platform/ws/jobs/fullinfo
-
-
Submit a job:
curl -k -X POST \ -H 'Content-Type: multipart/mixed; boundary=bqJky99mlBWa-ZuqjC53mG6EzbmlxB' \ -H 'Accept: text/xml, application/xml' \ -H "Cookie: $MYTOKEN" \ -H 'Accept-Language: en-us' \ -d ' --bqJky99mlBWa-ZuqjC53mG6EzbmlxB Content-Disposition: form-data; name="AppName" Content-ID: <AppName> generic --bqJky99mlBWa-ZuqjC53mG6EzbmlxB Content-Disposition: form-data; name="data" Content-Type: multipart/mixed; boundary=_Part_1_701508.1145579811786 Accept-Language: en-us Content-ID: <data> --_Part_1_701508.1145579811786 Content-Disposition: form-data; name="COMMANDTORUN" Content-Type: application/xml; charset=UTF-8 Content-Transfer-Encoding: 8bit Accept-Language: en-us <AppParam><id>COMMANDTORUN</id><value>sleep 99</value><type></type></AppParam> --_Part_1_701508.1145579811786-- --bqJky99mlBWa-ZuqjC53mG6EzbmlxB-- ' https://$AC_HOST:$AC_PORT/platform/webservice/pacclient/submitapp