本文档介绍如何查看预留。
准备工作
- 查看预留的要求和限制。
-
如果您尚未设置身份验证,请进行设置。身份验证是通过其进行身份验证以访问 Google Cloud 服务和 API 的过程。如需从本地开发环境运行代码或示例,您可以按如下方式向 Compute Engine 进行身份验证。
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
安装 Google Cloud CLI,然后通过运行以下命令初始化 Google Cloud CLI:
gcloud init
- Set a default region and zone.
-
项目的
compute.reservations.list
权限(查看预留列表) -
项目的
compute.reservations.get
权限(查看预留的详细信息) FILTER_EXPRESSION
:过滤表达式。PROJECT_ID
:预留所在项目的 ID。PROJECT_ID
:预留所在项目的 ID。ZONE
:预留所在的可用区。PROJECT_ID
:预留所在项目的 ID。ZONE
:预留所在的可用区。FILTER_EXPRESSION
:过滤表达式。在 Google Cloud 控制台中,转到预留页面。
随即会出现预留页面。
在名称列中,点击要描述的预留的名称。
随即会显示预留的详情页面。如需确定预留的利用率,请参阅预留机器总数和使用的机器数字段。
RESERVATION_NAME
:现有预留的名称。PROJECT_ID
:预留所在项目的 ID。ZONE
:预留所在的可用区。PROJECT_ID
:预留所在项目的 ID。ZONE
:预留所在的可用区。RESERVATION_NAME
:现有预留的名称。
REST
如需在本地开发环境中使用本页面上的 REST API 示例,请使用您提供给 gcloud CLI 的凭据。
如需了解详情,请参阅 Google Cloud 身份验证文档中的使用 REST 时进行身份验证。
所需的角色
如需获得查看预留所需的权限,请让您的管理员向您授予项目的 Compute Admin (
roles/compute.admin
) IAM 角色。如需详细了解如何授予角色,请参阅管理访问权限。此预定义角色包含查看预留所需的权限。如需查看所需的确切权限,请展开所需权限部分:
所需权限
如需查看预留,您需要具备以下权限:
查看预留
您只能查看当前项目中创建的预留。
只有所有者项目才能查看共享预留。如需查看共享预留与之共享的项目,请查看预留的详细信息。
查看预留列表
如需查看预留列表,请使用 Google Cloud 控制台、gcloud CLI 或 REST。
控制台
在 Google Cloud 控制台中,转到预留页面。
随即会出现预留页面。
在表中,每行描述一个预留,每列描述一个属性。例如,已用机器列描述每个预留的利用率和总容量:值
25 (50)
表示 50 个虚拟机的预留,其中 25 个虚拟机已使用。可选:如需修改显示的预留和属性,请分别使用
过滤条件和 列显示选项。gcloud
如需查看预留列表,请使用
gcloud compute reservations list
命令。gcloud compute reservations list \ --project=PROJECT_ID
将
PROJECT_ID
替换为预留所在的项目的 ID。输出应类似于以下示例:
NAME: r-01 IN_USE_COUNT: 0 COUNT: 5 ZONE: us-central1-a SHARE_TYPE: LOCAL NAME: r-02 IN_USE_COUNT: 3 COUNT: 10 ZONE: us-central1-f SHARE_TYPE: LOCAL
(可选)如需使用过滤表达式缩小预留列表的范围,请指定
--filter
标志。gcloud compute reservations list \ --filter="FILTER_EXPRESSION" \ --project=PROJECT_ID
替换以下内容:
例如,如需仅查看名称以
prefix
开头且位于可用区us-central1-a
的预留,请运行以下命令:gcloud compute reservations list \ --filter="name~prefix AND zone=us-central1-a" \ --project=example-project
REST
如需查看预留列表,请向
reservations.list
方法发出GET
请求。GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/reservations
替换以下内容:
输出类似于以下示例:
{ "id": "4100668622331754141", "creationTimestamp": "2019-09-27T08:21:14.707-07:00", "selfLink": "https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a/reservations/reservation-05", "zone": "https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a", "name": "reservation-05", "specificReservation": { "instanceProperties": { "machineType": "n1-standard-2", "minCpuPlatform": "Any CPU Platform", }, "count": "100", "inUseCount": "0" }, "specificReservationRequired": false, "status": "READY", "kind": "compute#reservation" }, { "id": "2533514314332214789", "creationTimestamp": "2019-09-27T08:21:14.707-07:00", "selfLink": "https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a/reservations/reservation-04", "zone": "https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a", "name": "reservation-04", "specificReservation": { "instanceProperties": { "machineType": "n1-standard-2", "guestAccelerators": [ { "acceleratorType": "nvidia-tesla-t4", "acceleratorCount": 1 } ], "minCpuPlatform": "Any CPU Platform", "localSsds": [ { "diskSizeGb": "375", "interface": "SCSI" } ] }, "count": "50", "inUseCount": "25" }, "specificReservationRequired": false, "status": "READY", "kind": "compute#reservation" }
(可选)如需使用过滤表达式缩小预留列表的范围,请发出以下
GET
请求:GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/reservations?filter=FILTER_EXPRESSION
替换以下内容:
例如,如需仅查看名称以
prefix
开头且位于可用区us-central1-a
的预留,请使用网址编码值发出以下GET
请求:GET https://compute.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/reservations?filter=name%7Eprefix%20AND%20zone=us-central1-a
查看预留详细信息
如需查看预留的详细信息,请使用 Google Cloud 控制台、gcloud CLI 或 REST。
控制台
如需查看预留的详细信息,请执行以下操作:
gcloud
如需查看预留的详细信息,请使用
gcloud compute reservations describe
命令。gcloud compute reservations describe RESERVATION_NAME \ --project=PROJECT_ID \ --zone=ZONE
请替换以下内容:
输出应类似于以下示例:
kind: compute#reservation name: reservation-04 selfLink: https://compute.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a/reservations/reservation-04 specificReservation: count: '50' inUseCount: '25' instanceProperties: guestAccelerators: - acceleratorCount: 1 acceleratorType: nvidia-tesla-t4 localSsds: - diskSizeGb: '375' interface: SCSI machineType: n1-standard-2 minCpuPlatform: Any CPU Platform specificReservationRequired: false status: READY zone: https://compute.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a
如需确定预留的利用率,请查看
count
和inUseCount
字段。在本例中,预留了 50 个虚拟机,总共使用了 25 个虚拟机。REST
如需查看预留的详细信息,请向
reservations.get
方法发出GET
请求。GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/reservations/RESERVATION_NAME
请替换以下内容:
输出应类似于以下示例:
{ "id": "2533514314332214789", "creationTimestamp": "2019-09-27T08:21:14.707-07:00", "selfLink": "https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a/reservations/reservation-04", "zone": "https://www.googleapis.com/compute/v1/projects/my-project/zones/us-centra1-a", "name": "reservation-04", "specificReservationRequired": false, "status": "READY", "kind": "compute#reservation", "specificReservation": { "instanceProperties": { "machineType": "n1-standard-2", "guestAccelerators": [ { "acceleratorType": "nvidia-tesla-t4", "acceleratorCount": 1 } ], "minCpuPlatform": "Any CPU Platform", "localSsds": [ { "diskSizeGb": "375", "interface": "SCSI" } ] }, "count": "50", "inUseCount": "25" } }
如需确定预留的利用率,请查看
count
和inUseCount
字段。在本例中,预留了 50 个虚拟机,总共使用了 25 个虚拟机。后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-06-28。
[{ "type": "thumb-down", "id": "hardToUnderstand", "label":"Hard to understand" },{ "type": "thumb-down", "id": "incorrectInformationOrSampleCode", "label":"Incorrect information or sample code" },{ "type": "thumb-down", "id": "missingTheInformationSamplesINeed", "label":"Missing the information/samples I need" },{ "type": "thumb-down", "id": "translationIssue", "label":"翻译问题" },{ "type": "thumb-down", "id": "otherDown", "label":"其他" }] [{ "type": "thumb-up", "id": "easyToUnderstand", "label":"易于理解" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"解决了我的问题" },{ "type": "thumb-up", "id": "otherUp", "label":"其他" }] -