本文档介绍了如何查看布置政策。
查看布置政策对于查看项目中的所有现有布置政策或验证特定布置政策的配置详细信息很有用。
准备工作
-
设置身份验证(如果尚未设置)。身份验证是通过其进行身份验证以访问 Google Cloud 服务和 API 的过程。如需从本地开发环境运行代码或示例,您可以按如下方式向 Compute Engine 进行身份验证。
Select the tab for how you plan to use the samples on this page:
gcloud
-
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
- 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" }
了解如何替换、移除或删除布置政策。
了解如何应用布置政策:
了解如何验证使用紧凑布置政策的虚拟机的位置。
REST
如需在本地开发环境中使用本页面上的 REST API 示例,请使用您提供给 gcloud CLI 的凭据。
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
如需了解详情,请参阅 Google Cloud 身份验证文档中的使用 REST 时进行身份验证。
所需的角色
如需获得查看布置政策所需的权限,请让您的管理员为您授予项目的 Compute Instance Admin (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
替换以下内容:
输出类似于以下内容:
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-11-25。
-