查看刊登位置政策

本文說明如何查看刊登位置政策。

查看刊登位置政策有助於瞭解專案中的所有現有刊登位置政策,或驗證特定刊登位置政策的設定詳細資料。

事前準備

  • 如果尚未設定驗證,請先完成設定。 「驗證」是指驗證身分的程序,確認您有權存取 Trusted Cloud by S3NS 服務和 API。如要從本機開發環境執行程式碼或範例,請選取下列任一選項,向 Compute Engine 進行驗證:

    Select the tab for how you plan to use the samples on this page:

    gcloud

    1. 安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。 登入後,執行下列指令初始化 Google Cloud CLI:

      gcloud init
    2. Set a default region and zone.

    REST

    如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。

      安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。 登入後,執行下列指令初始化 Google Cloud CLI:

      gcloud init

    詳情請參閱 Trusted 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"
    }
    

後續步驟