* Resets a stopped Google Compute Engine instance (with unencrypted disks). * * @param {string} projectId - project ID or project number of the Cloud project your instance belongs to. * @param {string} zone - name of the zone your instance belongs to. * @param {string} instanceName - name of the
(projectId, zone, instanceName)
| 20 | * @param {string} instanceName - name of the instance your want to reset. |
| 21 | */ |
| 22 | function main(projectId, zone, instanceName) { |
| 23 | // [START compute_reset_instance] |
| 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 instanceName = 'YOUR_INSTANCE_NAME' |
| 30 | |
| 31 | const compute = require('@google-cloud/compute'); |
| 32 | |
| 33 | async function resetInstance() { |
| 34 | const instancesClient = new compute.InstancesClient(); |
| 35 | |
| 36 | const [response] = await instancesClient.reset({ |
| 37 | project: projectId, |
| 38 | zone, |
| 39 | instance: instanceName, |
| 40 | }); |
| 41 | let operation = response.latestResponse; |
| 42 | const operationsClient = new compute.ZoneOperationsClient(); |
| 43 | |
| 44 | // Wait for the 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('Instance reset.'); |
| 54 | } |
| 55 | |
| 56 | resetInstance(); |
| 57 | // [END compute_reset_instance] |
| 58 | } |
| 59 | |
| 60 | main(...process.argv.slice(2)); |
no test coverage detected