VM インスタンスのリファラーの表示


VM インスタンスと他の Compute Engine リソースの関係を表示するには、listReferrers API メソッドを使用します。

この API を使用すると、Compute Engine は次の事項を説明する参照リストを返します。

  • ソースリソース: ターゲット リソースをポイントするリソース。
  • ターゲット リソース: 目的のリソース。
  • 参照タイプ: 2 つのリソース間の関係。

たとえば、この API を使用して、VM インスタンスが属するインスタンス グループのリストを簡単に表示できます。

始める前に

制限事項

  • 一覧表示できるのは、VM インスタンスとインスタンス グループ(マネージドと非マネージドの両方)の関係のみです。
  • リファラーを一覧表示するには、API を使用する必要があります。

単一のリファラーの一覧表示

リファラーは、他のリソースを参照するリソースです。VM インスタンスの場合、インスタンス グループは共通のリファラーになります。

たとえば、ゾーン us-central1-aexample-ig-a1 という名前の VM インスタンスがあるとします。次の図に示すように、VM インスタンスは同じゾーン内の example-ig というインスタンス グループのメンバーです。

仮想マシン インスタンスは、同じゾーン内のインスタンス グループのメンバーです。

この関係を確認するには、次の HTTP リクエストで example-ig-a1listReferrers メソッドを呼び出します。

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
  }
]

この場合、targetexample-ig-a1 であり、referrerexample-ig instance グループの MEMBER_OF です。

複数のリファラーを一覧表示する

リソースに複数のリファラーがある場合、レスポンスでターゲット リソースのすべてのリファラーのリストが返されます。インスタンスが 2 つのインスタンス グループに属している場合、レスポンスには両方のインスタンス グループが含まれます。

仮想マシン インスタンスが 2 つのインスタンス グループのメンバーである場合、レスポンスには両方のインスタンス グループが含まれます。

たとえば、次のレスポンスは、example-instance-a2 という名前のインスタンスが example-igexample-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 インスタンスがあるとします。

リージョン us-central1 で、ゾーン us-central1-a のインスタンス new-instance-a3 は、example-rmig リージョン インスタンス グループのメンバーです。

このインスタンスをターゲットとして、次の 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
  }
]

次のステップ