Reservierungsgruppe abrufen

Ruft eine bestimmte Ressource für die Reservierungsgruppe aus der BigQuery Reservation API anhand ihres Namens ab.

Codebeispiel

Node.js

Bevor Sie dieses Beispiel anwenden, folgen Sie den Schritten zur Einrichtung von Node.js in der BigQuery-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Angaben finden Sie in der Referenzdokumentation zur BigQuery Node.js API.

Richten Sie zur Authentifizierung bei BigQuery die Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für Clientbibliotheken einrichten.

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

const client = new ReservationServiceClient();

/**
 * Gets the specified reservation group.
 *
 * A reservation group is a container for reservations.
 *
 * @param projectId Google Cloud Project ID, for example 'example-project-id'.
 * @param location Google Cloud Location, for example 'us-central1'.
 * @param reservationGroupId the ID of the reservation group to get, for example 'example-reservation-group-id'.
 */
async function getReservationGroup(
  projectId,
  location = 'us-central1',
  reservationGroupId = 'example-group-reservation',
) {
  const request = {
    name: client.reservationGroupPath(projectId, location, reservationGroupId),
  };

  try {
    const [reservationGroup] = await client.getReservationGroup(request);
    console.log(`Got reservation group: ${reservationGroup.name}`);
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.log(
        `Reservation group '${reservationGroupId}' not found in project '${projectId}' at location '${location}'.`,
      );
    } else {
      console.error(
        `Error getting reservation group '${reservationGroupId}':`,
        err,
      );
    }
  }
}

Python

Bevor Sie dieses Beispiel ausprobieren, folgen Sie der Python-Einrichtungsanleitung in der BigQuery-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Angaben finden Sie in der Referenzdokumentation zur BigQuery Python API.

Richten Sie zur Authentifizierung bei BigQuery die Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für Clientbibliotheken einrichten.

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


client = bigquery_reservation_v1.ReservationServiceClient()


def get_reservation_group(project_id: str, location: str, reservation_group_id: str):
    """Gets information about a reservation group.

    A reservation group is a container for reservations.

    Args:
        project_id: The Google Cloud project ID.
        location: The geographic location of the reservation group, for example, us-central1.
        reservation_group_id: The ID of the reservation group to retrieve.
    """
    name = client.reservation_group_path(project_id, location, reservation_group_id)

    try:
        reservation_group = client.get_reservation_group(name=name)
        print(f"Retrieved reservation group: {reservation_group.name}")
    except exceptions.NotFound:
        print(f"Reservation group '{name}' not found.")

Weitere Informationen

Wenn Sie nach Codebeispielen für andere Produkte von Google Cloud suchen und filtern möchten, können Sie den Beispielbrowser fürGoogle Cloud verwenden.