本文說明如何查看刊登位置政策。
查看刊登位置政策有助於瞭解專案中的所有現有刊登位置政策,或驗證特定刊登位置政策的設定詳細資料。
事前準備
-
如果尚未設定驗證,請先完成設定。
驗證可確認您的身分,以便存取 Google Cloud 服務和 API。如要從本機開發環境執行程式碼或範例,請選取下列其中一個選項,向 Compute Engine 進行驗證:
選取這個頁面上的分頁,瞭解如何使用範例:
gcloud
-
安裝 Google Cloud CLI。 完成後,執行下列指令來初始化 Google Cloud CLI:
gcloud init若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI。
-
- 設定預設地區和區域。
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
安裝 Google Cloud CLI。
若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI。
詳情請參閱 Google Cloud 驗證說明文件中的「使用 REST 進行驗證」。
必要的角色
如要取得查看放置群組政策所需的權限,請要求系統管理員授予您專案的 Compute 執行個體管理員 (v1) (roles/compute.instanceAdmin.v1) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。
這個預先定義的角色具備查看配置政策所需的權限。如要查看確切的必要權限,請展開「Required permissions」(必要權限) 部分:
所需權限
如要查看刊登位置政策,必須具備下列權限:
-
如要查看配置政策清單:
按一下專案的
compute.resourcePolicies.list -
如要查看刊登位置政策的詳細資料:
compute.resourcePolicies.get專案
查看刊登位置政策
如要查看專案中可用的配置政策,請選取本文所述的下列其中一種方法:
如要查看專案中的所有現有刊登位置政策,請查看刊登位置政策清單。
如要查看刊登位置政策的設定詳細資料,請查看刊登位置政策的詳細資料。
查看刊登位置政策清單
如要查看專案中的所有放置位置政策清單,請選取下列其中一個選項:
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="
}
如要進一步瞭解如何使用篩選運算式,透過 URL 編碼縮小資源政策清單的範圍,請參閱 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 的實際位置。