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

Function getStaleReservations

compute/test/util.js:91–121  ·  view source on GitHub ↗

* Get reservations created more than one hour ago.

(prefix)

Source from the content-addressed store, hash-verified

89 * Get reservations created more than one hour ago.
90 */
91async function getStaleReservations(prefix) {
92 const projectId = await reservationsClient.getProjectId();
93 const result = [];
94 const currentDate = new Date();
95 currentDate.setHours(currentDate.getHours() - 1);
96
97 const aggListRequest = reservationsClient.aggregatedListAsync({
98 project: projectId,
99 });
100
101 for await (const [zone, reservationsObject] of aggListRequest) {
102 const reservations = reservationsObject.reservations;
103 result.push(
104 ...reservations
105 .filter(
106 reservation =>
107 new Date(reservation.creationTimestamp) < currentDate &&
108 reservation.name.startsWith(prefix)
109 )
110 .map(reservation => {
111 return {
112 zone: zone.split('zones/')[1],
113 reservationName: reservation.name,
114 timestamp: reservation.creationTimestamp,
115 };
116 })
117 );
118 }
119
120 return result;
121}
122
123async function deleteReservation(zone, reservationName) {
124 const projectId = await reservationsClient.getProjectId();

Calls 1

getProjectIdMethod · 0.80

Tested by

no test coverage detected