Python API reference
By default, IBM Spectrum LSF Application Center provides the client API in Python. There is an example of how to access the IBM Spectrum LSF Application Center web services. The location is: PAC_TOP/gui/3.0/bin/pac_api.py
To use the API, the Python program must import the modules:
sys
os
getopt
httplib2
From xml.dom, import minidom
From ConfigParser, import ConfigParser
getpass
From pac_api, import *.
ping (url)
Description
The ping API implements the ping web service. It detects whether or not a web service is running at the specified URL.
Input
- url
A web service URL
Format: http://host_name:port_number/ or https://host_name:port_number/
Output
- On success
"Web services are ready..."
- On failure
"Web services are not ready..."
logon (url, username, password)
Description
The logon API implements the logon web service. It generates the security token required to access the other web services.
The URL and security token are saved to: $HOME/.pacpass.
Input
- url
Non-empty string
Format: http://host_name:port_number/ or https://host_name:port_number/
- username
Non-empty string
- password
Non-empty string
Output
- On success
Get security token
Save URL and token in .pacpass
- On failure
Print error message
logout()
Description
The logout API implements the logout web service. It invalidates the security token, and the user can no longer access the other web services.
logout releases the security token in the following location: $HOME/.pacpass.
logout also removes the .pacpass file.
Input
$HOME/.pacpass or $HOMEPATH\.pacpass
Output
- On success
Release the security token from the IBM Spectrum LSF Application Center host
Remove .pacpass from the client
- On failure
Print error message
status,message = getAllAppStatus()
Description
The getAllAppStatus API implements the get application list web service. It lists the applications and application status.
Input
Empty
Output
- On success
(status="ok")
message = <AppInfos><AppInfo><appName>%s</appName><status>%s</status></AppInfo>
<AppInfo><appName>%s</appName><status>%s</status></AppInfo><AppInfo>...</AppInfo></AppInfos>
- On failure
(status="error")
message = <AppInfo><errMsg>Error message </errMsg></AppInfo>
status,message = getAppParameter(appName)
Description
The getAppParameter API implements the get application parameters web service. It lists the parameters of an application.
Input
Job ID
Output
- On success
(status="ok")
message = <AppParams><AppParam><id>%s</id><label>%s</label<mandatory>%s</mandatory>
<defaultValue>%s</defaultValue>></AppParam>
<AppInfo>...</AppInfo>
<AppParams>
- On failure
(status="error")
message = <AppInfo><errMsg>Error message </errMsg></AppInfo>
status,message = submitJob(jobDict)
Description
The submitJob API implements the submit job web service. It submits a job to IBM Spectrum LSF Application Center.
The API specifies job parameters and uploads the required data files, and submits the job to LSF®.
Input
- jobDict
Job parameters dictionary. It must include all the following:
JobDict[APP_NAME]= <App_Type>:<App_Instance>
JobDict['PARAMS']= { <ID>:<VALUE>, <ID>:<VALUE> …}
JobDict['INPUT_FILES']={ <ID>:<FILEPATH, LOADING_TYPE>, <ID>:<FILEPATH, LOADING_TYPE> …}
Where:
<ID> is the parameter ID from application form, could be from CONSOLE.
<LOADING_TYPE> is one of the following: “upload”, “copy”, “link”
The <FILEPATH> must be a local path for “upload”.
The <FILEPATH> must be a IBM Spectrum LSF Application Center server path for “copy” and “link”.
Output
- On success
(status="ok") job ID
- On failure
(status="error") error messages returned from the web service
status,message = getJobListInfo (parameter)
Description
Returns short or detailed information for jobs and job arrays with the specified job ID, job name, job status. It also returns jobs and job arrays that belong to a specified job group, were submitted by a specified user, or that have finished within a specified time period. By default, when no parameters are specified, returns short information for all jobs and job arrays submitted by the user who is currently logged on.
The information returned is similar to the information that can be retrieved with the LSF commands bjobs and bhist.
Input
Parameters can be combined together with &.
- id
- Job ID or job array ID. Integer.
- status
- Job status. String. Possible values:
- Pending
- Suspended
- Running
- Exit
- Done
- name
- Name of job. String.
- group
- Name of job group to which the job belongs. String.
- user
- Name of user for which to display job information. The logged in user must have permission to view the jobs. Specify the keyword all to retrieve information for all jobs of all users.
- details
- Return detailed information about a job. Valid values:
- yes
- no
- past
- Number of hours. Integer. Can only be used with the job status Done or Exit. Retrieves information for jobs that have finished within the specified number of hours.
Output
- On success
Short format:
(status="ok") message = <Jobs> <Job> <name>%s</name> <id>%s</id> <status>%s</status> <cmd>%s</cmd> </Job> <Job> ... </Job> </Jobs>
Detailed format:
(status="ok") message = <Jobs> <Job> <name>%s</name> <id>%s</id> <status>%s</status> <cmd>%s</cmd> <cwd>/home/lsfadmin/generic_1342080220286ST0Yx</cwd> <description>-</description> <exHosts>test</exHosts> <execCwd>/home/lsfadmin/generic_1342080220286ST0Yx</execCwd> ... <Job> ... </Job> </Jobs>
The following is the information returned when the parameter details=yes. All returned information is of type String.
Job information Description Application Profile The application profile the job was submitted to. Application Type Name of submission template used to submit the job. Command The job command specified during job submission. Current Working Directory The current working directory on the submission host. Description The job description assigned to the job during job submission. End Time For done or exited jobs: when the job finished. For running jobs, when the job is estimated to finish. Calculated as Current time + Time Remaining. Estimated Run Time Estimated running time for the job specified by the user during job submission, with the LSF command bsub -We. Execution Cwd Current working directory where job is running. Execution Hosts The name of one or more hosts on which the job is running. Exit Code Job exit code. External Status External status information for a job, specified with the LSF command bpost -d. Graphic Job Indicates whether the job was submitted with remote console support enabled. Input Files Input files specified during job submission. Job ID The job ID that LSF assigned to the job. Job Name Name of job specified during job submission. Job Priority Priority specified for the job during job submission. Job Type Type of workload. Possible values: are job, job array, or flow. Mem Total resident memory usage in MB, of all processes in a job. For host-based resource usage, the total resident memory usage of all processes in a job running on a host. Number of threads Number of currently active threads of a job. Output Files Output files created by the job. Pending Reason The reason the job is in the Pending state. Process Group ID Currently active process group ID in a job. Process ID Currently active processes in a job. Project The project the job was submitted from. Queue The name of the job queue to which the job was submitted. Requested Hosts All the resource requirement strings you specified during job submission. Required Processors Number of processors specified as required to run the job during job submission. Run Time How long the job has been running. Start Time When the job started running. Status Current status of job. Submission Host Host from which the job was submitted. Submission Time When the job was sent to the system. Swap Total virtual memory usage in MB, of all processes in a job. For host-based resource usage, the total virtual memory usage of all processes in a job running on a host. Time Remaining Time remaining to complete the job. Calculated as Estimated Runtime – Runtime. Available only for jobs submitted with an estimated runtime with the LSF command bsub -We. User The user who submitted the job. - On failure
(status="error") error messages returned from the web service.
Example
status, message = getJobListInfo('status='+jobStatus+'&user='+user+'&details='+details+'&past='+past)
status,message = getJobInfo (jobId)(Deprecated)
Description
Deprecated since version 9.1.0.0. Use status,message = getJobListInfo (parameter) instead.
The getJobInfo API implements the get job web service. It shows job information for a job with the specified job ID.
Output includes the external status for a job. You use bpost -d to provide external status information for a job. You can also view this status in the Jobs page, with the External Status column. You will need to select the column for display with the Options button.
Input
- jobId
Non-empty string
Matches the LSF job ID
Output
- On success
(status="ok") "<Job> <id>%s</id><name>%s</name><status>%s</status><cmd>%s</cmd><extStatus>%s</extStatus></Job>"
- On failure
(status="error") error messages returned from the web service
status,message = getJobForStatus(jobStatus)(Deprecated)
Description
Deprecated since version 9.1.0.0. Use status,message = getJobListInfo (parameter) instead.
The getJobForStatus API implements the get jobs for status web service. It shows job information for jobs having the specified job status.
Output includes the external status for a job. You use bpost -d to provide external status information for a job. You can also view this status in the Jobs page, with the External Status column. You will need to select the column for display with the Options button.
Input
- jobStatus
One of the following:
Running
Pending
Suspended
Exit
Done
Output
- On success
(status="ok")
“<Jobs> <Job> <id>%s</id> <name>%s</name><status>%s</status><cmd>%s</cmd></Job><extStatus>%s</extStatus><Job> <id>%s</id> <name>%s</name><status>%s</status><cmd>%s</cmd><extStatus>%s</extStatus></Job>…</Jobs>”
- On failure
(status="error") error messages returned from the web service
status,message = getJobForName(jobName)(Deprecated)
Description
Deprecated since version 9.1.0.0. Use status,message = getJobListInfo (parameter) instead.
The getJobForName API implements the get jobs for name web service. It shows job information for jobs matching the specified job name pattern.
Output includes the external status for a job. You use bpost -d to provide external status information for a job. You can also view this status in the Jobs page, with the External Status column. You will need to select the column for display with the Options button.
Input
- jobName
Job name string pattern
"*" is supported in the job name string to match multiple jobs
Output
- On success
(status="ok")
“<Jobs><Job> <id>%s</id> <name>%s</name><status>%s</status><cmd>%s</cmd><extStatus>%s</extStatus></Job><Job> <id>%s</id> <name>%s</name><status>%s</status><cmd>%s</cmd><extStatus>%s</extStatus></Job>…</Jobs>”
- On failure
(status="error") error messages returned from the web service
For example: "Error to get Job info for job name: fluent*"
status,message = doJobAction(jobAction, jobId)
Description
The doJobAction API implements the job operation web service. It controls jobs. The following job control actions are supported: kill, suspend, resume, and requeue.
Input
- jobAction
One of the following:
Kill
Suspend
Resume
Requeue
- jobId
A unique number for the job ID
Output
- On success
(status="ok") action response message from LSF
- On failure
(status="error") error messages returned from the web service
status,message = doUserCmd(userCmd)
Description
Send the command to the Platform Application Web Services for execution. Used to extend actions you can take on jobs or to execute custom commands.
Input
- userCmd
A command listed in the configuration file $GUI_CONFDIR/webservice.usercmd.
By default, the following LSF commands are listed in this file:
- bbot
- bchkpnt
- bkill
- bpost
- brequeue
- brestart
- bresume
- brun
- bstop
- btop
- bswitch
- bmig
You can also add any other commands to the file that you want to run such as for example, ls or hostname.
Output
- On success
(status="ok") command response message from LSF
- On failure
(status="error") error messages returned from the web service
files = jobdataList(jobId)
Description
The jobDataList API implements the get job file list web service. It lists all the files for a job.
Input
Job ID
Output
A string in the format:
host_name:path;host_name2:path2; ... host_nameN:pathN
downloadJobFiles(jobId, dstPath, dFile, cmd)
Description
The downloadJobFiles API implements the download a file web service. It downloads job data for a job.
This API downloads all files under the job directory.
Input
- jobId
Non-empty string
Matches the LSF job ID
- dstPath
The destination directory path
If it is an empty string, use the current directory
- dFile
The name of the file.
If it is an empty string, download all files
To specify multiple files, separate with a comma(,). You can also use the following wildcard characters in a file name to indicate multiple files, including the following characters:
- * - any number of alphanumeric characters
- ? - a single alphanumeric character
- [0-9] - a numeric character between 0 and 9.
- [a-z] - a single lower case letter from a to z.
- [A-Z] - a single capital letter from A to Z.
If there are white spaces, commas, or wildcard characters in the text, you must use double-quotation marks to enclose the text.
- cmd
-
Optional. Command to use to compress files before downloading. If you do not specify the command, files are not compressed before downloading. The compression program must be installed on the Platform Application Center server and must be in the system path. The output of the compression command is returned by the API.
Examples
- downloadJobFiles(100, /home/user1, "jobfile_*")
- downloadJobFiles(101, /home/user1, "jobfile_1,jobfile_2,jobfile_3")
- downloadJobFiles(102, /home/user1, "jobfile_[0-9]")
- downloadJobFiles(103, /home/user1, "jobfile_*,file 1.txt, file 2.txt")
- downloadJobFiles(105, /home/user1, "myfile", gzip)
Output
- On success
Download the job files and copy them to <dstPath>.
If a compression command is specified, compresses each specified file, downloads, and copies to <dstPath>.
- On failure
Do not copy any files, check error message in IBM Spectrum LSF Application Center log file
uploadJobFiles(jobId, dstPath, dFile)
Description
Uploads data for a job to the job directory on the web server or the remote directory on a specific host. By default, if a job ID is specified but no directory is specified, files are uploaded to the job directory on the web server.
The job can be in any status.
Input
- jobId
Only used to upload files to the job directory on the web server.
The ID of the job for which to upload files.
The ID must be a positive integer and must match an LSF job ID.
- dstPath
Format:
[host_name:]dstPath
Optional. Uploads files to the specified directory on the web server. The directory can be an absolute path on the web server or a relative path to the job directory on the web server. If not specified, the job directory on the web server is used.
When a host name is specified, uploads files to the specified job directory on the specified host. The directory must be an absolute path to the remote job directory on the host. The host can be any LSF server host.
- dFile
- Files to upload. To specify multiple files, separate with a comma(,).
If no path is specified for the file, the job directory on the web
server is used as the location of the file. If no file is specified,
all files in the directory are uploaded.
If it is an empty string, uploads all files.
Output
- On success
Uploads the job files and copies them to <dstPath>.
- On failure
Do not upload files, check error message in IBM Spectrum LSF Application Center log file
getNotificationSetting()
Description
The getNotificationSettings API implements the GET notification settings web service. It returns the notification settings for the login user.
Input
Empty
Output
- On success
-
(status="ok")
message
<UserNotificationSettings> <UserName>user1</UserName> <UserEmail>user1@company.com</UserEmail> <AppParam> <defaultValue>Y</defaultValue> <id>NOTIFY_ENABLE</id> <label>Enable notifications</label> <type></type> <value>Y</value> </AppParam> <AppParam> <defaultValue>START,END</defaultValue> <id>NOTIFY_EVENTS</id> <label>Workload events</label> <type></type> <value>START,END</value> </AppParam> <AppParam> <defaultValue>BROWSER,EMAIL</defaultValue> <id>NOTIFY_CHANNELS</id> <label>Notification channels</label> <type></type> <value>BROWSER,EMAIL</value> </AppParam> </UserNotificationSettings>
- On failure
-
(status="error")
message = Error message
registerNotification(workloadId, params)
Description
The registerNotification API implements the POST registering notification web service. It returns the result of registering notification for a workload.
Input
- workloadId
-
Non-empty string
Matches either an LSF job ID or a flow ID
- Params
-
Python hash table contains parameter name and value pairs.
Valid parameter names are NOTIFY_EVENTS, NOTIFY_CHANNELS.
Valid parameter values for NOTIFY_EVENTS are START,END,SUSPENDED, FAIL delimited by a comma.
Valid parameter values for NOTIFY_CHANNELS are BROWSER,DESKTOP,EMAIL,MOBILE delimited by a comma.
Output
- On success
-
(status="ok")
message =”The workload id workloadId has been registered for status change notifications.”
- On failure
-
(status="error")
message = Error message