申请试用

使用 pacclient.py 访问 REST API 调用


IBM Spectrum LSF Application Center 为应用程序提交,数据管理,作业信息查询,作业操作等提供标准 RESTful Web 服务。 LSF Applicationn Center Web Service API 可与多种语言和方法集成。 此示例显示如何使用 pacclient.py(这是基于 Python 3 的客户机) 来访问 LSF Application Center REST API 调用。


  请注意:此示例假定 LSF Application Center 配置为通过 http使用 REST API。 有关更多信息,请参阅 LSF Application Center Web Service。


准备工作

在使用 http连接到 LSF Application Center 之前,需要完成以下步骤:

(1)要从设备访问 LSF Application Center REST API ,需要设置 SSH 连接。 您可以通过新的命令行终端从本地设备连接到 LSF 管理节点。 Schematics 日志输出包含所需的 LSF Application Center 信息。

  1. ssh -L 8080:localhost:8080 -J root@{FLOATING_IP_ADDRESS} lsfadmin@{MANAGEMENT_NODE_IP_ADDRESS}


其中, MANAGEMENT_NODE_IP_ADDRESS 需要替换为与 <cluster_prefix>-management-host-0关联的管理节点 IP 地址, FLOATING_IP_ADDRESS 需要替换为登录节点浮动 IP 地址。 要查找管理和登录节点 IP ,请参阅 收集 IP 地址的指示信息。


(2)打开第二个终端,下载并安装 Python 3.6 或更高版本。 以下示例适用于 Linux 和 MAC 系统。 如果您正在使用 Windows ,那么安装将有所不同。 有关更多信息,请参阅 适用于 Windows 的Python 发行版


    重要信息:从此第二个终端运行以下所有命令。


a.通过运行以下命令来安装 Python 3 (3.6 或更高版本) 和 pip3 :

yum install python3
yum install python3-pip


b.通过运行以下命令来安装 httplib2 :

pip3 install httplib2


c.通过运行以下命令来安装 configparser :

pip3 install configparser


d.通过运行以下命令来安装 urllib3 :

pip3 install urllib3


(3)将以下存储库克隆到本地设备:

git clone https://github.com/IBMSpectrumComputing/lsf-
integrations.git
cd Spectrum\/LSF\/Application\/Center/pacclient/


使用 http 连接到 LSF Application Center

打开新的命令行终端并运行以下命令:

$ ./pacclient.py help
 pacclient.py usage:

 ping      --- Check whether the web service is available
 logon     --- Log on to IBM Spectrum LSF Application Center
 logout    --- Log out from IBM Spectrum LSF Application Center
 app       --- List applications or parameters of an application
 submit    --- Submit a job
 job       --- Show information for one or more jobs
 jobaction --- Perform a job action on a job
 jobdata   --- List all the files for a job
 download  --- Download job data for a job
 upload    --- Upload job data for a job
 usercmd   --- Perform a user command
 useradd   --- Add a user to IBM Spectrum LSF Application Center
 userdel   --- Remove a user from IBM Spectrum LSF Application Center
 userupd   --- Updates user email in CSV format from IBM Spectrum LSF Application Center.
 pacinfo   --- Displays IBM Spectrum LSF Application Center
 version, build number and build date
 notification --- Displays the notification settings for the current user.
          --- Registers notifications for a workload.
 flow          --- Show details for one or more flow instances from IBM Spectrum LSF Process Manager.
 flowaction    --- Perform an action on a flow instance from IBM Spectrum LSF Process Manager.
 flowdef       --- Show details for one or more flow definitions from IBM Spectrum LSF Process Manager.
 flowdefaction --- Perform an action on a flow definition from IBM Spectrum LSF Process Manager. help      
 --- Display command usage # Login to the LSF Cluster.
 $ ./pacclient.py logon -l http://localhost:8080 -u lsfadmin -p xxxxxxx
 You have logged on to PAC as: lsfadmin # Submit a Job in LSF cluster.
 $ ./pacclient.py submit -a generic -p "COMMANDTORUN=sleep 200"
 The job has been submitted successfully: job ID 45439

 # List out existing and running jobs.
 $ ./pacclient.py job
 JOBID     STATUS    EXTERNAL_STATUS        JOB_NAME                 COMMAND 45439     Running   -                      *938772910               sleep 200

 # Stop running job.
 $ ./pacclient.py usercmd -c "bstop 45439"
 Job <45439> is being stopped

 $ ./pacclient.py job
 JOBID     STATUS    EXTERNAL_STATUS        JOB_NAME                 COMMAND 45439     Suspended -                      *938772910               sleep 200

 # Resume running job.
 $ ./pacclient.py usercmd -c "bresume 45439"
 Job <45439> is being resumed

 $ ./pacclient.py job
 JOBID     STATUS    EXTERNAL_STATUS        JOB_NAME                 COMMAND 45439     Running   -                      *938772910               sleep 200