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

Function main

compute/startInstance.js:22–58  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

20 * @param {string} instanceName - name of the instance your want to start.
21 */
22function main(projectId, zone, instanceName) {
23 // [START compute_start_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 startInstance() {
34 const instancesClient = new compute.InstancesClient();
35
36 const [response] = await instancesClient.start({
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 started.');
54 }
55
56 startInstance();
57 // [END compute_start_instance]
58}
59
60main(...process.argv.slice(2));

Callers 1

startInstance.jsFile · 0.70

Calls 1

startInstanceFunction · 0.85

Tested by

no test coverage detected