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

Function main

compute/snapshots/deleteSnapshot.js:21–54  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

19 * @param {string} snapshotName - Name of the snapshot to delete.
20 */
21function 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
56process.on('unhandledRejection', err => {
57 console.error(err.message);

Callers 1

deleteSnapshot.jsFile · 0.70

Calls 1

deleteSnapshotFunction · 0.85

Tested by

no test coverage detected