查看刊登位置政策


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

查看刊登位置政策可讓您查看專案中所有現有的刊登位置政策,或驗證特定刊登位置政策的設定詳細資料。

事前準備

  • 如果尚未設定,請先設定驗證機制。驗證是指驗證身分,以便存取 Google Cloud 服務和 API 的程序。如要在本機開發環境中執行程式碼或範例,您可以選取下列任一選項,向 Compute Engine 進行驗證:

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

    gcloud

    1. 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.

    2. Set a default region and zone.

    REST

    To use the REST API samples on this page in a local development environment, you use the credentials you provide to the 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.

    For more information, see Authenticate for using REST in the Google Cloud authentication documentation.

必要的角色

如要取得查看刊登位置政策所需的權限,請要求管理員為您授予專案的 Compute Instance Admin (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"
    }
    

後續步驟