VM インスタンスと他の Compute Engine リソースの関係を表示するには、listReferrers
REST API メソッドを使用します。
REST を使用すると、Compute Engine は次の事項を記述する参照リストを返します。
- ソースリソース: ターゲット リソースをポイントするリソース。
- ターゲット リソース: 目的のリソース。
- 参照タイプ: 2 つのリソース間の関係。
たとえば、REST を使用して、VM インスタンスが属するインスタンス グループのリストを簡単に表示できます。
始める前に
-
まだ設定していない場合は、認証を設定します。認証とは、 Trusted Cloud by S3NS サービスと API にアクセスするために ID を確認するプロセスです。ローカル開発環境からコードまたはサンプルを実行するには、次のいずれかのオプションを選択して Compute Engine に対する認証を行います。
このページの REST API サンプルをローカル開発環境で使用するには、gcloud CLI に指定した認証情報を使用します。
After installing the Google Cloud CLI, sign in to the gcloud CLI with your federated identity and then initialize it by running the following command:
gcloud init
詳細については、 Trusted Cloud 認証ドキュメントの REST を使用して認証するをご覧ください。
制限事項
- 一覧表示できるのは、VM インスタンスとインスタンス グループ(マネージドと非マネージドの両方)の関係のみです。
- リファラーを一覧表示するには REST を使用する必要があります。
単一のリファラーの一覧表示
リファラーは、他のリソースを参照するリソースです。VM インスタンスの場合、インスタンス グループは共通のリファラーになります。
たとえば、ゾーン us-central1-a
に example-ig-a1
という名前の VM インスタンスがあるとします。次の図に示すように、VM インスタンスは同じゾーン内の example-ig
というインスタンス グループのメンバーです。
この関係を確認するには、次の HTTP リクエストで example-ig-a1
の listReferrers
メソッドを呼び出します。
GET https://compute.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances/example-ig-a1/referrers
サーバーが次の項目を含む標準のリスト レスポンスを返します。
"items": [
{
"target": https://compute.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances/example-ig-a1,
"referenceType": MEMBER_OF,
"referrer": https://compute.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instanceGroups/example-ig
}
]
この場合、target
は example-ig-a1
であり、referrer
、example-ig instance
グループの MEMBER_OF
です。
複数のリファラーを一覧表示する
リソースに複数のリファラーがある場合、レスポンスでターゲット リソースのすべてのリファラーのリストが返されます。インスタンスが 2 つのインスタンス グループに属している場合、レスポンスには両方のインスタンス グループが含まれます。
たとえば、次のレスポンスは、example-instance-a2
という名前のインスタンスが example-ig
と example-ig-2
の 2 つのインスタンス グループに属していることを示しています。
"items": [
{
"target": https://compute.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances/example-instance-a2,
"referenceType": MEMBER_OF,
"referrer": https://compute.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instanceGroups/example-ig
},
{
"target": https://compute.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances/example-instance-a2,
"referenceType": MEMBER_OF,
"referrer": https://compute.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instanceGroups/example-ig-2
}
]
クロススコープのリファラーを一覧表示する
listReferrers
メソッドは、他のリージョンやゾーンなど、別のスコープ内に存在するリファラーに関する情報も返します。たとえば、リージョン マネージド インスタンス グループ(リージョン MIG)に属する VM インスタンスがあるとします。
このインスタンスをターゲットとして、次の HTTP リクエストで listReferrers
メソッドを呼び出します。
GET https://compute.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances/new-instance-a3/referrers
サーバーが次の項目を含む標準のリスト レスポンスを返します。
"items": [
{
"target": https://compute.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances/new-instance-a3,
"referenceType": MEMBER_OF,
"referrer": https://compute.googleapis.com/compute/v1/projects/myproject/regions/us-central1/instanceGroups/example-rmig
}
]
レスポンスは、リージョン インスタンス グループをリファラーのリストに示します。
コレクション内のすべてのリソースに対するリファラーを一覧表示する
ワイルドカード文字(-
)を使用すると、特定のゾーン内の、すべての VM インスタンスに対するすべてのリファラーのリストをリクエストできます。このリストは、次のような HTTP リクエストで取得できます。
GET https://compute.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances/-/referrers
ゾーン内の VM インスタンスとインスタンスの参照のリストを含むレスポンスがサーバーから返されます。次に例を示します。
"items": [
{
"target": https://compute.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances/example-ig-a1,
"referenceType": MEMBER_OF,
"referrer": https://compute.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instanceGroups/example-ig
},
{
"target": https://compute.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances/example-ig-a2,
"referenceType": MEMBER_OF,
"referrer": https://compute.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instanceGroups/example-ig
},
{
"target": https://compute.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances/example-ig-a2,
"referenceType": MEMBER_OF,
"referrer": https://compute.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instanceGroups/example-ig-2
},
{
"target": https://compute.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances/new-instance-a3,
"referenceType": MEMBER_OF,
"referrer": https://compute.googleapis.com/compute/v1/projects/myproject/regions/us-central1/instanceGroups/example-rmig
}
]
次のステップ
- インスタンス グループの詳細を確認する。
- 使用可能なゾーンとリージョンのリストを確認する。