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

Function getStaleDisks

compute/test/util.js:210–240  ·  view source on GitHub ↗

* Get storage pools created more than one hour ago.

(prefix)

Source from the content-addressed store, hash-verified

208 * Get storage pools created more than one hour ago.
209 */
210async function getStaleDisks(prefix) {
211 const projectId = await disksClient.getProjectId();
212 const result = [];
213 const currentDate = new Date();
214 currentDate.setHours(currentDate.getHours() - 1);
215
216 const aggListRequest = disksClient.aggregatedListAsync({
217 project: projectId,
218 });
219
220 for await (const [zone, disksObject] of aggListRequest) {
221 const disks = disksObject.disks;
222 result.push(
223 ...disks
224 .filter(
225 disk =>
226 new Date(disk.creationTimestamp) < currentDate &&
227 disk.name.startsWith(prefix)
228 )
229 .map(disk => {
230 return {
231 zone: zone.split('zones/')[1],
232 diskName: disk.name,
233 timestamp: disk.creationTimestamp,
234 };
235 })
236 );
237 }
238
239 return result;
240}
241
242async function deleteDisk(zone, diskName) {
243 const projectId = await disksClient.getProjectId();

Calls 1

getProjectIdMethod · 0.80

Tested by

no test coverage detected