本文說明如何查看刊登位置政策。
查看刊登位置政策有助於瞭解專案中的所有現有刊登位置政策,或驗證特定刊登位置政策的設定詳細資料。
事前準備
-
如果尚未設定驗證,請先完成設定。
驗證可確認您的身分,以便存取 Google Cloud 服務和 API。如要從本機開發環境執行程式碼或範例,可以選取下列任一選項,向 Compute Engine 進行驗證:
Select the tab for how you plan to use the samples on this page:
gcloud
-
安裝 Google Cloud CLI。 安裝完成後,執行下列指令初始化 Google Cloud CLI:
gcloud init
如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI。
- Set a default region and zone.
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
安裝 Google Cloud CLI。 安裝完成後,執行下列指令初始化 Google Cloud CLI:
gcloud init
如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI。
詳情請參閱 Google Cloud 驗證說明文件中的「Authenticate for using REST」。
必要的角色
如要取得查看放置群組政策所需的權限,請要求管理員授予您專案的 Compute 執行個體管理員 (v1) (
roles/compute.instanceAdmin.v1
) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。這個預先定義的角色具備查看配置政策所需的權限。如要查看確切的必要權限,請展開「必要權限」部分:
所需權限
如要查看刊登位置政策,必須具備下列權限:
-
如要查看刊登位置政策清單,請按照下列步驟操作:
compute.resourcePolicies.list
on the project -
如要查看刊登位置政策的詳細資料:
compute.resourcePolicies.get
on the project
查看刊登位置政策
如要查看專案中可用的配置政策,請選取本文所述的下列其中一種方法:
如要查看專案中的所有現有刊登位置政策,請查看刊登位置政策清單。
如要查看刊登位置政策的設定詳細資料,請查看刊登位置政策的詳細資料。
查看刊登位置政策清單
如要查看專案中的所有刊登位置政策清單,請選取下列其中一個選項:
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*
更改下列內容:
PROJECT_ID
:專案 ID,用於查看刊登位置政策清單。REGION
:一或多個刊登位置政策所在的區域。
輸出結果會與下列內容相似:
{ "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
更改下列內容:
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
REST
如要查看刊登位置政策的詳細資料,請對
resourcePolicies.get
方法發出GET
要求。GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/resourcePolicies/POLICY_NAME
更改下列內容:
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 位置。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-09-04 (世界標準時間)。
-