使用 Schematics API 检索操作日志
(1)要检索操作的日志,例如生成计划,应用计划以及使用 IBM Cloud® Schematics Python API 销毁资源,请创建 Python 文件并提供您选择的名称,例如 schematics_logs_api.py。
(2)将 使用 Python API 检索 Schematics 工作空间操作详细信息 示例请求复制并粘贴到 Python 文件中。
(3)在请求中更改以下参数:
·将 authenticator = IAMAuthenticator('
·根据您希望 Schematics 工作空间驻留的位置 (例如 schematics_service.set_service_url('https://us.schematics.cloud.ibm.com')) ,将 API 端点更改为此链接中提到的端点。
1)在 schematics_service.get_workspace_activity 函数中,提供以下参数:
·提供在 创建工作空间 任务中生成的工作空间标识,例如 us-south.workspace.Terraform-Schematics-Python-Workspace.b3bbc9f5。
·提供作为要检索其日志的特定操作的成功响应生成的活动标识。 在 Schematics 工作空间中成功完成操作时,您接收到活动标识。
1)通过使用 python3
2)当确定作为请求的一部分传递的参数是否有效时,您将获得操作标识,名称和操作状态 (例如 COMPLETED 或 FAILED) 作为响应。 您应该能够检索特定 Schematics 工作空间的操作的日志。 如果未获得成功响应,那么错误响应包含需要解决的错误。 解决这些错误并运行脚本,直到您能够获取有效响应并检索日志为止。
示例 Python 请求
# Retrieve Schematics workspace action details using 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 Retrieving the Schematic logs")
workspace_activity = schematics_service.get_workspace_activity(
w_id='<workspace-id>',
activity_id='<activity-ID>').get_result()print(json.dumps(workspace_activity, indent=2))
logging.info("Completed Retrieving the Schematic logs")
示例 Python 响应
请注意:Python 响应是一个通用示例。 由于频繁的代码更新,可能会更改版本控制和部署值。
INFO:root:Started Retrieving the Schematic logs
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 992
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): us.schematics.cloud.ibm.com:443
DEBUG:urllib3.connectionpool:https://us.schematics.cloud.ibm.com:443
"GET /v1/workspaces/us-east.workspace.sunil-myworkspace-
may12.2e0a560f/actions/6242ef71d4003bdae4a7ed7a3cbb0887 HTTP/1.1" 200 None
{"action_id": "a11223334b11224345",
"name": "PLAN",
"status": "COMPLETED",
"message": [],
"performed_by": "user@us.ibm.com",
"performed_at": "2019-08-21T14:07:25.814722573Z","templates": [
{"template_id": "a1234b-2124",
"template_type": "terraform_v0.12",
"start_time": "2019-08-21T14:07:26.120106199Z",
"end_time": "2019-08-21T14:07:30.088495607Z",
"status": "COMPLETED",
"message": "{"messagekey":"M2001_ActivitySuccessful","parms":{},
"requestid":"1234b1234b123-1234n13","timestamp":"2019-08-21T14:07:30.088498532Z"}",
"log_url": "https://schematics.cloud.ibm.com/v1/workspaces/myworkspace-123456/ runtime_data/
a1234b-2124/log_store/actions/11223334b11224345"
}
]
}
INFO:root:Completed Retrieving the Schematic logs