使用資源收回

您可以使用 IBM Cloud® CLI 或 IBM Cloud® 資源控制器 API 來管理特定資源的收回處理程序。 如需詳細資訊,請參閱 有關資源的常見問題

使用 CLI 列出收回的資源

若要列出可使用 CLI 還原或刪除的收回資源,請執行下列指令:

ibmcloud resource reclamations [--resource-instance-id INSTANCE_ID]

輸入下列指令選項:

  • --resource-instance-id: 資源實例的廣域唯一 ID (GUID)。

下列範例顯示如何列出特定服務實例的收回:

ibmcloud resource reclamations --resource-instance-id abcd1234-ef56-486e-b293-22d6c7eb6699

使用 API 列出收回的資源

若要列出可還原或刪除的已收回資源,請呼叫 IBM Cloud® 資源控制器 API,如下列範例所示:

使用 ListReclamationsOptions.Builder 來建立 ListReclamationsOptions 物件,其中包含 listReclamations 方法的參數值。

實例化 ListReclamationsOptions 結構並設定欄位,以提供 ListReclamations 方法的參數值。

curl -X GET https://resource-controller.cloud.ibm.com/v1/reclamations?account_id=b80a8b513ae24e178438b7a18bd8d609 -H 'Authorization: Bearer <IAM_TOKEN>'
ListReclamationsOptions listReclamationsOptions = new ListReclamationsOptions.Builder()
  .accountId(accountId)
  .build();

Response<ReclamationsList> response = service.listReclamations(listReclamationsOptions).execute();
ReclamationsList reclamationsList = response.getResult();

System.out.printf("listReclamations() response:\n%s\n", reclamationsList.toString());
const params = {
  accountId: accountId,
};

resourceControllerService.listReclamations(params)
  .then(res => {
    var resources = res.result.resources;
    resources.forEach(reclaim => {
      if (reclaim.resource_instance_id.toString() === instanceGuid) {
        reclamationId = reclaim.id;
      }
    });
    console.log('listReclamations() response:\n' + JSON.stringify(res.result, null, 2));
  })
  .catch(err => {
    console.warn(err)
  });
reclamations_list = resource_controller_service.list_reclamations(
    account_id=account_id
).get_result()

print('\nlist_reclamations() response:\n',
      json.dumps(reclamations_list, indent=2))
listReclamationsOptions := resourceControllerService.NewListReclamationsOptions()
listReclamationsOptions = listReclamationsOptions.SetAccountID(accountID)
reclamationsList, response, err := resourceControllerService.ListReclamations(listReclamationsOptions)
if err != nil {
  panic(err)
}
b, _ := json.MarshalIndent(reclamationsList, "", "  ")
fmt.Printf("\nListReclamations() response:\n%s\n", string(b))

使用 CLI 刪除收回的資源

若要使用 CLI 刪除已回收的資源,請執行下列指令:

ibmcloud resource reclamation-delete ID [--comment COMMENT] [--f, --force]

輸入下列指令選項:

  • ID: 資源收回的 ID。 這是收回 ID,而不是資源實例 ID。 (必要)。
  • -- comment: 動作的相關註解。
    • f, --force: 不經確認強制刪除。

下列範例顯示如何刪除 ID 為 d9fendfwlw 的資源收回:

ibmcloud resource reclamation-delete "d9fendfwlw"

下列範例顯示如何刪除 ID 為 d9fendfwlw 的資源收回,並留下 no longer needed 的註解而不確認:

ibmcloud resource reclamation-delete "d9fendfwlw" --comment "no longer needed" -f

使用 API 刪除資源

若要收回 (暫時刪除) 資源,請呼叫 IBM Cloud® 資源控制器 API,如下列範例所示。 指定 reclaim 以刪除資源。id 是收回 ID,而不是資源實例 ID。

curl -X POST https://resource-controller.cloud.ibm.com/v1/reclamations/0114be9024c6eede47d08a85ac0c5c43/actions/reclaim -H 'Authorization: Bearer <IAM_TOKEN>' -H 'Content-Type: application/json' -d '{
    "request_by": "bar",
    "comment": "reclaim resource instance 614fc866-1d4f-4c9e-973e-637f1089a6a1"
  }'
RunReclamationActionOptions runReclamationActionOptions = new RunReclamationActionOptions.Builder()
  .id(reclamationId)
  .actionName("reclaim")
  .build();

Response<Reclamation> response = service.runReclamationAction(runReclamationActionOptions).execute();
Reclamation reclamation = response.getResult();

System.out.printf("runReclamationAction() response:\n%s\n", reclamation.toString());
const params = {
  id: reclamationId,
  actionName: 'reclaim',
};

resourceControllerService.runReclamationAction(params)
  .then(res => {
    console.log('runReclamationAction() response:\n' + JSON.stringify(res.result, null, 2));
  })
  .catch(err => {
    console.warn(err)
  });
reclamation = resource_controller_service.run_reclamation_action(
    id=reclamation_id,
    action_name='reclaim'
).get_result()

print('\nrun_reclamation_action() response:\n',
      json.dumps(reclamation, indent=2))
runReclamationActionOptions := resourceControllerService.NewRunReclamationActionOptions(
  reclamationID,
  "reclaim",
)

reclamation, response, err := resourceControllerService.RunReclamationAction(runReclamationActionOptions)
if err != nil {
  panic(err)
}
b, _ := json.MarshalIndent(reclamation, "", "  ")
fmt.Printf("\nRunReclamationAction() response:\n%s\n", string(b))

使用 CLI 還原資源

資源通常可在刪除後 3 天內還原。 不過,還原期限可能會因服務而異,因為每個服務都遵循自己的保留政策。 如需詳細資訊,請參閱個別服務的文件。

並非所有資源都可以還原。 您可以執行 ibmcloud resource reclamations 指令來檢查可以還原的資源。

若要使用 CLI 還原資源,請執行下列指令:

ibmcloud resource reclamation-restore ID [--comment COMMENT]

輸入下列指令選項:

  • ID: 資源收回的 ID。 這是收回 ID,而不是資源實例 ID。  (必要)
  • -- comment: 動作的相關註解。

下列範例顯示如何還原具有 d9fendfwlw ID 的資源:

ibmcloud resource reclamation-restore "d9fendfwlw"

如需相關資訊,請參閱 ibmcloud resource reclamations 指令參考手冊。

使用 API 還原資源

資源通常可在刪除後 3 天內還原。 不過,還原期限可能會因服務而異,因為每個服務都遵循自己的保留政策。 如需詳細資訊,請參閱個別服務的文件。

並非所有資源都可以還原。 取得所有收回的清單,以檢查您可以還原的資源。

若要使用 API 來還原資源,請呼叫 IBM Cloud® 資源控制器 API,如下列範例所示。 指定 restore 以還原資源。id 是收回 ID,而不是資源實例 ID。

curl -X POST https://resource-controller.cloud.ibm.com/v1/reclamations/0114be9024c6eede47d08a85ac0c5c43/actions/restore -H 'Authorization: Bearer <IAM_TOKEN>' -H 'Content-Type: application/json' -d '{
    "request_by": "bar",
    "comment": "restore resource instance 614fc866-1d4f-4c9e-973e-637f1089a6a1"
  }'
RunReclamationActionOptions runReclamationActionOptions = new RunReclamationActionOptions.Builder()
  .id(reclamationId)
  .actionName("restore")
  .build();

Response<Reclamation> response = service.runReclamationAction(runReclamationActionOptions).execute();
Reclamation reclamation = response.getResult();

System.out.printf("runReclamationAction() response:\n%s\n", reclamation.toString());
const params = {
  id: reclamationId,
  actionName: 'restore',
};

resourceControllerService.runReclamationAction(params)
  .then(res => {
    console.log('runReclamationAction() response:\n' + JSON.stringify(res.result, null, 2));
  })
  .catch(err => {
    console.warn(err)
  });
reclamation = resource_controller_service.run_reclamation_action(
    id=reclamation_id,
    action_name='restore'
).get_result()

print('\nrun_reclamation_action() response:\n',
      json.dumps(reclamation, indent=2))
runReclamationActionOptions := resourceControllerService.NewRunReclamationActionOptions(
  reclamationID,
  "restore",
)

reclamation, response, err := resourceControllerService.RunReclamationAction(runReclamationActionOptions)
if err != nil {
  panic(err)
}
b, _ := json.MarshalIndent(reclamation, "", "  ")
fmt.Printf("\nRunReclamationAction() response:\n%s\n", string(b))