예약 나열

지정된 프로젝트 및 위치 내의 모든 BigQuery 예약을 나열합니다.

코드 샘플

Node.js

이 샘플을 사용해 보기 전에 BigQuery 빠른 시작: 클라이언트 라이브러리 사용Node.js 설정 안내를 따르세요. 자세한 내용은 BigQuery Node.js API 참고 문서를 확인하세요.

BigQuery에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 클라이언트 라이브러리의 인증 설정을 참조하세요.

const {ReservationServiceClient} =
  require('@google-cloud/bigquery-reservation').v1;
const {status} = require('@grpc/grpc-js');

const client = new ReservationServiceClient();

/**
 * Lists all reservations for the project in the specified location.
 *
 * A reservation provides computational resource guarantees, in the form of
 * slots, to users.
 *
 * @param {string} projectId Google Cloud project ID. for example 'example-project-id'
 * @param {string} location Google Cloud location. for example 'us-central1'
 */
async function listReservations(projectId, location = 'us-central1') {
  const request = {
    parent: `projects/${projectId}/locations/${location}`,
  };

  try {
    const [reservations] = await client.listReservations(request);

    if (reservations.length === 0) {
      console.log(
        `No reservations found in project ${projectId} in location ${location}.`,
      );
      return;
    }

    console.log(
      `Reservations in project ${projectId} in location ${location}:`,
    );
    for (const reservation of reservations) {
      console.log(`- Reservation: ${reservation.name}`);
      console.log(`  Slot capacity: ${reservation.slotCapacity}`);
      console.log(`  Ignore idle slots: ${reservation.ignoreIdleSlots}`);
    }
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.log(`Project or location not found: ${request.parent}`);
    } else {
      console.error('An error occurred while listing reservations:', err);
    }
  }
}

Python

이 샘플을 사용해 보기 전에 BigQuery 빠른 시작: 클라이언트 라이브러리 사용Python 설정 안내를 따르세요. 자세한 내용은 BigQuery Python API 참고 문서를 확인하세요.

BigQuery에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 클라이언트 라이브러리의 인증 설정을 참조하세요.

from google.api_core import exceptions
from google.cloud import bigquery_reservation_v1

client = bigquery_reservation_v1.ReservationServiceClient()


def list_reservations(project_id: str, location: str):
    """Lists all reservations for a project and location.

    A reservation provides computational resource guarantees, in the form of
    slots, to users. This sample shows how to list existing reservations
    within a specific project and location.

    Args:
        project_id: The Google Cloud project ID.
        location: The geographic location of the reservations, for example, us-central1.
    """

    parent = f"projects/{project_id}/locations/{location}"

    try:
        print(f"Listing reservations for parent: '{parent}':")
        for reservation in client.list_reservations(parent=parent):
            print(f"\tReservation: {reservation.name}")
            print(f"\tSlot capacity: {reservation.slot_capacity}")

        print("Finished listing reservations.")
    except exceptions.NotFound:
        print(
            f"Parent resource '{parent}' was not found. Please check your project ID and location."
        )

다음 단계

다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저를 참조하세요.