* Get storage pools created more than one hour ago.
(prefix)
| 149 | * Get storage pools created more than one hour ago. |
| 150 | */ |
| 151 | async 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 | |
| 182 | async function deleteStoragePool(zone, storagePoolName) { |
| 183 | const projectId = await storagePoolsClient.getProjectId(); |
no test coverage detected