{"action":"created","comment":{"url":"https://api.github.com/repos/googleapis/nodejs-compute/pulls/comments/228584613","pull_request_review_id":168486743,"id":228584613,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyODU4NDYxMw==","diff_hunk":"@@ -16,130 +16,134 @@\n 'use strict';\n \n const Compute = require('@google-cloud/compute');\n-const http = require('http');\n+const axios = require('axios');\n \n const compute = new Compute();\n \n const zone = compute.zone('us-central1-a');\n \n-// callback(error, externalIp)\n-function createVm(name, callback) {\n+async function createVm(name) {\n   // Create a new VM, using default ubuntu image. The startup script\n   // installs apache and a custom homepage.\n-  const config = {\n-    os: 'ubuntu',\n-    http: true,\n-    metadata: {\n-      items: [\n-        {\n-          key: 'startup-script',\n-          value: `#! /bin/bash\n \n-        # Installs apache and a custom homepage\n-        apt-get update\n-        apt-get install -y apache2\n-        cat <<EOF > /var/www/html/index.html\n-        <!doctype html>\n-        <h1>Hello World</h1>\n-        <p>This page was created from a simple start-up script!</p>`,\n-        },\n-      ],\n-    },\n-  };\n+  try {\n+    const config = {\n+      os: 'ubuntu',\n+      http: true,\n+      metadata: {\n+        items: [\n+          {\n+            key: 'startup-script',\n+            value: `#! /bin/bash\n+    \n+            # Installs apache and a custom homepage\n+            apt-get update\n+            apt-get install -y apache2\n+            cat <<EOF > /var/www/html/index.html\n+            <!doctype html>\n+            <h1>Hello World</h1>\n+            <p>This page was created from a simple start-up script!</p>`,\n+          },\n+        ],\n+      },\n+    };\n+    const vm = zone.vm(name);\n+    console.log('Creating VM ...');\n+    const data = await vm.create(config);\n+    await data[1].promise();\n+    const metadata = await vm.getMetadata();\n \n-  const vm = zone.vm(name);\n+    // External IP of the VM.\n+    const ip = metadata[0].networkInterfaces[0].accessConfigs[0].natIP;\n+    console.log(`Booting new VM with IP http://${ip}...`);\n \n-  vm.create(config)\n-    .then(data => {\n-      const operation = data[1];\n-      return operation.promise();\n-    })\n-    .then(() => {\n-      return vm.getMetadata();\n-    })\n-    .then(data => {\n-      const metadata = data[0];\n-\n-      // External IP of the VM.\n-      const ip = metadata.networkInterfaces[0].accessConfigs[0].natIP;\n-      console.log(`Booting new VM with IP http://${ip}...`);\n+    // Ping the VM to determine when the HTTP server is ready.\n+    return await pingVM(ip);\n+  } catch (err) {\n+    console.error(`Something went wrong while creating ${name} :`, err);\n+  }\n+}\n \n-      // Ping the VM to determine when the HTTP server is ready.\n-      let waiting = true;\n-      const timer = setInterval(\n-        ip => {\n-          http\n-            .get('http://' + ip, res => {\n-              const statusCode = res.statusCode;\n-              if (statusCode === 200 && waiting) {\n-                waiting = false;\n-                clearTimeout(timer);\n-                // HTTP server is ready.\n-                console.log('Ready!');\n-                callback(null, ip);\n-              }\n-            })\n-            .on('error', () => {\n-              // HTTP server is not ready yet.\n-              process.stdout.write('.');\n-            });\n-        },\n-        2000,\n-        ip\n-      );\n-    })\n-    .catch(err => callback(err));\n+async function pingVM(ip) {","path":"samples/startup-script/index.js","position":114,"original_position":114,"commit_id":"cd3c1f857a9aca9b2fddd80cb6dc30408f5809e4","original_commit_id":"cd3c1f857a9aca9b2fddd80cb6dc30408f5809e4","user":{"login":"JustinBeckwith","id":534619,"node_id":"MDQ6VXNlcjUzNDYxOQ==","avatar_url":"https://avatars2.githubusercontent.com/u/534619?v=4","gravatar_id":"","url":"https://api.github.com/users/JustinBeckwith","html_url":"https://github.com/JustinBeckwith","followers_url":"https://api.github.com/users/JustinBeckwith/followers","following_url":"https://api.github.com/users/JustinBeckwith/following{/other_user}","gists_url":"https://api.github.com/users/JustinBeckwith/gists{/gist_id}","starred_url":"https://api.github.com/users/JustinBeckwith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JustinBeckwith/subscriptions","organizations_url":"https://api.github.com/users/JustinBeckwith/orgs","repos_url":"https://api.github.com/users/JustinBeckwith/repos","events_url":"https://api.github.com/users/JustinBeckwith/events{/privacy}","received_events_url":"https://api.github.com/users/JustinBeckwith/received_events","type":"User","site_admin":false},"body":"```js\r\nasync function pingVM(ip) {\r\n  while(true) {\r\n    await new Promise(r => setTimeout(r, 2000);\r\n    const res = await axios.get(`http://${ip}`); \r\n    const statusCode = res.status;\r\n    if (statusCode === 200)  \r\n      (the other code or whatever goes here)\r\n      return;\r\n    } else {\r\n        console.log('things');\r\n    }\r\n}","created_at":"2018-10-26T16:11:56Z","updated_at":"2018-10-26T16:13:04Z","html_url":"https://github.com/googleapis/nodejs-compute/pull/183#discussion_r228584613","pull_request_url":"https://api.github.com/repos/googleapis/nodejs-compute/pulls/183","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/googleapis/nodejs-compute/pulls/comments/228584613"},"html":{"href":"https://github.com/googleapis/nodejs-compute/pull/183#discussion_r228584613"},"pull_request":{"href":"https://api.github.com/repos/googleapis/nodejs-compute/pulls/183"}}},"pull_request":{"url":"https://api.github.com/repos/googleapis/nodejs-compute/pulls/183","id":224804414,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI0ODA0NDE0","html_url":"https://github.com/googleapis/nodejs-compute/pull/183","diff_url":"https://github.com/googleapis/nodejs-compute/pull/183.diff","patch_url":"https://github.com/googleapis/nodejs-compute/pull/183.patch","issue_url":"https://api.github.com/repos/googleapis/nodejs-compute/issues/183","number":183,"state":"open","locked":false,"title":"docs(samples): update samples to use async/await and mocha","user":{"login":"muraliQlogic","id":38901089,"node_id":"MDQ6VXNlcjM4OTAxMDg5","avatar_url":"https://avatars1.githubusercontent.com/u/38901089?v=4","gravatar_id":"","url":"https://api.github.com/users/muraliQlogic","html_url":"https://github.com/muraliQlogic","followers_url":"https://api.github.com/users/muraliQlogic/followers","following_url":"https://api.github.com/users/muraliQlogic/following{/other_user}","gists_url":"https://api.github.com/users/muraliQlogic/gists{/gist_id}","starred_url":"https://api.github.com/users/muraliQlogic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/muraliQlogic/subscriptions","organizations_url":"https://api.github.com/users/muraliQlogic/orgs","repos_url":"https://api.github.com/users/muraliQlogic/repos","events_url":"https://api.github.com/users/muraliQlogic/events{/privacy}","received_events_url":"https://api.github.com/users/muraliQlogic/received_events","type":"User","site_admin":false},"body":"Works towards https://github.com/googleapis/google-cloud-node/issues/2865 and https://github.com/googleapis/google-cloud-node/issues/2869 (it's a good idea to open an issue first for discussion)\r\n\r\n- [ ] Tests and linter pass\r\n- [ ] Code coverage does not decrease (if any source code was changed)\r\n- [ ] Appropriate docs were updated (if necessary)\r\n","created_at":"2018-10-22T20:31:14Z","updated_at":"2018-10-26T16:13:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"13caed61a155b81857aa4e7991cf5c39ef40f432","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":738762758,"node_id":"MDU6TGFiZWw3Mzg3NjI3NTg=","url":"https://api.github.com/repos/googleapis/nodejs-compute/labels/cla:%20yes","name":"cla: yes","color":"0B7601","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/googleapis/nodejs-compute/pulls/183/commits","review_comments_url":"https://api.github.com/repos/googleapis/nodejs-compute/pulls/183/comments","review_comment_url":"https://api.github.com/repos/googleapis/nodejs-compute/pulls/comments{/number}","comments_url":"https://api.github.com/repos/googleapis/nodejs-compute/issues/183/comments","statuses_url":"https://api.github.com/repos/googleapis/nodejs-compute/statuses/cd3c1f857a9aca9b2fddd80cb6dc30408f5809e4","head":{"label":"muraliQlogic:Issue-2869","ref":"Issue-2869","sha":"cd3c1f857a9aca9b2fddd80cb6dc30408f5809e4","user":{"login":"muraliQlogic","id":38901089,"node_id":"MDQ6VXNlcjM4OTAxMDg5","avatar_url":"https://avatars1.githubusercontent.com/u/38901089?v=4","gravatar_id":"","url":"https://api.github.com/users/muraliQlogic","html_url":"https://github.com/muraliQlogic","followers_url":"https://api.github.com/users/muraliQlogic/followers","following_url":"https://api.github.com/users/muraliQlogic/following{/other_user}","gists_url":"https://api.github.com/users/muraliQlogic/gists{/gist_id}","starred_url":"https://api.github.com/users/muraliQlogic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/muraliQlogic/subscriptions","organizations_url":"https://api.github.com/users/muraliQlogic/orgs","repos_url":"https://api.github.com/users/muraliQlogic/repos","events_url":"https://api.github.com/users/muraliQlogic/events{/privacy}","received_events_url":"https://api.github.com/users/muraliQlogic/received_events","type":"User","site_admin":false},"repo":{"id":153866132,"node_id":"MDEwOlJlcG9zaXRvcnkxNTM4NjYxMzI=","name":"nodejs-compute","full_name":"muraliQlogic/nodejs-compute","private":false,"owner":{"login":"muraliQlogic","id":38901089,"node_id":"MDQ6VXNlcjM4OTAxMDg5","avatar_url":"https://avatars1.githubusercontent.com/u/38901089?v=4","gravatar_id":"","url":"https://api.github.com/users/muraliQlogic","html_url":"https://github.com/muraliQlogic","followers_url":"https://api.github.com/users/muraliQlogic/followers","following_url":"https://api.github.com/users/muraliQlogic/following{/other_user}","gists_url":"https://api.github.com/users/muraliQlogic/gists{/gist_id}","starred_url":"https://api.github.com/users/muraliQlogic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/muraliQlogic/subscriptions","organizations_url":"https://api.github.com/users/muraliQlogic/orgs","repos_url":"https://api.github.com/users/muraliQlogic/repos","events_url":"https://api.github.com/users/muraliQlogic/events{/privacy}","received_events_url":"https://api.github.com/users/muraliQlogic/received_events","type":"User","site_admin":false},"html_url":"https://github.com/muraliQlogic/nodejs-compute","description":"Node.js client for Google Compute Engine: Scalable, High-Performance Virtual Machines","fork":true,"url":"https://api.github.com/repos/muraliQlogic/nodejs-compute","forks_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/forks","keys_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/keys{/key_id}","collaborators_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/teams","hooks_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/hooks","issue_events_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/issues/events{/number}","events_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/events","assignees_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/assignees{/user}","branches_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/branches{/branch}","tags_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/tags","blobs_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/git/refs{/sha}","trees_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/git/trees{/sha}","statuses_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/statuses/{sha}","languages_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/languages","stargazers_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/stargazers","contributors_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/contributors","subscribers_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/subscribers","subscription_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/subscription","commits_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/commits{/sha}","git_commits_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/git/commits{/sha}","comments_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/comments{/number}","issue_comment_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/issues/comments{/number}","contents_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/contents/{+path}","compare_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/compare/{base}...{head}","merges_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/merges","archive_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/downloads","issues_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/issues{/number}","pulls_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/pulls{/number}","milestones_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/milestones{/number}","notifications_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/labels{/name}","releases_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/releases{/id}","deployments_url":"https://api.github.com/repos/muraliQlogic/nodejs-compute/deployments","created_at":"2018-10-20T03:30:16Z","updated_at":"2018-10-22T20:06:02Z","pushed_at":"2018-10-26T15:48:50Z","git_url":"git://github.com/muraliQlogic/nodejs-compute.git","ssh_url":"git@github.com:muraliQlogic/nodejs-compute.git","clone_url":"https://github.com/muraliQlogic/nodejs-compute.git","svn_url":"https://github.com/muraliQlogic/nodejs-compute","homepage":"https://cloud.google.com/compute/","size":1218,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"googleapis:master","ref":"master","sha":"1943ecfc12343e7b57657522aef79f58f28fff67","user":{"login":"googleapis","id":16785467,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE2Nzg1NDY3","avatar_url":"https://avatars3.githubusercontent.com/u/16785467?v=4","gravatar_id":"","url":"https://api.github.com/users/googleapis","html_url":"https://github.com/googleapis","followers_url":"https://api.github.com/users/googleapis/followers","following_url":"https://api.github.com/users/googleapis/following{/other_user}","gists_url":"https://api.github.com/users/googleapis/gists{/gist_id}","starred_url":"https://api.github.com/users/googleapis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/googleapis/subscriptions","organizations_url":"https://api.github.com/users/googleapis/orgs","repos_url":"https://api.github.com/users/googleapis/repos","events_url":"https://api.github.com/users/googleapis/events{/privacy}","received_events_url":"https://api.github.com/users/googleapis/received_events","type":"Organization","site_admin":false},"repo":{"id":98463458,"node_id":"MDEwOlJlcG9zaXRvcnk5ODQ2MzQ1OA==","name":"nodejs-compute","full_name":"googleapis/nodejs-compute","private":false,"owner":{"login":"googleapis","id":16785467,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE2Nzg1NDY3","avatar_url":"https://avatars3.githubusercontent.com/u/16785467?v=4","gravatar_id":"","url":"https://api.github.com/users/googleapis","html_url":"https://github.com/googleapis","followers_url":"https://api.github.com/users/googleapis/followers","following_url":"https://api.github.com/users/googleapis/following{/other_user}","gists_url":"https://api.github.com/users/googleapis/gists{/gist_id}","starred_url":"https://api.github.com/users/googleapis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/googleapis/subscriptions","organizations_url":"https://api.github.com/users/googleapis/orgs","repos_url":"https://api.github.com/users/googleapis/repos","events_url":"https://api.github.com/users/googleapis/events{/privacy}","received_events_url":"https://api.github.com/users/googleapis/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/googleapis/nodejs-compute","description":"Node.js client for Google Compute Engine: Scalable, High-Performance Virtual Machines","fork":false,"url":"https://api.github.com/repos/googleapis/nodejs-compute","forks_url":"https://api.github.com/repos/googleapis/nodejs-compute/forks","keys_url":"https://api.github.com/repos/googleapis/nodejs-compute/keys{/key_id}","collaborators_url":"https://api.github.com/repos/googleapis/nodejs-compute/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/googleapis/nodejs-compute/teams","hooks_url":"https://api.github.com/repos/googleapis/nodejs-compute/hooks","issue_events_url":"https://api.github.com/repos/googleapis/nodejs-compute/issues/events{/number}","events_url":"https://api.github.com/repos/googleapis/nodejs-compute/events","assignees_url":"https://api.github.com/repos/googleapis/nodejs-compute/assignees{/user}","branches_url":"https://api.github.com/repos/googleapis/nodejs-compute/branches{/branch}","tags_url":"https://api.github.com/repos/googleapis/nodejs-compute/tags","blobs_url":"https://api.github.com/repos/googleapis/nodejs-compute/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/googleapis/nodejs-compute/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/googleapis/nodejs-compute/git/refs{/sha}","trees_url":"https://api.github.com/repos/googleapis/nodejs-compute/git/trees{/sha}","statuses_url":"https://api.github.com/repos/googleapis/nodejs-compute/statuses/{sha}","languages_url":"https://api.github.com/repos/googleapis/nodejs-compute/languages","stargazers_url":"https://api.github.com/repos/googleapis/nodejs-compute/stargazers","contributors_url":"https://api.github.com/repos/googleapis/nodejs-compute/contributors","subscribers_url":"https://api.github.com/repos/googleapis/nodejs-compute/subscribers","subscription_url":"https://api.github.com/repos/googleapis/nodejs-compute/subscription","commits_url":"https://api.github.com/repos/googleapis/nodejs-compute/commits{/sha}","git_commits_url":"https://api.github.com/repos/googleapis/nodejs-compute/git/commits{/sha}","comments_url":"https://api.github.com/repos/googleapis/nodejs-compute/comments{/number}","issue_comment_url":"https://api.github.com/repos/googleapis/nodejs-compute/issues/comments{/number}","contents_url":"https://api.github.com/repos/googleapis/nodejs-compute/contents/{+path}","compare_url":"https://api.github.com/repos/googleapis/nodejs-compute/compare/{base}...{head}","merges_url":"https://api.github.com/repos/googleapis/nodejs-compute/merges","archive_url":"https://api.github.com/repos/googleapis/nodejs-compute/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/googleapis/nodejs-compute/downloads","issues_url":"https://api.github.com/repos/googleapis/nodejs-compute/issues{/number}","pulls_url":"https://api.github.com/repos/googleapis/nodejs-compute/pulls{/number}","milestones_url":"https://api.github.com/repos/googleapis/nodejs-compute/milestones{/number}","notifications_url":"https://api.github.com/repos/googleapis/nodejs-compute/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/googleapis/nodejs-compute/labels{/name}","releases_url":"https://api.github.com/repos/googleapis/nodejs-compute/releases{/id}","deployments_url":"https://api.github.com/repos/googleapis/nodejs-compute/deployments","created_at":"2017-07-26T20:31:42Z","updated_at":"2018-10-25T18:33:30Z","pushed_at":"2018-10-26T15:48:51Z","git_url":"git://github.com/googleapis/nodejs-compute.git","ssh_url":"git@github.com:googleapis/nodejs-compute.git","clone_url":"https://github.com/googleapis/nodejs-compute.git","svn_url":"https://github.com/googleapis/nodejs-compute","homepage":"https://cloud.google.com/compute/","size":1257,"stargazers_count":30,"watchers_count":30,"language":"JavaScript","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":20,"mirror_url":null,"archived":false,"open_issues_count":18,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":20,"open_issues":18,"watchers":30,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/googleapis/nodejs-compute/pulls/183"},"html":{"href":"https://github.com/googleapis/nodejs-compute/pull/183"},"issue":{"href":"https://api.github.com/repos/googleapis/nodejs-compute/issues/183"},"comments":{"href":"https://api.github.com/repos/googleapis/nodejs-compute/issues/183/comments"},"review_comments":{"href":"https://api.github.com/repos/googleapis/nodejs-compute/pulls/183/comments"},"review_comment":{"href":"https://api.github.com/repos/googleapis/nodejs-compute/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/googleapis/nodejs-compute/pulls/183/commits"},"statuses":{"href":"https://api.github.com/repos/googleapis/nodejs-compute/statuses/cd3c1f857a9aca9b2fddd80cb6dc30408f5809e4"}},"author_association":"NONE"}}
{"actor":{"display_login":"JustinBeckwith"}}