Skip to content

Commit

Permalink
fix: modernize the samples (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Dec 22, 2018
1 parent 2ca3b46 commit e586c4a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
2 changes: 1 addition & 1 deletion packages/google-cloud-compute/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"docs": "jsdoc -c .jsdoc.js",
"generate-scaffolding": "repo-tools generate all && repo-tools generate lib_samples_readme -l samples/ --config ../.cloud-repo-tools.json",
"lint": "eslint '**/*.js'",
"samples-test": "cd samples/ && npm link ../ && cd startup-script && npm link ../../ && cd ../ && npm test && cd ../",
"samples-test": "cd samples/ && npm link ../ && npm test && cd ../",
"system-test": "mocha system-test/*.js --timeout 600000",
"test": "nyc mocha",
"fix": "eslint --fix '**/*.js'"
Expand Down
12 changes: 5 additions & 7 deletions packages/google-cloud-compute/samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@
"node": ">=8"
},
"scripts": {
"system-test": "mocha system-test/*.js --timeout 600000",
"startup-test": "mocha startup-script/system-test/*.test.js --timeout 600000",
"test": "npm run system-test && npm run startup-test"
"test": "mocha --timeout 1200000"
},
"dependencies": {
"node-fetch": "^2.3.0",
"@google-cloud/compute": "^0.11.0",
"googleapis": "^36.0.0",
"nodemailer": "^4.3.1",
"nodemailer-smtp-transport": "^2.7.4",
"sendgrid": "^5.2.3",
"uuid": "^3.2.1"
"sendgrid": "^5.2.3"
},
"devDependencies": {
"chai": "^4.2.0",
"execa": "^1.0.0",
"mocha": "^5.0.0",
"proxyquire": "^2.0.1"
"proxyquire": "^2.0.1",
"uuid": "^3.2.1"
}
}
37 changes: 18 additions & 19 deletions packages/google-cloud-compute/samples/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,31 @@
// See the License for the specific language governing permissions and
// limitations under the License.

/* eslint-disable no-unused-vars */

'use strict';

// [START compute_engine_quickstart]
// Imports the Google Cloud client library
const Compute = require('@google-cloud/compute');
const uuid = require('uuid');
// Creates a client
const compute = new Compute();
async function createVM(
vmName = 'new_virtual_machine' // VM name of your choice
) {
// Imports the Google Cloud client library
const Compute = require('@google-cloud/compute');

// Create a new VM using the latest OS image of your choice.
const zone = compute.zone('us-central1-a');
const name = `ubuntu-http-${uuid().split('-')[0]}`;
// Creates a client
const compute = new Compute();

async function createVM() {
const data = await zone.createVM(name, {os: 'ubuntu'});
// Create a new VM using the latest OS image of your choice.
const zone = compute.zone('us-central1-c');

// `operation` lets you check the status of long-running tasks.
const vm = data[0];
const operation = data[1];
// Start the VM create task
const [vm, operation] = await zone.createVM(vmName, {os: 'ubuntu'});
console.log(vm);

// `operation` lets you check the status of long-running tasks.
await operation.promise();
// Virtual machine created!
}

createVM().catch(console.error);

// Complete!
console.log('Virtual machine created!');
}
// [END compute_engine_quickstart]

createVM(...process.argv.slice(2)).catch(console.error);

0 comments on commit e586c4a

Please sign in to comment.