* Delete a snapshot of a disk. * * @param {string} projectId - Project ID or project number of the Cloud project you want to use. * @param {string} snapshotName - Name of the snapshot to delete.
(projectId, snapshotName)
| 19 | * @param {string} snapshotName - Name of the snapshot to delete. |
| 20 | */ |
| 21 | function main(projectId, snapshotName) { |
| 22 | // [START compute_snapshot_delete] |
| 23 | /** |
| 24 | * TODO(developer): Uncomment and replace these variables before running the sample. |
| 25 | */ |
| 26 | // const projectId = 'YOUR_PROJECT_ID'; |
| 27 | // const snapshotName = 'YOUR_SNAPSHOT_NAME'; |
| 28 | |
| 29 | const compute = require('@google-cloud/compute'); |
| 30 | |
| 31 | async function deleteSnapshot() { |
| 32 | const snapshotsClient = new compute.SnapshotsClient(); |
| 33 | |
| 34 | const [response] = await snapshotsClient.delete({ |
| 35 | project: projectId, |
| 36 | snapshot: snapshotName, |
| 37 | }); |
| 38 | let operation = response.latestResponse; |
| 39 | const operationsClient = new compute.GlobalOperationsClient(); |
| 40 | |
| 41 | // Wait for the create disk operation to complete. |
| 42 | while (operation.status !== 'DONE') { |
| 43 | [operation] = await operationsClient.wait({ |
| 44 | operation: operation.name, |
| 45 | project: projectId, |
| 46 | }); |
| 47 | } |
| 48 | |
| 49 | console.log('Snapshot deleted.'); |
| 50 | } |
| 51 | |
| 52 | deleteSnapshot(); |
| 53 | // [END compute_snapshot_delete] |
| 54 | } |
| 55 | |
| 56 | process.on('unhandledRejection', err => { |
| 57 | console.error(err.message); |
no test coverage detected