IBM Cloud Docs
リソースの再利用の使用

リソースの再利用の使用

IBM Cloud® CLI または IBM Cloud® Resource Controller API を使用して、特定のリソースの再利用プロセスを管理できます。 詳しくは、 リソースに関するFAQ をご覧ください

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® Resource Controller 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® Resource Controller 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 を使用したリソースの復元

You can restore a resource within 7 days after you delete it.

すべてのリソースが復元可能とは限りません。 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 を使用したリソースの復元

You can restore a resource within 7 days after you delete it.

すべてのリソースが復元可能とは限りません。 すべての再利用のリストを取得して、復元できるリソースを確認します。

API を使用してリソースを復元するには、以下の例のように IBM Cloud® Resource Controller 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))