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

Function getStaleStoragePools

compute/test/util.js:151–180  ·  view source on GitHub ↗

* Get storage pools created more than one hour ago.

(prefix)

Source from the content-addressed store, hash-verified

149 * Get storage pools created more than one hour ago.
150 */
151async function getStaleStoragePools(prefix) {
152 const projectId = await storagePoolsClient.getProjectId();
153 const result = [];
154 const currentDate = new Date();
155 currentDate.setHours(currentDate.getHours() - 1);
156
157 const aggListRequest = storagePoolsClient.aggregatedListAsync({
158 project: projectId,
159 });
160
161 for await (const [zone, storagePoolsObject] of aggListRequest) {
162 const storagePools = storagePoolsObject.storagePools;
163 result.push(
164 ...storagePools
165 .filter(
166 storagePool =>
167 new Date(storagePool.creationTimestamp) < currentDate &&
168 storagePool.name.startsWith(prefix)
169 )
170 .map(storagePool => {
171 return {
172 zone: zone.split('zones/')[1],
173 storagePoolName: storagePool.name,
174 timestamp: storagePool.creationTimestamp,
175 };
176 })
177 );
178 }
179 return result;
180}
181
182async function deleteStoragePool(zone, storagePoolName) {
183 const projectId = await storagePoolsClient.getProjectId();

Calls 1

getProjectIdMethod · 0.80

Tested by

no test coverage detected