查看预留或未来预留请求


本文档介绍了如何查看您的预留或未来预留请求。如需详细了解不同类型的预留,请参阅选择预留类型

查看预留或未来预留请求时,您可以执行以下操作:

  • 查看预留设置。此检查可帮助您验证预留的详细信息,确保预留符合您的需求,并规划容量。

  • 确定可使用实例的数量。此检查可帮助您确定有多少 Compute Engine 实例可以使用您的预留容量。

限制

您只能在创建共享预留或共享未来预留请求的项目中查看相应预留或请求。

准备工作

  • 如果您尚未设置身份验证,请进行设置。身份验证是通过其进行身份验证以访问 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

    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.
    3. Go

      如需在本地开发环境中使用本页面上的 Go 示例,请安装并初始化 gcloud CLI,然后使用您的用户凭证设置应用默认凭证。

      1. Install the Google Cloud CLI.

      2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

      3. To initialize the gcloud CLI, run the following command:

        gcloud init
      4. 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.

        If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

      5. 如需了解详情,请参阅 Set up authentication for a local development environment。 如需了解详情,请参阅身份验证文档中的为本地开发环境设置 ADC

      Java

      如需在本地开发环境中使用本页面上的 Java 示例,请安装并初始化 gcloud CLI,然后使用您的用户凭证设置应用默认凭证。

      1. Install the Google Cloud CLI.

      2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

      3. To initialize the gcloud CLI, run the following command:

        gcloud init
      4. 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.

        If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

      5. 如需了解详情,请参阅 Set up authentication for a local development environment。 如需了解详情,请参阅身份验证文档中的为本地开发环境设置 ADC

      Node.js

      如需在本地开发环境中使用本页面上的 Node.js 示例,请安装并初始化 gcloud CLI,然后使用您的用户凭证设置应用默认凭证。

      1. Install the Google Cloud CLI.

      2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

      3. To initialize the gcloud CLI, run the following command:

        gcloud init
      4. 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.

        If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

      5. 如需了解详情,请参阅 Set up authentication for a local development environment。 如需了解详情,请参阅身份验证文档中的为本地开发环境设置 ADC

      Python

      如需在本地开发环境中使用本页面上的 Python 示例,请安装并初始化 gcloud CLI,然后使用您的用户凭证设置应用默认凭证。

      1. Install the Google Cloud CLI.

      2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

      3. To initialize the gcloud CLI, run the following command:

        gcloud init
      4. 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.

        If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

      5. 如需了解详情,请参阅 Set up authentication for a local development environment。 如需了解详情,请参阅身份验证文档中的为本地开发环境设置 ADC

      REST

      如需在本地开发环境中使用本页面上的 REST API 示例,请使用您提供给 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.

      如需了解详情,请参阅 Google Cloud 身份验证文档中的使用 REST 时进行身份验证

所需的角色

如需获得查看预留或未来预留请求所需的权限,请让您的管理员为您授予项目的 Compute Admin (roles/compute.admin) IAM 角色。如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限

此预定义角色包含查看预留或未来预留请求所需的权限。如需查看所需的确切权限,请展开所需权限部分:

所需权限

您需要具备以下权限才能查看预留或未来预留请求:

  • 项目的 compute.reservations.list 权限(查看预留列表)
  • 项目的 compute.futureReservations.list 权限(查看未来预留请求列表)
  • 项目的 compute.reservations.get 权限(查看预留的详细信息)
  • 项目的 compute.futureReservations.get 权限(查看未来预留请求的详细信息)

您也可以使用自定义角色或其他预定义角色来获取这些权限。

查看预留设置

以下部分介绍了如何查看预留或未来预留请求的设置。

查看预留

如需查看一个或多个预留的设置,请使用本部分中所述的以下方法之一:

  • 如需简要了解项目中的所有预留,请查看预留列表。

  • 如需查看单个预留的完整详细信息,请查看该预留的详细信息。

如需查看预留中的 deleteAtTimereservationSharingPolicy 字段(预览版),请使用 Google Cloud CLI 查看预留的详细信息,或使用 REST API 查看预留。如果您不需要这些字段,请选择以下任一选项来查看预留:

控制台

  1. 在 Google Cloud 控制台中,前往预留页面。

    转到“预留”

    按需预留标签页(默认)上,表会列出每个预留,表中的每一列会描述一个属性。

  2. 可选:在按需预留表中,执行以下一项或两项操作:

    • 如需显示预留的保证数量,请点击 列显示选项...,选中保证数量复选框,然后点击确定

    • 如需优化预留列表,请在 过滤条件字段中选择要用于过滤预留的属性。

  3. 如需查看某个预留的详细信息,请在名称列中点击相应预留的名称。系统会打开一个显示相应预留详细信息的页面。

gcloud

  • 如需查看预留列表,请使用 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 替换为过滤表达式。

  • 如需查看预留的详细信息,请使用 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
    

Go

  • 如需查看预留列表,请使用以下代码示例:

    // Copyright 2024 Google LLC
    //
    // Licensed under the Apache License, Version 2.0 (the "License");
    // you may not use this file except in compliance with the License.
    // You may obtain a copy of the License at
    //
    //     https://www.apache.org/licenses/LICENSE-2.0
    //
    // Unless required by applicable law or agreed to in writing, software
    // distributed under the License is distributed on an "AS IS" BASIS,
    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    // See the License for the specific language governing permissions and
    // limitations under the License.
    
    package snippets
    
    import (
    	"context"
    	"fmt"
    	"io"
    
    	compute "cloud.google.com/go/compute/apiv1"
    	computepb "cloud.google.com/go/compute/apiv1/computepb"
    	"google.golang.org/api/iterator"
    )
    
    // Get list of reservations for given project in particular zone
    func listReservations(w io.Writer, projectID, zone string) error {
    	// projectID := "your_project_id"
    	// zone := "us-west3-a"
    
    	ctx := context.Background()
    	reservationsClient, err := compute.NewReservationsRESTClient(ctx)
    	if err != nil {
    		return err
    	}
    	defer reservationsClient.Close()
    
    	req := &computepb.ListReservationsRequest{
    		Project: projectID,
    		Zone:    zone,
    	}
    
    	it := reservationsClient.List(ctx, req)
    	fmt.Fprintf(w, "Instances found in zone %s:\n", zone)
    	for {
    		instance, err := it.Next()
    		if err == iterator.Done {
    			break
    		}
    		if err != nil {
    			return err
    		}
    		fmt.Fprintf(w, "- %s %d\n", instance.GetName(), instance.GetSpecificReservation().GetCount())
    	}
    
    	return nil
    }
    
    
  • 如需查看预留的详细信息,请使用以下代码示例:

    // Copyright 2024 Google LLC
    //
    // Licensed under the Apache License, Version 2.0 (the "License");
    // you may not use this file except in compliance with the License.
    // You may obtain a copy of the License at
    //
    //     https://www.apache.org/licenses/LICENSE-2.0
    //
    // Unless required by applicable law or agreed to in writing, software
    // distributed under the License is distributed on an "AS IS" BASIS,
    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    // See the License for the specific language governing permissions and
    // limitations under the License.
    
    package snippets
    
    import (
    	"context"
    	"fmt"
    	"io"
    
    	compute "cloud.google.com/go/compute/apiv1"
    	computepb "cloud.google.com/go/compute/apiv1/computepb"
    )
    
    // Get certain reservation for given project and zone
    func getReservation(w io.Writer, projectID, zone, reservationName string) (*computepb.Reservation, error) {
    	// projectID := "your_project_id"
    	// zone := "us-west3-a"
    	// reservationName := "your_reservation_name"
    
    	ctx := context.Background()
    	reservationsClient, err := compute.NewReservationsRESTClient(ctx)
    	if err != nil {
    		return nil, err
    	}
    	defer reservationsClient.Close()
    
    	req := &computepb.GetReservationRequest{
    		Project:     projectID,
    		Reservation: reservationName,
    		Zone:        zone,
    	}
    
    	reservation, err := reservationsClient.Get(ctx, req)
    	if err != nil {
    		return nil, fmt.Errorf("unable to delete reservation: %w", err)
    	}
    
    	fmt.Fprintf(w, "Reservation: %s\n", reservation.GetName())
    
    	return reservation, nil
    }
    
    

Java

  • 如需查看预留列表,请使用以下代码示例:

    /*
     * Copyright 2024 Google LLC
     *
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     *   http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     */
    
    package compute.reservation;
    
    import com.google.cloud.compute.v1.Reservation;
    import com.google.cloud.compute.v1.ReservationsClient;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.List;
    
    public class ListReservations {
    
      public static void main(String[] args) throws IOException {
        // TODO(developer): Replace these variables before running the sample.
        // Project ID or project number of the Cloud project you want to use.
        String project = "YOUR_PROJECT_ID";
        // Zone in which reservations are located.
        String zone = "us-central1-a";
    
        listReservations(project, zone);
      }
    
      // List all reservations in the given project and zone.
      public static List<Reservation> listReservations(String project, String zone) throws IOException {
        // Initialize client that will be used to send requests. This client only needs to be created
        // once, and can be reused for multiple requests.
        List<Reservation> listOfReservations = new ArrayList<>();
    
        try (ReservationsClient reservationsClient = ReservationsClient.create()) {
          for (Reservation reservation : reservationsClient.list(project, zone).iterateAll()) {
            listOfReservations.add(reservation);
            System.out.println("Reservation: " + reservation.getName());
          }
        }
        return listOfReservations;
      }
    }
  • 如需查看预留的详细信息,请使用以下代码示例:

    /*
     * Copyright 2024 Google LLC
     *
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     * http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     */
    
    package compute.reservation;
    
    import com.google.cloud.compute.v1.Reservation;
    import com.google.cloud.compute.v1.ReservationsClient;
    import java.io.IOException;
    import java.util.concurrent.ExecutionException;
    import java.util.concurrent.TimeoutException;
    
    public class GetReservation {
    
      public static void main(String[] args)
          throws IOException, ExecutionException, InterruptedException, TimeoutException {
        // TODO(developer): Replace these variables before running the sample.
        // Project ID or project number of the Cloud project you want to use.
        String projectId = "YOUR_PROJECT_ID";
        // Name of the zone in which you want to create the reservation.
        String zone = "us-central1-a";
        // Name of the reservation you want to create.
        String reservationName = "test-reservation-name";
    
        getReservation(projectId, reservationName, zone);
      }
    
      // Retrieve a reservation with the given name in the given zone.
      public static Reservation getReservation(
          String projectId, String reservationName, String zone)
          throws IOException {
        // Initialize client that will be used to send requests. This client only needs to be created
        // once, and can be reused for multiple requests.
        try (ReservationsClient reservationsClient = ReservationsClient.create()) {
    
          // Get the reservation.
          Reservation reservation = reservationsClient.get(projectId, zone, reservationName);
    
          System.out.println("Reservation: " + reservation.getName());
          return reservation;
        }
      }
    }

Node.js

  • 如需查看预留列表,请使用以下代码示例:

    /*
     * Copyright 2024 Google LLC
     *
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     *     https://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     */
    
    'use strict';
    
    async function main() {
      // Import the Compute library
      const computeLib = require('@google-cloud/compute');
    
      // Instantiate a reservationsClient
      const reservationsClient = new computeLib.ReservationsClient();
    
      /**
       * TODO(developer): Update these variables before running the sample.
       */
      // The ID of the project where your reservations are located.
      const projectId = await reservationsClient.getProjectId();
      // The zone where your reservations are located.
      const zone = 'us-central1-a';
    
      async function callGetReservations() {
        const reservations = (
          await reservationsClient.list({
            project: projectId,
            zone,
          })
        )[0];
    
        console.log(JSON.stringify(reservations));
      }
    
      await callGetReservations();
    }
    
    main().catch(err => {
      console.error(err);
      process.exitCode = 1;
    });
    
  • 如需查看预留的详细信息,请使用以下代码示例:

    /*
     * Copyright 2024 Google LLC
     *
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     *     https://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     */
    
    'use strict';
    
    async function main(reservationName) {
      // Import the Compute library
      const computeLib = require('@google-cloud/compute');
    
      // Instantiate a reservationsClient
      const reservationsClient = new computeLib.ReservationsClient();
    
      /**
       * TODO(developer): Update/uncomment these variables before running the sample.
       */
      // The ID of the project where your reservation is located.
      const projectId = await reservationsClient.getProjectId();
      // The zone where your reservation is located.
      const zone = 'us-central1-a';
      // The name of the reservation to return.
      // reservationName = 'reservation-01';
    
      async function callGetReservation() {
        const requestedReservation = (
          await reservationsClient.get({
            project: projectId,
            zone,
            reservation: reservationName,
          })
        )[0];
    
        console.log(JSON.stringify(requestedReservation));
      }
    
      await callGetReservation();
    }
    
    main(...process.argv.slice(2)).catch(err => {
      console.error(err);
      process.exitCode = 1;
    });
    

Python

  • 如需查看预留列表,请使用以下代码示例:

    # Copyright 2024 Google LLC
    #
    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    # You may obtain a copy of the License at
    #
    #    https://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.
    
    
    # This file is automatically generated. Please do not modify it directly.
    # Find the relevant recipe file in the samples/recipes or samples/ingredients
    # directory and apply your changes there.
    
    
    from google.cloud import compute_v1
    from google.cloud.compute_v1.services.reservations.pagers import ListPager
    
    
    def list_compute_reservation(project_id: str, zone: str = "us-central1-a") -> ListPager:
        """
        Lists all compute reservations in a specified Google Cloud project and zone.
        Args:
            project_id (str): The ID of the Google Cloud project.
            zone (str): The zone of the reservations.
        Returns:
            ListPager: A pager object containing the list of reservations.
        """
    
        client = compute_v1.ReservationsClient()
    
        reservations_list = client.list(
            project=project_id,
            zone=zone,
        )
    
        for reservation in reservations_list:
            print("Name: ", reservation.name)
            print(
                "Machine type: ",
                reservation.specific_reservation.instance_properties.machine_type,
            )
        # Example response:
        # Name:  my-reservation_1
        # Machine type:  n1-standard-1
        # Name:  my-reservation_2
        # Machine type:  n1-standard-1
    
        return reservations_list
    
    
    
  • 如需查看预留的详细信息,请使用以下代码示例:

    # Copyright 2024 Google LLC
    #
    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    # You may obtain a copy of the License at
    #
    #    https://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.
    
    
    # This file is automatically generated. Please do not modify it directly.
    # Find the relevant recipe file in the samples/recipes or samples/ingredients
    # directory and apply your changes there.
    
    
    from google.cloud import compute_v1
    from google.cloud.compute_v1.types import compute
    
    
    def get_compute_reservation(
        project_id: str,
        zone: str = "us-central1-a",
        reservation_name="your-reservation-name",
    ) -> compute.Reservation:
        """
        Retrieves a compute reservation from GCP.
        Args:
            project_id (str): The ID of the Google Cloud project.
            zone (str): The zone of the reservation.
            reservation_name (str): The name of the reservation to retrieve.
        Returns:
            compute.Reservation: The reservation object retrieved from Google Cloud.
        """
    
        client = compute_v1.ReservationsClient()
    
        reservation = client.get(
            project=project_id,
            zone=zone,
            reservation=reservation_name,
        )
    
        print("Name: ", reservation.name)
        print("STATUS: ", reservation.status)
        print(reservation.specific_reservation)
        # Example response:
        # Name:  your-reservation-name
        # STATUS:  READY
        # count: 3
        # instance_properties {
        #   machine_type: "n1-standard-1"
        #   local_ssds {
        #     disk_size_gb: 375
        #     interface: "NVME"
        #   }
        # ...
    
        return reservation
    
    
    

REST

  • 如需查看预留列表,请向 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
    

    FILTER_EXPRESSION 替换为使用网址编码值的过滤表达式。

  • 如需查看预留的详细信息,请向 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"
      }
    }
    

查看未来预留请求

如需查看一个或多个未来预留请求的设置,请使用本部分中所述的以下方法之一:

  • 如需简要了解项目中的所有未来预留请求,请查看请求列表。

  • 如需查看单个未来预留请求的完整详细信息,请查看该请求的详细信息。

如需查看未来预留请求,请选择以下选项之一:

控制台

  1. 在 Google Cloud 控制台中,前往预留页面。

    转到“预留”

  2. 点击未来预留标签页。

    表会列出每个未来预留请求,表中的每一列会描述一个属性。

  3. 可选:如需优化请求列表,请在 过滤条件字段中选择要用于过滤请求的属性。

  4. 如需查看某个请求的详细信息,请在名称列中点击相应请求的名称。系统会打开一个显示相应未来预留请求详细信息的页面。

gcloud

  • 如需查看未来预留请求列表,请使用 gcloud beta compute future-reservations list 命令

    gcloud beta compute future-reservations list
    

    输出类似于以下示例:

    NAME: fr-04
    TOTAL_COUNT: 100
    START_TIME: 2025-07-20T07:00:00Z
    END_TIME: 2025-08-05T07:00:00Z
    PROCUREMENT_STATUS: FULFILLED
    ZONE: us-east1-a
    
    NAME: fr-05
    TOTAL_COUNT: 10
    START_TIME: 2025-07-20T07:00:00Z
    END_TIME: 2025-12-01T00:00:00Z
    PROCUREMENT_STATUS: PENDING_APPROVAL
    ZONE: us-west1-c
    

    (可选)如需使用过滤表达式优化未来预留请求列表,请添加 --filter 标志:

    gcloud beta compute future-reservations list \
        --filter="FILTER_EXPRESSION"
    

    FILTER_EXPRESSION 替换为过滤表达式。

  • 如需查看未来预留请求的详细信息,请使用 gcloud beta compute future-reservations describe 命令

    gcloud beta compute future-reservations describe FUTURE_RESERVATION_NAME \
        --zone=ZONE
    

    替换以下内容:

    • FUTURE_RESERVATION_NAME:现有未来预留请求的名称。

    • ZONE:未来预留请求所在的可用区。

    输出类似于以下示例:

    autoCreatedReservationsDeleteTime: '2025-05-02T01:00:00Z'
    creationTimestamp: '2025-03-23T10:08:31.613-07:00'
    id: '5212276518668495076'
    kind: compute#futureReservation
    name: fr-01
    planningStatus: SUBMITTED
    selfLink: https://www.googleapis.com/compute/beta/projects/example-project/zones/us-central1-a/futureReservations/fr-01
    selfLinkWithId: https://www.googleapis.com/compute/beta/projects/example-project/zones/us-central1-a/futureReservations/5212276518668495076
    shareSettings:
      shareType: LOCAL
    specificSkuProperties:
      instanceProperties:
        machineType: n1-standard-64
      totalCount: '800'
    status:
      existingMatchingUsageInfo:
        count: '3'
        timestamp: '2025-03-30T01:00:00Z'
      lockTime: '2025-03-30T17:09:59.297799Z'
      procurementStatus: APPROVED
    timeWindow:
      endTime: '2025-05-02T01:00:00Z'
      startTime: '2025-04-30T17:30:00Z'
    zone: https://www.googleapis.com/compute/beta/projects/example-project/zones/us-central1-a
    

REST

  • 如需查看未来预留请求列表,请向 Beta 版 futureReservations.list 方法发出 GET 请求:

    GET https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/futureReservations
    

    替换以下内容:

    • PROJECT_ID:您在其中创建了未来预留请求的项目的 ID。

    • ZONE:未来预留请求所在的可用区。

    输出类似于以下示例:

    {
      "id": "projects/my-project/zones/us-east1-a/futureReservations",
      "items": [
        {
          "id": "743865190848184978",
          "creationTimestamp": "2025-03-23T18:16:45.274-07:00",
          "selfLink": "https://www.googleapis.com/compute/beta/projects/my-project/zones/us-east1-a/futureReservations/fr-base",
          "selfLinkWithId": "https://www.googleapis.com/compute/beta/projects/my-project/zones/us-east1-a/futureReservations/743865190848184978",
          "zone": "https://www.googleapis.com/compute/beta/projects/my-project/zones/us-east1-a",
          "name": "fr-base",
          "specificSkuProperties": {
            "instanceProperties": {
              "machineType": "n1-standard-1"
            },
            "totalCount": "100"
          },
          "planningStatus": "SUBMITTED",
          "timeWindow": {
            "endTime": "2025-05-02T01:00:00Z",
            "startTime": "2025-04-30T17:30:00Z"
          },
          "status": {
            "procurementStatus": "FULFILLED",
            "lockTime": "2025-03-30T07:00:00Z",
            "existingMatchingUsageInfo": {
              "count": "3",
              "timestamp": "2025-03-30T01:00:00Z"
            }
          },
          "kind": "compute#futureReservation"
        },
        ...
      ],
      "selfLink": "https://www.googleapis.com/compute/beta/projects/my-project/zones/us-east1-a/futureReservations",
      "etag": "AnzKY34l-cvvV-JnniESJ0dtQvQ=/hvc4jaHpxFAZmOt1FVtKNgzZu-M=",
      "kind": "compute#futureReservationsListResponse"
    }
    

    (可选)如需使用过滤表达式优化未来预留请求列表,请添加 filter 查询参数:

    GET https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/aggregated/futureReservations?filter=FILTER_EXPRESSION
    

    FILTER_EXPRESSION 替换为使用网址编码值的过滤表达式。

  • 如需查看未来预留请求的详细信息,请向 Beta 版 futureReservations.get 方法发出 GET 请求。

    GET https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/futureReservations/FUTURE_RESERVATION_NAME
    

    替换以下内容:

    • PROJECT_ID:您在其中创建了未来预留请求的项目的 ID。

    • ZONE:未来预留请求所在的可用区。

    • FUTURE_RESERVATION_NAME:现有未来预留请求的名称。

    输出类似于以下内容:

    {
      "autoCreatedReservationsDeleteTime": "2025-05-02T01:00:00Z",
      "creationTimestamp": "2025-03-23T10:08:31.613-07:00",
      "id": "5212276518668495076",
      "kind": "compute#futureReservation",
      "name": "fr-01",
      "planningStatus": "SUBMITTED",
      "selfLink": "https://www.googleapis.com/compute/beta/projects/example-project/zones/us-central1-a/futureReservations/fr-01",
      "selfLinkWithId": "https://www.googleapis.com/compute/beta/projects/example-project/zones/us-central1-a/futureReservations/5212276518668495076",
      "shareSettings": {
        "shareType": "LOCAL"
      },
      "specificSkuProperties": {
        "instanceProperties": {
          "machineType": "n1-standard-64"
        },
        "totalCount": "800"
      },
      "status": {
        "lockTime": "2025-03-30T17:09:59.297799Z",
        "procurementStatus": "APPROVED",
        "existingMatchingUsageInfo": {
          "count": "3",
          "timestamp": "2025-03-30T01:00:00Z"
        }
      },
      "timeWindow": {
        "endTime": "2025-05-02T01:00:00Z",
        "startTime": "2025-04-30T17:30:00Z"
      },
      "zone": "https://www.googleapis.com/compute/beta/projects/example-project/zones/us-central1-a"
    }
    

确定可使用实例的数量

如需确定可以使用预留容量的计算实例数量,请执行以下操作之一:

预留中的可使用实例

当您查看预留的详细信息时,可以通过查看以下字段来了解有多少个计算实例在使用预留,以及有多少个实例可以使用预留:

  • 保证数量 (assuredCount):在预留的可用区内实际预留的实例数量。此数量包括为您的项目以及将共享预留与之共享的任何项目预留的实例。

  • 总数 (count):预留中指定的预留实例数量。此数量应与保证数量相符。

  • 正在使用的机器数 (inUseCount):您的项目或将共享预留与之共享的项目中正在使用预留的正在运行实例的数量。

例如,如果保证数量 (assuredCount) 和总数 (count) 均为 50,且正在使用预留的实例数量 (inUseCount) 为 25,则在预留完全用完之前,还可以有 25 个实例使用预留。

未来预留请求中的可使用实例

您可以确定 Compute Engine 在未来预留请求开始时间为其创建预留的计算实例数量。对于草稿、待审批或已批准的请求,您可以按以下方式确定此数量:

  1. 查看您的项目以及与之共享请求的任何项目中有多少个正在运行的实例和未使用预留与请求属性匹配。

  2. 从请求中的总数中减去匹配的正在运行实例和未使用预留数量。

您可以一次性确定单个或多个请求的可使用实例数量。对于多个请求,请使用 Google Cloud 控制台或 REST API。对于单个请求,请选择以下任一选项:

控制台

  1. 在 Google Cloud 控制台中,前往预留页面。

    转到“预留”

  2. 点击未来预留标签页。

    表会列出每个未来预留请求,表中的每一列会描述一个属性。

  3. 如需确定 Compute Engine 计划在请求开始时间为请求预留的实例数量,请从总数列中减去匹配计数列。

    匹配计数列会显示以下警告之一:

    • 匹配计数为零:您的项目或与之共享请求的任何项目中没有匹配的正在运行实例或未使用预留。

    • 匹配计数等于总数:Compute Engine 不会在请求开始时间为请求预留任何实例。

    如果您修改请求或是创建与请求匹配的新实例或预留,Compute Engine 会在 30 分钟内更新匹配计数列。

  4. 可选:如需检查匹配计数列在请求中上次更新的时间,请执行以下操作:

    1. 名称列中,点击相应请求的名称。系统会打开一个显示相应未来预留请求详细信息的页面。

    2. 资源详情部分中,检查上次匹配用量评估时间字段。

gcloud

  1. 如需查看未来预留请求的详细信息,请使用 gcloud beta compute future-reservations describe 命令

    gcloud beta compute future-reservations describe FUTURE_RESERVATION_NAME \
        --zone=ZONE
    

    替换以下内容:

    • FUTURE_RESERVATION_NAME:现有未来预留请求的名称。

    • ZONE:未来预留请求所在的可用区。

    在输出中,找到 counttotalCount 字段:

    ...
    specificSkuProperties:
      ...
      totalCount: '100'
    status:
      existingMatchingUsageInfo:
        count: '50'
        timestamp: '2025-03-30T01:00:00Z'
      ...
      procurementStatus: DRAFTING
    ...
    
  2. totalCount 中减去 count 的值。例如,如果 count 为 50,totalCount 为 100,则 Compute Engine 会在请求开始时间自动为 50 个实例创建预留。

    如果您修改请求或是创建与请求匹配的新实例或预留,Compute Engine 会在 30 分钟内更新 existingMatchingUsageInfo 字段。如需验证此字段的上次更新时间,请检查 existingMatchingUsageInfo.timestamp 的值。

REST

  1. 如需查看未来预留请求列表,请向 Beta 版 futureReservations.list 方法发出 GET 请求。在请求网址中添加 filter 查询参数,并指定仅显示 namespecificSkuPropertiesstatus 字段:

    GET https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/futureReservations?fields=items.name,items.specificSkuProperties,items.status
    

    替换以下内容:

    • PROJECT_ID:您在其中创建了未来预留请求的项目的 ID。

    • ZONE:未来预留请求所在的可用区。

    在输出中,找到每个草稿、待审批或已批准请求的 counttotalCount 字段:

    {
      "items": [
        {
          "specificSkuProperties": {
            ...
            totalCount: "100"
          },
          "name": "fr-01",
          "status": {
            "procurementStatus": "APPROVED",
            ...
            existingMatchingUsageInfo: {
              count: "50",
              "timestamp": "2025-01-22T07:54:26.295Z"
            }
          }
        },
        {
          "specificSkuProperties": {
            ...
            totalCount: "20"
          },
          "name": "fr-02",
          "status": {
            "procurementStatus": "DRAFTING",
            ...
            existingMatchingUsageInfo: {
              "count": "2",
              "timestamp": "2025-01-22T07:54:26.295Z"
            }
          }
        }
      ]
    }
    
  2. 对于每个请求,请从 totalCount 中减去 count 的值。例如,如果 count 为 50,totalCount 为 100,则 Compute Engine 会在请求开始时间自动为 50 个实例创建预留。

    如果您修改请求或是创建与请求匹配的新实例或预留,Compute Engine 会在 30 分钟内更新 existingMatchingUsageInfo 字段。如需验证此字段的上次更新时间,请检查 existingMatchingUsageInfo.timestamp 的值。

日历模式下的未来预留请求中的可使用实例

当您查看未来预留请求的详细信息时,可以了解 Compute Engine 计划在请求开始时间预配的计算实例数量。无论您的项目或共享请求的任何项目中有多少个匹配的实例,Compute Engine 都会按照请求中指定的数量创建实例。

后续步骤