本文档介绍如何查看预留。
查看预留有助于大致了解项目中的所有预留或查看预留的配置详情。如果您想查看共享预留,只能使用所有者项目查看。
准备工作
-
如果您尚未设置身份验证,请进行设置。身份验证是通过其进行身份验证以访问 Google Cloud 服务和 API 的过程。如需从本地开发环境运行代码或示例,您可以选择以下任一选项向 Compute Engine 进行身份验证:
Select the tab for how you plan to use the samples on this page:
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
-
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
- Set a default region and zone.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
Terraform
如需在本地开发环境中使用本页面上的 Terraform 示例,请安装并初始化 gcloud CLI,然后使用您的用户凭据设置应用默认凭据。
如需了解详情,请参阅 Set up authentication for a local development environment。
Go
如需在本地开发环境中使用本页面上的 Go 示例,请安装并初始化 gcloud CLI,然后使用您的用户凭据设置应用默认凭据。
如需了解详情,请参阅 Set up authentication for a local development environment。 如需了解详情,请参阅身份验证文档中的为本地开发环境设置 ADC。
Java
如需在本地开发环境中使用本页面上的 Java 示例,请安装并初始化 gcloud CLI,然后使用您的用户凭据设置应用默认凭据。
如需了解详情,请参阅 Set up authentication for a local development environment。 如需了解详情,请参阅身份验证文档中的为本地开发环境设置 ADC。
Node.js
如需在本地开发环境中使用本页面上的 Node.js 示例,请安装并初始化 gcloud CLI,然后使用您的用户凭据设置应用默认凭据。
如需了解详情,请参阅 Set up authentication for a local development environment。 如需了解详情,请参阅身份验证文档中的为本地开发环境设置 ADC。
Python
如需在本地开发环境中使用本页面上的 Python 示例,请安装并初始化 gcloud CLI,然后使用您的用户凭据设置应用默认凭据。
如需了解详情,请参阅 Set up authentication for a local development environment。 如需了解详情,请参阅身份验证文档中的为本地开发环境设置 ADC。
REST
如需在本地开发环境中使用本页面上的 REST API 示例,请使用您提供给 gcloud CLI 的凭据。
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
如需了解详情,请参阅 Google Cloud 身份验证文档中的使用 REST 时进行身份验证。
-
所需的角色
如需获得查看预留所需的权限,请让您的管理员向您授予项目的 Compute Admin (roles/compute.admin
) IAM 角色。如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
此预定义角色包含查看预留所需的权限。如需查看所需的确切权限,请展开所需权限部分:
所需权限
如需查看预留,您需要具备以下权限:
-
项目的
compute.reservations.list
权限(查看预留列表) -
项目的
compute.reservations.get
权限(查看预留的详细信息)
查看预留
如需查看项目中预留的相关信息,请使用以下方法之一:
查看预留列表
如需查看您的预订列表,请选择以下选项之一:
在 Google Cloud 控制台中,前往预订页面。
在按需预留标签页(默认)上,表中每行描述一个预留,每列描述一个房源。
可选:如需修改显示的预留和房源,请分别使用
过滤条件和 列显示选项。
如需查看预留列表,请使用 gcloud compute reservations list
命令。
gcloud compute reservations list
输出应类似于以下示例:
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 "
将 FILTER_EXPRESSION
替换为过滤表达式。
例如,如需仅查看名称以 prefix
开头且位于可用区 us-central1-a
的预留,请运行以下命令:
gcloud compute reservations list \
--filter="name~prefix AND zone=us-central1-a"
如需查看预留列表,请向 reservations.list
方法发出 GET
请求。
GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID /zones/ZONE /reservations
替换以下内容:
PROJECT_ID
:预留所在项目的 ID。ZONE
:预留所在的可用区。
输出类似于以下示例:
{
"kind": "compute#reservation",
"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"
},
"count": "100",
"inUseCount": "0",
"assuredCount": "100"
},
"specificReservationRequired": false,
"status": "READY",
"shareSettings": {
"shareType": "LOCAL"
}
},
{
"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
}
],
"localSsds": [
{
"diskSizeGb": "375",
"interface": "SCSI"
}
]
},
"count": "50",
"inUseCount": "25",
"assuredCount": "50"
},
"specificReservationRequired": false,
"status": "READY",
"shareSettings": {
"shareType": "LOCAL"
}
}
(可选)如需使用过滤表达式缩小预留列表的范围,请添加 filter
查询参数,如下所示:
GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID /zones/ZONE /reservations?filter=FILTER_EXPRESSION
替换以下内容:
PROJECT_ID
:预留所在项目的 ID。ZONE
:预留所在的可用区。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 产品在预留中使用了多少虚拟机,请使用Google Cloud 控制台查看预留的详细信息。否则,请选择以下任一选项:
如需查看预留的详细信息,请使用 gcloud compute reservations describe
命令。
gcloud compute reservations describe RESERVATION_NAME \
--zone=ZONE
替换以下内容:
RESERVATION_NAME
:现有预留的名称。ZONE
:预留所在的可用区。
输出类似于以下内容:
creationTimestamp: '2024-10-11T03:25:23.192-07:00'
id: '4488228526648280060'
kind: compute#reservation
name: r-01
selfLink: https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a/reservations/r-01
shareSettings:
shareType: LOCAL
specificReservation:
assuredCount: '50'
count: '50'
inUseCount: '25'
instanceProperties:
machineType: n2-standard-2
specificReservationRequired: false
status: READY
zone: https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a
如需查看预留的详细信息,请向 reservations.get
方法发出 GET
请求。
GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID /zones/ZONE /reservations/RESERVATION_NAME
替换以下内容:
PROJECT_ID
:预留所在项目的 ID。ZONE
:预留所在的可用区。RESERVATION_NAME
:现有预留的名称。
输出类似于以下内容:
{
"kind": "compute#reservation",
"id": "4488228526648280060",
"creationTimestamp": "2024-10-11T03:25:23.192-07:00",
"selfLink": "https://www.googleapis.com/compute/v1/projects/davide-experimental/zones/us-central1-a/reservations/r-01",
"zone": "https://www.googleapis.com/compute/v1/projects/davide-experimental/zones/us-central1-a",
"name": "r-01",
"specificReservation": {
"instanceProperties": {
"machineType": "n2-standard-2"
},
"count": "50",
"inUseCount": "25",
"assuredCount": "50"
},
"specificReservationRequired": false,
"status": "READY",
"shareSettings": {
"shareType": "LOCAL"
}
}
确定可消耗型虚拟机的数量
查看预留时,您可以通过检查以下字段来确定有多少虚拟机正在使用该预留,以及还可以有多少虚拟机使用该预留:
保证的数量 (
assuredCount
):在预留的可用区中为您的项目以及共享预留的任何项目实际预留的虚拟机数量。总数 (
count
):预留中指定的预留虚拟机数量。此数字应与保证的数量一致。正在使用的机器 (
inUseCount
):您的项目或共享预留的共享对象项目中正在使用预留的正在运行的虚拟机数量。
例如,如果保证数量 (assuredCount
) 和总数量 (count
) 均为 50,并且使用预留的虚拟机数量 (inUseCount
) 为 25,则有 25 个虚拟机正在使用该预留,您可以在该预留完全用尽之前再创建和运行 25 个虚拟机。