申请试用

删除工作空间


销毁所有关联的 VPC 资源后,如果不再需要该工作空间,那么还可以删除 Schematics 工作空间。


1、使用 UI 删除工作空间

(1)在 Schematics > Workspaces 页面上的 IBM Cloud 控制台中,选择 操作> 删除工作空间 以删除 schematics 工作空间。

(2)通过在文本框中输入工作空间名称来确认操作,然后单击 删除工作空间

 

2、使用 CLI 删除工作空间

运行以下命令以删除工作空间:

ibmcloud schematics workspace delete --id <WORKSPACE_ID> 

 

    请注意:您可以监视日志文件以查看工作空间的删除进度。

 

3、使用 API 删除工作空间

(1)要使用 IBM Cloud Schematics Python API 删除工作空间,请创建 Python 文件并提供您选择的名称,例如 schematics_delete_workspace.py。


(2)将 使用 Schematics Python API 示例请求复制并粘贴到 Python 文件中。


(3)在请求中更改以下参数:

  ·将 IBM Cloud 密钥替换为 authenticator = IAMAuthenticator('') 变量。

  ·根据您希望 Schematics 工作空间驻留的位置 (例如 schematics_service.set_service_url('https://us.schematics.cloud.ibm.com')) ,将 API 端点更改为 API 端点 中提到的端点。


(4)在 schematics_service.delete_workspace 函数中,提供以下参数:

  ·提供在 创建工作空间 任务中生成的工作空间标识,例如 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

      ·: 如果要破坏资源以及删除工作空间,请将 destroy_resources 参数值设置为 True。 在这种情况下,将首先删除资源,然后删除工作空间。

  ·: 如果要删除工作空间但不删除资源,请完全除去 destroy_resources 参数或将 destroy_resources 参数设置为 False。 如果已删除资源,并且 destroy_resources 参数值设置为 True,那么 RESOURCE DELETE 操作将处于 FAILED 状态。


(5)使用 python3来运行 Python 脚本以删除工作空间。


(6)如果作为请求的一部分传递的参数有效,那么您将获得状态 Started Deleting Schematic Workspace 和 Completed Deleting Schematic Workspace 作为响应。 您应该能够看到工作空间已在您创建的 Schematics 中删除。 如果未获得成功响应,那么错误响应包含需要解决的错误。 请解决这些错误并运行脚本,直到您能够获取有效响应并删除工作空间为止。


示例 Python 请求

# Delete a workspace using Schematics Python API

import json, logging
from ibm_schematics.schematics_v1 import SchematicsV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

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 Deleting Schematic Workspace")

workspace_delete_response = schematics_service.delete_workspace(
    w_id='<workspace id>',
    refresh_token='<refresh-token>',
    destroy_resources= True,
).get_result()print(json.dumps(workspace_delete_response, indent=2))

logging.info("Completed Deleting Schematic Workspace")


示例 Python 响应

INFO:root:Started Deleting Schematic Workspace
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 987
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): us.schematics.cloud.ibm.com:443
DEBUG:urllib3.connectionpool:https://us.schematics.cloud.ibm.com:443 "
DELETE /v1/workspaces/us-south.workspace.Schematic-Sunil-Test-Workspace.5a4cbf11?destroy_
resources=true HTTP/1.1" 200 2
""

INFO:root:Completed Deleting Schematic Workspace