MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

compute/reservations/deleteReservation.js:17–58  ·  view source on GitHub ↗
(reservationName)

Source from the content-addressed store, hash-verified

15 */
16'use strict';
17async function main(reservationName) {
18 // [START compute_reservation_delete]
19 // Import the Compute library
20 const computeLib = require('@google-cloud/compute');
21 // Instantiate a reservationsClient
22 const reservationsClient = new computeLib.ReservationsClient();
23 // Instantiate a zoneOperationsClient
24 const zoneOperationsClient = new computeLib.ZoneOperationsClient();
25 /**
26 * TODO(developer): Update/uncomment these variables before running the sample.
27 */
28 // The ID of the project where your reservation is located.
29 const projectId = await reservationsClient.getProjectId();
30 // The zone where your reservation is located.
31 const zone = 'us-central1-a';
32 // The name of the reservation to delete.
33 // reservationName = 'reservation-01';
34
35 async function callDeleteReservation() {
36 // Delete the reservation
37 const [response] = await reservationsClient.delete({
38 project: projectId,
39 reservation: reservationName,
40 zone,
41 });
42
43 let operation = response.latestResponse;
44
45 // Wait for the delete reservation operation to complete.
46 while (operation.status !== 'DONE') {
47 [operation] = await zoneOperationsClient.wait({
48 operation: operation.name,
49 project: projectId,
50 zone: operation.zone.split('/').pop(),
51 });
52 }
53
54 console.log(`Reservation: ${reservationName} deleted.`);
55 }
56 await callDeleteReservation();
57 // [END compute_reservation_delete]
58}
59main(...process.argv.slice(2)).catch(err => {
60 console.error(err);
61 process.exitCode = 1;

Callers 1

Calls 2

callDeleteReservationFunction · 0.85
getProjectIdMethod · 0.80

Tested by

no test coverage detected