应用计划
应用套餐时,将部署 IBM Cloud® 资源,以在 IBM Cloud 帐户上构建具有特定配置属性选择的 Spectrum LSF 集群实例。
1、使用 UI 应用计划
(1)在 IBM Cloud 控制台中生成计划后,单击 应用计划。 此操作将生成可在 "作业" 选项卡中查看的新日志。
(2)查看日志文件以查找任何错误,修正错误,然后再次单击 应用计划 。
(3)成功应用计划后,可以通过单击 资源 选项卡来查看在此工作空间下部署的所有资源。
2、使用 CLI 应用计划
运行以下命令以将计划应用于工作空间:
ibmcloud schematics apply --id <WORKSPACE_ID>
在部署资源时,您可以监视日志文件以查找错误或确认操作已成功完成。 根据作为配置文件一部分供应的虚拟服务器数,此步骤可能需要一些时间。 运行以下命令以监视日志文件:
ibmcloud schematics logs --id <WORKSPACE_ID>
样本响应:
2021/04/05 09:44:54 Terraform apply | Apply complete! Resources: 14 added, 0 changed, 0 destroyed.
2021/04/05 09:44:54 Terraform apply |
2021/04/05 09:44:54 Terraform apply | Outputs:
2021/04/05 09:44:54 Terraform apply |
2021/04/05 09:44:54 Terraform apply | sshcommand = ssh -J root@52.116.124.67 root@10.241.0.6
2021/04/05 09:44:54 Command finished successfully.
2021/04/05 09:45:00 Done with the workspace action
成功应用计划后,它会在 Terraform 代码的 输出 部分中生成 sshcommand 。 您可以使用此命令登录到 Spectrum LSF 集群。 只能从其 IP 地址在 remote_allowed_ips中指定的系统成功运行此 SSH 命令。
3、使用 API 应用计划
(1)要使用 IBM Cloud Schematics Python API 来应用计划,请创建 Python 文件并提供您选择的名称,例如 schematics_apply_plan.py。
(2)将 使用 Schematics Python API 示例请求复制并粘贴到 Python 文件。
(3)在请求中更改以下参数:
·将 IBM Cloud API 密钥替换为 authenticator = IAMAuthenticator('
·根据您希望 Schematics 工作空间驻留的位置 (例如 schematics_service.set_service_url('https://us.schematics.cloud.ibm.com')) ,将 API 端点更改为 API 端点 中提到的端点。
1)在 schematics_service.apply_workspace_command 函数中,提供以下参数:
·提供在 创建工作空间 任务中生成的工作空间标识,例如 us-south.workspace.Terraform-Schematics-Python-Workspace.b3bbc9f5。
·使用以下命令导出 IBM Cloud API 密钥:
export IBMCLOUD_API_KEY =”<ibm-cloud-api-key>”
·运行以下 curl 命令以创建刷新令牌:
curl -X POST "https://iam.cloud.ibm.com/identity/token" -H
"Content-Type: application/x-www-form-urlencoded" -d
"grant_type=urn:ibm:params:oauth:grant-
type:apikey&apikey=$IBMCLOUD_API_KEY" -u bx:bx
1)使用 python3
2)如果作为请求的一部分传递的参数有效,那么您将获得响应中的活动标识。 您应该会看到正在 IBM Cloud 控制台中创建的 Schematics 工作空间中应用计划。 如果未获得成功响应,那么错误响应包含需要解决的错误。 请解决这些错误并运行该脚本,直到您能够获取有效响应并应用计划为止。
3)如果要检查操作的日志,请参阅 使用 Schematics API 检索操作日志 以检索日志。 响应包含操作的状态,并且以 COMPLETED 或 FAILED 状态显示。
示例 Python 请求
# Apply a plan using Schematics Python API
import json, logging
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
from ibm_schematics.schematics_v1 import SchematicsV1
logging.basicConfig()
logging.root.setLevel(logging.NOTSET)
logging.basicConfig(level=logging.NOTSET)
authenticator = IAMAuthenticator('<ibmcloud-api-key>')
schematics_service = SchematicsV1(authenticator = authenticator)
schematics_service.set_service_url('https://us.schematics.cloud.ibm.com')
logging.info("Started Applying Schematic Plan")
workspace_activity_apply_result = schematics_service.apply_workspace_command(
w_id='<workspace id>',
refresh_token='<refresh-token>'
).get_result()
print(json.dumps(workspace_activity_apply_result, indent=2))
logging.info("Completed Applying Schematic Plan")
INFO:root:Started Applying Schematic Plan
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): iam.cloud.ibm.com:443
DEBUG:urllib3.connectionpool:https://iam.cloud.ibm.com:443 "POST /identity/token HTTP/1.1" 200 985
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): us.schematics.cloud.ibm.com:443
DEBUG:urllib3.connectionpool:https://us.schematics.cloud.ibm.com:443
"PUT /v1/workspaces/us-south.workspace.Schematic-Sunil-Test-
Workspace.5a4cbf11/apply HTTP/1.1" 202 49{
"activityid": "33bade478b4e93f5c613e4f62943ad9a"}
INFO:root:Completed Applying Schematic Plan