* Deletes a disk from a project. * * @param {string} projectId - Project ID or project number of the Cloud project you want to use. * @param {string} zone - Name of the zone in which is the disk you want to delete. * @param {string} diskName - Name of the disk you want to delete.
(projectId, zone, diskName)
| 20 | * @param {string} diskName - Name of the disk you want to delete. |
| 21 | */ |
| 22 | function main(projectId, zone, diskName) { |
| 23 | // [START compute_disk_delete] |
| 24 | /** |
| 25 | * TODO(developer): Uncomment and replace these variables before running the sample. |
| 26 | */ |
| 27 | // const projectId = 'YOUR_PROJECT_ID'; |
| 28 | // const zone = 'europe-central2-b'; |
| 29 | // const diskName = 'YOUR_DISK_NAME'; |
| 30 | |
| 31 | const compute = require('@google-cloud/compute'); |
| 32 | |
| 33 | async function deleteDisk() { |
| 34 | const disksClient = new compute.DisksClient(); |
| 35 | |
| 36 | const [response] = await disksClient.delete({ |
| 37 | project: projectId, |
| 38 | zone, |
| 39 | disk: diskName, |
| 40 | }); |
| 41 | let operation = response.latestResponse; |
| 42 | const operationsClient = new compute.ZoneOperationsClient(); |
| 43 | |
| 44 | // Wait for the create disk operation to complete. |
| 45 | while (operation.status !== 'DONE') { |
| 46 | [operation] = await operationsClient.wait({ |
| 47 | operation: operation.name, |
| 48 | project: projectId, |
| 49 | zone: operation.zone.split('/').pop(), |
| 50 | }); |
| 51 | } |
| 52 | |
| 53 | console.log('Disk deleted.'); |
| 54 | } |
| 55 | |
| 56 | deleteDisk(); |
| 57 | // [END compute_disk_delete] |
| 58 | } |
| 59 | |
| 60 | process.on('unhandledRejection', err => { |
| 61 | console.error(err.message); |
no test coverage detected