本文件說明如何查看刊登位置政策。
查看刊登位置政策可讓您查看專案中所有現有的刊登位置政策,或驗證特定刊登位置政策的設定詳細資料。
事前準備
-
如果尚未設定,請先設定驗證機制。「驗證」是指驗證身分,以便存取 Google Cloud 服務和 API 的程序。如要從本機開發環境執行程式碼或範例,請選取下列任一選項,以便對 Compute Engine 進行驗證:
Select the tab for how you plan to use the samples on this page:
gcloud
-
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
- Set a default region and zone.
-
如要查看刊登位置政策清單,請按照下列步驟操作:
compute.resourcePolicies.list
on the project -
如要查看刊登位置政策的詳細資料,請按照下列步驟操作:
compute.resourcePolicies.get
on the project 如要查看專案中所有現有的刊登位置政策,請查看刊登位置政策清單。
如要查看刊登位置政策的設定詳細資料,請查看刊登位置政策的詳細資料。
PROJECT_ID
:您要查看刊登位置政策清單的專案 ID。REGION
:一或多個刊登位置政策所在的區域。POLICY_NAME
:現有刊登位置政策的名稱。REGION
:刊登位置政策所在的區域。如果您正在查看密集配置政策的詳細資料,請按照下列步驟操作:
creationTimestamp: '2024-05-09T02:09:24.588-07:00' groupPlacementPolicy: collocation: COLLOCATED id: '5587673659722509355' kind: compute#resourcePolicy name: example-compact-policy region: https://www.googleapis.com/compute/v1/projects/example-project/regions/us-central1 selfLink: https://www.googleapis.com/compute/v1/projects/example-project/regions/us-central1/resourcePolicies/example-compact-policy status: READY
如果您查看的是廣告刊登位置政策的詳細資料,請按照下列步驟操作:
creationTimestamp: '2024-05-09T02:08:13.404-07:00' groupPlacementPolicy: availabilityDomainCount: 5 id: '5970772604948130963' kind: compute#resourcePolicy name: example-spread-policy region: https://www.googleapis.com/compute/v1/projects/example-project/regions/us-central1 selfLink: https://www.googleapis.com/compute/v1/projects/example-project/regions/us-central1/resourcePolicies/example-spread-policy status: READY
PROJECT_ID
:您要查看詳細資料的刊登位置政策所在專案的 ID。REGION
:刊登位置政策所在的區域。POLICY_NAME
:現有刊登位置政策的名稱。如果您正在查看密集配置政策的詳細資料,請按照下列步驟操作:
{ "kind": "compute#resourcePolicy", "id": "5587673659722509355", "creationTimestamp": "2024-05-09T02:09:24.588-07:00", "selfLink": "https://www.googleapis.com/compute/v1/projects/example-project/regions/us-central1/resourcePolicies/example-compact-policy", "region": "https://www.googleapis.com/compute/v1/projects/example-project/regions/us-central1", "name": "example-compact-policy", "groupPlacementPolicy": { "collocation": "COLLOCATED" }, "status": "READY" }
如果您查看的是廣告刊登位置政策的詳細資料,請按照下列步驟操作:
{ "kind": "compute#resourcePolicy", "id": "5970772604948130963", "creationTimestamp": "2024-05-09T02:08:13.404-07:00", "selfLink": "https://www.googleapis.com/compute/v1/projects/example-project/regions/us-central1/resourcePolicies/example-spread-policy", "region": "https://www.googleapis.com/compute/v1/projects/example-project/regions/us-central1", "name": "example-spread-policy", "groupPlacementPolicy": { "availabilityDomainCount": 5 }, "status": "READY" }
瞭解如何取代、移除或刪除刊登位置政策。
瞭解如何套用刊登位置政策:
瞭解如何驗證使用密集配置政策的 VM 位置。
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
詳情請參閱 Google Cloud 驗證說明文件中的「驗證以使用 REST」。
必要的角色
如要取得查看刊登位置政策所需的權限,請要求管理員為您授予專案的 Compute 執行個體管理員 (v1) (
roles/compute.instanceAdmin.v1
) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。這個預先定義的角色具備查看刊登位置政策所需的權限。如要查看確切的必要權限,請展開「必要權限」部分:
所需權限
您必須具備下列權限,才能查看刊登位置政策:
查看刊登位置政策
如要查看專案中可用的刊登位置政策,請選取本文所述的下列其中一種方法:
查看刊登位置政策清單
如要查看專案中所有刊登位置政策的清單,請選取下列任一選項:
gcloud
如要查看刊登位置政策清單,請使用
gcloud compute resource-policies list
指令,並將--filter
標記設為groupPlacementPolicy:*
。gcloud compute resource-policies list \ --filter="groupPlacementPolicy:*"
輸出結果會與下列內容相似:
NAME: example-compact-policy DESCRIPTION: REGION: https://www.googleapis.com/compute/v1/projects/example-project/regions/us-central1 CREATION_TIMESTAMP: 2024-05-09T02:09:24.588-07:00 NAME: example-spread-policy DESCRIPTION: REGION: https://www.googleapis.com/compute/v1/projects/example-project/regions/us-central1 CREATION_TIMESTAMP: 2024-05-09T02:08:13.404-07:00
如要進一步瞭解如何使用篩選運算式縮小 Compute Engine 資源清單的範圍,請參閱
gcloud topic filters
指令。REST
如要查看特定地區的刊登位置政策清單,請對
resourcePolicies.list
方法發出GET
要求。在要求網址中加入filter
查詢參數,並將其設為groupPlacementPolicy%3A*
。GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/resourcePolicies?filter=groupPlacementPolicy%3A*
更改下列內容:
輸出結果會與下列內容相似:
{ "kind": "compute#resourcePolicyList", "id": "projects/example-project/regions/us-central1/resourcePolicies", "items": [ { "kind": "compute#resourcePolicy", "id": "5587673659722509355", "creationTimestamp": "2024-05-09T02:09:24.588-07:00", "selfLink": "https://www.googleapis.com/compute/v1/projects/example-project/regions/us-central1/resourcePolicies/example-compact-policy", "region": "https://www.googleapis.com/compute/v1/projects/example-project/regions/us-central1", "name": "example-compact-policy", "groupPlacementPolicy": { "collocation": "COLLOCATED" }, "status": "READY" }, { "kind": "compute#resourcePolicy", "id": "5970772604948130963", "creationTimestamp": "2024-05-09T02:08:13.404-07:00", "selfLink": "https://www.googleapis.com/compute/v1/projects/example-project/regions/us-central1/resourcePolicies/example-spread-policy", "region": "https://www.googleapis.com/compute/v1/projects/example-project/regions/us-central1", "name": "example-spread-policy", "groupPlacementPolicy": { "availabilityDomainCount": 5 }, "status": "READY" } ], "selfLink": "https://www.googleapis.com/compute/v1/projects/example-project/regions/us-central1/resourcePolicies", "etag": "-L7XCupTQ5V9__TOJ8G5RDcR2cY=/g_xt0udkOM_tU7jSL0z9I2Sivis=" }
如要進一步瞭解如何使用篩選運算式,透過網址編碼功能縮小資源政策清單的範圍,請參閱
filter
查詢參數。查看刊登位置政策的詳細資料
如要查看刊登位置政策的詳細資料,請選取下列任一選項:
gcloud
如要查看刊登位置政策的詳細資料,請使用
gcloud compute resource-policies describe
指令。gcloud compute resource-policies describe POLICY_NAME \ --region=REGION
更改下列內容:
輸出結果會與下列內容相似:
REST
如要查看刊登位置政策的詳細資料,請對
resourcePolicies.get
方法發出GET
要求。GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/resourcePolicies/POLICY_NAME
更改下列內容:
輸出結果會與下列內容相似:
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-06-16 (世界標準時間)。
-