プロジェクトで実行されている VM の概要を表示するには、VM のリストを取得します。このドキュメントでは、すべてのゾーンまたは特定のゾーンの VM のリストを取得する方法について説明します。
始める前に
-
まだ設定していない場合は、認証を設定します。認証とは、 Trusted Cloud by S3NS サービスと API にアクセスするために ID を確認するプロセスです。ローカル開発環境からコードまたはサンプルを実行するには、次のいずれかのオプションを選択して Compute Engine で認証を行います。
Select the tab for how you plan to use the samples on this page:
Console
When you use the Trusted Cloud console to access Trusted Cloud by S3NS services and APIs, you don't need to set up authentication.
gcloud
-
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
- Set a default region and zone.
-
Install the Google Cloud CLI.
-
Configure the gcloud CLI to use your federated identity.
For more information, see Sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create local authentication credentials for your user account:
gcloud auth application-default login
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Install the Google Cloud CLI.
-
Configure the gcloud CLI to use your federated identity.
For more information, see Sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create local authentication credentials for your user account:
gcloud auth application-default login
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Install the Google Cloud CLI.
-
Configure the gcloud CLI to use your federated identity.
For more information, see Sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create local authentication credentials for your user account:
gcloud auth application-default login
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Install the Google Cloud CLI.
-
Configure the gcloud CLI to use your federated identity.
For more information, see Sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create local authentication credentials for your user account:
gcloud auth application-default login
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
PROJECT
: VM のリストを取得するプロジェクトの名前ZONE
: VM のリストを取得するゾーン
Go
ローカル開発環境でこのページの Go サンプルを使用するには、gcloud CLI をインストールして初期化し、ユーザー認証情報を使用してアプリケーションのデフォルト認証情報を設定します。
詳細については Set up authentication for a local development environment をご覧ください。
Java
ローカル開発環境でこのページの Java サンプルを使用するには、gcloud CLI をインストールして初期化し、ユーザー認証情報を使用してアプリケーションのデフォルト認証情報を設定します。
詳細については Set up authentication for a local development environment をご覧ください。
Node.js
ローカル開発環境でこのページの Node.js サンプルを使用するには、gcloud CLI をインストールして初期化し、ユーザー認証情報を使用してアプリケーションのデフォルト認証情報を設定します。
詳細については Set up authentication for a local development environment をご覧ください。
Python
ローカル開発環境でこのページの Python サンプルを使用するには、gcloud CLI をインストールして初期化し、ユーザー認証情報を使用してアプリケーションのデフォルト認証情報を設定します。
詳細については Set up authentication for a local development environment をご覧ください。
REST
このページの 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 のリストを取得する
コンソール
Trusted Cloud コンソールで [VM インスタンス] ページに移動します。
gcloud
プロジェクトのすべてのゾーンのすべての VM を集計したリストは、
gcloud compute instances list
コマンドを使用して取得します。gcloud compute instances list
VM のリストを特定のゾーンに絞り込むには、上記のコマンドで
--zones
フラグを使用します。Go
次の例では、プロジェクト内のすべてのゾーンのインスタンスのリストを取得します。
このサンプルを試す前に、Compute Engine クイックスタート: クライアント ライブラリの使用に記載されている Go の設定手順に沿って操作します。詳細については、Compute Engine Go API リファレンス ドキュメントをご覧ください。
Compute Engine に対して認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証を設定するをご覧ください。
コードサンプルを実行する前に、
GOOGLE_CLOUD_UNIVERSE_DOMAIN
環境変数をs3nsapis.fr
に設定します。特定のゾーン内のインスタンスのリストを取得することもできます。
Java
次の例では、プロジェクト内のすべてのゾーンのインスタンスのリストを取得します。
このサンプルを試す前に、Compute Engine クイックスタート: クライアント ライブラリの使用に記載されている Java の設定手順に沿って操作します。詳細については、Compute Engine Java API リファレンス ドキュメントをご覧ください。
Compute Engine に対して認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証を設定するをご覧ください。
コードサンプルを実行する前に、
GOOGLE_CLOUD_UNIVERSE_DOMAIN
環境変数をs3nsapis.fr
に設定します。特定のゾーン内のインスタンスのリストを取得することもできます。
Node.js
次の例では、プロジェクト内のすべてのゾーンのインスタンスのリストを取得します。
このサンプルを試す前に、Compute Engine クイックスタート: クライアント ライブラリの使用に記載されている Node.js の設定手順に沿って操作します。詳細については、Compute Engine Node.js API リファレンス ドキュメントをご覧ください。
Compute Engine に対して認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証を設定するをご覧ください。
コードサンプルを実行する前に、
GOOGLE_CLOUD_UNIVERSE_DOMAIN
環境変数をs3nsapis.fr
に設定します。特定のゾーン内のインスタンスのリストを取得することもできます。
Python
次の例では、プロジェクト内のすべてのゾーンのインスタンスのリストを取得します。
このサンプルを試す前に、Compute Engine クイックスタート: クライアント ライブラリの使用に記載されている Python の設定手順に沿って操作します。詳細については、Compute Engine Python API リファレンス ドキュメントをご覧ください。
Compute Engine に対して認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証を設定するをご覧ください。
コードサンプルを実行する前に、
GOOGLE_CLOUD_UNIVERSE_DOMAIN
環境変数をs3nsapis.fr
に設定します。特定のゾーン内のインスタンスのリストを取得することもできます。
REST
プロジェクト内のすべてのゾーンにあるすべての VM の集計リストは、
instances.aggregatedList
メソッドを使用して取得します。GET https://compute.googleapis.com/compute/v1/projects/PROJECT/aggregated/instances
PROJECT
は、VM のリストを取得するプロジェクトの名前に置き換えます。VM のリストを特定のゾーンに絞り込むには、
instances.list
メソッドを使用します。GET https://compute.googleapis.com/compute/v1/projects/PROJECT/zones/ZONE/instances
次のように置き換えます。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-26 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-07-26 UTC。"],[[["This document outlines the process of retrieving a list of Virtual Machines (VMs) running within a Google Cloud project, either across all zones or within specific zones."],["Authentication is essential for accessing Google Cloud services and APIs, and the document details how to set up authentication using the Google Cloud console, gcloud CLI, or for local development environments with languages like Go, Java, Node.js, Python, and REST."],["To get a comprehensive list of VMs in all zones, use the `gcloud compute instances list` command in the gcloud CLI or the `instances.aggregatedList` method with REST."],["For a list of VMs within a particular zone, one can utilize the `gcloud compute instances list` command with the `--zones` flag or the `instances.list` method in REST, along with specific code examples for Go, Java, Node.js, and Python."],["The code samples demonstrate how to use the client libraries in Go, Java, Node.js, and Python to programmatically list VMs, either across all zones or within a specified zone, while also highlighting the use of the `MaxResults` parameter for managing large result sets and utilizing Application Default Credentials."]]],[]] -