{"action":"created","comment":{"url":"https://api.github.com/repos/TimNooren/bokchoi/pulls/comments/185230555","pull_request_review_id":116576763,"id":185230555,"diff_hunk":"@@ -0,0 +1,262 @@\n+\"\"\"\n+Can be used to run Bokchoi on the Google Cloud using Google Compute Engines\n+\n+\"\"\"\n+\n+import os\n+import sys\n+import time\n+import bokchoi.utils\n+\n+import googleapiclient.discovery\n+import googleapiclient.errors\n+\n+import google.auth\n+from google.oauth2 import service_account\n+from google.cloud import storage, exceptions\n+\n+\n+class GCP(object):\n+    \"\"\"Run Bokchoi on the Google Cloud using Google Compute Engines\"\"\"\n+    def __init__(self, bokchoi_project_name, settings):\n+        self.project_name = bokchoi_project_name\n+        self.entry_point = settings['EntryPoint']\n+        self.requirements = settings['Requirements']\n+        self.gcp = self.retrieve_gcp_settings(settings)\n+        self.credentials = self.authorize_client()\n+        self.compute = self.get_authorized_compute()\n+        self.storage = self.get_authorized_storage()\n+\n+    def authorize_client(self):\n+        \"\"\"If the environment variable GOOGLE_APPLICATION_CREDENTIALS or If the Google Cloud SDK is\n+        installed and has application default credentials set they are loaded and returned.\"\"\"\n+        try:\n+            credentials, _ = google.auth.default()\n+            return credentials\n+        except exceptions.Unauthorized as e:\n+            credentials = service_account.Credentials.from_service_account_file(self.gcp.get('AuthKeyLocation'))\n+            return credentials\n+        except Exception as e:\n+            print('Authentication failed, please set the GOOGLE_APPLICATION_CREDENTIALS env variable, install the'\n+                  'Google SDK and authenticate, or supply the JSON file location. \\n', e)\n+\n+    def get_authorized_compute(self):\n+        \"\"\"Authorize with default method (implicit env variable) or otherwise\n+        use the explicit authentication.\n+        \"\"\"\n+        return googleapiclient.discovery.build('compute', 'v1', credentials=self.credentials)\n+\n+    def get_authorized_storage(self):\n+        \"\"\"Authorize with default method (implicit env variable) or otherwise\n+        use the explicit authentication.\n+        \"\"\"\n+        return storage.Client(credentials=self.credentials)\n+\n+    @staticmethod\n+    def retrieve_gcp_settings(settings):\n+        \"\"\"\n+        Checks the given settings and validates if all required values\n+        are there and the values are correct.\n+        :arg settings: a json file with with defined settings\n+        :return: a python dict with renamed input parameters + defaults\n+        \"\"\"\n+        gcp = settings['GCP']\n+\n+        def check_none(v):\n+            if not gcp.get(v):\n+                raise Exception('{} is required, please add it to the config'.format(v))\n+\n+        required = ['ProjectId', 'AuthKeyLocation', 'Bucket']\n+        [check_none(v) for v in required]\n+\n+        return {\n+            'project': gcp.get('ProjectId'),\n+            'auth_key': gcp.get('AuthKeyLocation'),\n+            'bucket': gcp.get('Bucket'),\n+            'region': gcp.get('Region', 'europe-west4'),\n+            'zone': gcp.get('Zone', 'europe-west4-b'),\n+            'network': gcp.get('Network', 'default'),\n+            'sub_network': gcp.get('SubNetwork', 'default'),\n+            'instance_type': gcp.get('InstanceType', 'n1-standard-1'),\n+            'preemptible': gcp.get('Preemptible', False),\n+            'disk_space': gcp.get('DiskSpaceGb', 50)\n+        }\n+\n+    def list_instances(self):\n+        \"\"\"List names of all existing instances\"\"\"\n+        instances = []\n+        result = self.compute.instances().list(\n+            project=self.gcp.get('project'),\n+            zone=self.gcp.get('zone')).execute()\n+        [instances.append(x['name']) for x in result['items']]","path":"bokchoi/gcp/gcp.py","position":91,"original_position":91,"commit_id":"1976e2621f77665c27e20a194983f96e15d3a02c","original_commit_id":"1976e2621f77665c27e20a194983f96e15d3a02c","user":{"login":"TimNooren","id":17043587,"avatar_url":"https://avatars1.githubusercontent.com/u/17043587?v=4","gravatar_id":"","url":"https://api.github.com/users/TimNooren","html_url":"https://github.com/TimNooren","followers_url":"https://api.github.com/users/TimNooren/followers","following_url":"https://api.github.com/users/TimNooren/following{/other_user}","gists_url":"https://api.github.com/users/TimNooren/gists{/gist_id}","starred_url":"https://api.github.com/users/TimNooren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TimNooren/subscriptions","organizations_url":"https://api.github.com/users/TimNooren/orgs","repos_url":"https://api.github.com/users/TimNooren/repos","events_url":"https://api.github.com/users/TimNooren/events{/privacy}","received_events_url":"https://api.github.com/users/TimNooren/received_events","type":"User","site_admin":false},"body":"I think the list comprehension does not add anything here. I would gor for:\r\n`instances = [x['name'] for x in result['items']]`\r\nand remove `instances = []` above it.","created_at":"2018-05-01T14:15:12Z","updated_at":"2018-05-01T14:15:12Z","html_url":"https://github.com/TimNooren/bokchoi/pull/8#discussion_r185230555","pull_request_url":"https://api.github.com/repos/TimNooren/bokchoi/pulls/8","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/TimNooren/bokchoi/pulls/comments/185230555"},"html":{"href":"https://github.com/TimNooren/bokchoi/pull/8#discussion_r185230555"},"pull_request":{"href":"https://api.github.com/repos/TimNooren/bokchoi/pulls/8"}}},"pull_request":{"url":"https://api.github.com/repos/TimNooren/bokchoi/pulls/8","id":184904168,"html_url":"https://github.com/TimNooren/bokchoi/pull/8","diff_url":"https://github.com/TimNooren/bokchoi/pull/8.diff","patch_url":"https://github.com/TimNooren/bokchoi/pull/8.patch","issue_url":"https://api.github.com/repos/TimNooren/bokchoi/issues/8","number":8,"state":"open","locked":false,"title":"Add GCP support","user":{"login":"zwennesm","id":25796881,"avatar_url":"https://avatars2.githubusercontent.com/u/25796881?v=4","gravatar_id":"","url":"https://api.github.com/users/zwennesm","html_url":"https://github.com/zwennesm","followers_url":"https://api.github.com/users/zwennesm/followers","following_url":"https://api.github.com/users/zwennesm/following{/other_user}","gists_url":"https://api.github.com/users/zwennesm/gists{/gist_id}","starred_url":"https://api.github.com/users/zwennesm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zwennesm/subscriptions","organizations_url":"https://api.github.com/users/zwennesm/orgs","repos_url":"https://api.github.com/users/zwennesm/repos","events_url":"https://api.github.com/users/zwennesm/events{/privacy}","received_events_url":"https://api.github.com/users/zwennesm/received_events","type":"User","site_admin":false},"body":"The only thing i'm not sure of is, are the changes in bokchoi.py. I had to change\r\n\r\n```\r\ndef deploy(self, *args, **kwargs):\r\n  print('Deploying: ' + self.config.name)\r\n  return self.backend.deploy(path=self.config.path, *args, **kwargs)\r\n```\r\nto\r\n```\r\ndef deploy(self):\r\n  print('Deploying: ' + self.config.name)\r\n  return self.backend.deploy(path=self.config.config_path)\r\n```\r\nbecause self.config.path does not exist and self.backend.deploy does not require args* and kwargs* as params.","created_at":"2018-04-30T08:44:00Z","updated_at":"2018-05-01T14:15:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cc03d171487e4601042f55784380ad9ade9a9539","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":636852496,"url":"https://api.github.com/repos/TimNooren/bokchoi/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"milestone":{"url":"https://api.github.com/repos/TimNooren/bokchoi/milestones/1","html_url":"https://github.com/TimNooren/bokchoi/milestone/1","labels_url":"https://api.github.com/repos/TimNooren/bokchoi/milestones/1/labels","id":3308043,"number":1,"title":"0.3","description":null,"creator":{"login":"zwennesm","id":25796881,"avatar_url":"https://avatars2.githubusercontent.com/u/25796881?v=4","gravatar_id":"","url":"https://api.github.com/users/zwennesm","html_url":"https://github.com/zwennesm","followers_url":"https://api.github.com/users/zwennesm/followers","following_url":"https://api.github.com/users/zwennesm/following{/other_user}","gists_url":"https://api.github.com/users/zwennesm/gists{/gist_id}","starred_url":"https://api.github.com/users/zwennesm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zwennesm/subscriptions","organizations_url":"https://api.github.com/users/zwennesm/orgs","repos_url":"https://api.github.com/users/zwennesm/repos","events_url":"https://api.github.com/users/zwennesm/events{/privacy}","received_events_url":"https://api.github.com/users/zwennesm/received_events","type":"User","site_admin":false},"open_issues":1,"closed_issues":0,"state":"open","created_at":"2018-04-30T08:43:57Z","updated_at":"2018-04-30T08:44:00Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/TimNooren/bokchoi/pulls/8/commits","review_comments_url":"https://api.github.com/repos/TimNooren/bokchoi/pulls/8/comments","review_comment_url":"https://api.github.com/repos/TimNooren/bokchoi/pulls/comments{/number}","comments_url":"https://api.github.com/repos/TimNooren/bokchoi/issues/8/comments","statuses_url":"https://api.github.com/repos/TimNooren/bokchoi/statuses/1976e2621f77665c27e20a194983f96e15d3a02c","head":{"label":"zwennesm:gcp-support","ref":"gcp-support","sha":"1976e2621f77665c27e20a194983f96e15d3a02c","user":{"login":"zwennesm","id":25796881,"avatar_url":"https://avatars2.githubusercontent.com/u/25796881?v=4","gravatar_id":"","url":"https://api.github.com/users/zwennesm","html_url":"https://github.com/zwennesm","followers_url":"https://api.github.com/users/zwennesm/followers","following_url":"https://api.github.com/users/zwennesm/following{/other_user}","gists_url":"https://api.github.com/users/zwennesm/gists{/gist_id}","starred_url":"https://api.github.com/users/zwennesm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zwennesm/subscriptions","organizations_url":"https://api.github.com/users/zwennesm/orgs","repos_url":"https://api.github.com/users/zwennesm/repos","events_url":"https://api.github.com/users/zwennesm/events{/privacy}","received_events_url":"https://api.github.com/users/zwennesm/received_events","type":"User","site_admin":false},"repo":{"id":130827698,"name":"bokchoi","full_name":"zwennesm/bokchoi","owner":{"login":"zwennesm","id":25796881,"avatar_url":"https://avatars2.githubusercontent.com/u/25796881?v=4","gravatar_id":"","url":"https://api.github.com/users/zwennesm","html_url":"https://github.com/zwennesm","followers_url":"https://api.github.com/users/zwennesm/followers","following_url":"https://api.github.com/users/zwennesm/following{/other_user}","gists_url":"https://api.github.com/users/zwennesm/gists{/gist_id}","starred_url":"https://api.github.com/users/zwennesm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zwennesm/subscriptions","organizations_url":"https://api.github.com/users/zwennesm/orgs","repos_url":"https://api.github.com/users/zwennesm/repos","events_url":"https://api.github.com/users/zwennesm/events{/privacy}","received_events_url":"https://api.github.com/users/zwennesm/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/zwennesm/bokchoi","description":"Machine learning on AWS spot instances","fork":true,"url":"https://api.github.com/repos/zwennesm/bokchoi","forks_url":"https://api.github.com/repos/zwennesm/bokchoi/forks","keys_url":"https://api.github.com/repos/zwennesm/bokchoi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zwennesm/bokchoi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zwennesm/bokchoi/teams","hooks_url":"https://api.github.com/repos/zwennesm/bokchoi/hooks","issue_events_url":"https://api.github.com/repos/zwennesm/bokchoi/issues/events{/number}","events_url":"https://api.github.com/repos/zwennesm/bokchoi/events","assignees_url":"https://api.github.com/repos/zwennesm/bokchoi/assignees{/user}","branches_url":"https://api.github.com/repos/zwennesm/bokchoi/branches{/branch}","tags_url":"https://api.github.com/repos/zwennesm/bokchoi/tags","blobs_url":"https://api.github.com/repos/zwennesm/bokchoi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zwennesm/bokchoi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zwennesm/bokchoi/git/refs{/sha}","trees_url":"https://api.github.com/repos/zwennesm/bokchoi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zwennesm/bokchoi/statuses/{sha}","languages_url":"https://api.github.com/repos/zwennesm/bokchoi/languages","stargazers_url":"https://api.github.com/repos/zwennesm/bokchoi/stargazers","contributors_url":"https://api.github.com/repos/zwennesm/bokchoi/contributors","subscribers_url":"https://api.github.com/repos/zwennesm/bokchoi/subscribers","subscription_url":"https://api.github.com/repos/zwennesm/bokchoi/subscription","commits_url":"https://api.github.com/repos/zwennesm/bokchoi/commits{/sha}","git_commits_url":"https://api.github.com/repos/zwennesm/bokchoi/git/commits{/sha}","comments_url":"https://api.github.com/repos/zwennesm/bokchoi/comments{/number}","issue_comment_url":"https://api.github.com/repos/zwennesm/bokchoi/issues/comments{/number}","contents_url":"https://api.github.com/repos/zwennesm/bokchoi/contents/{+path}","compare_url":"https://api.github.com/repos/zwennesm/bokchoi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zwennesm/bokchoi/merges","archive_url":"https://api.github.com/repos/zwennesm/bokchoi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zwennesm/bokchoi/downloads","issues_url":"https://api.github.com/repos/zwennesm/bokchoi/issues{/number}","pulls_url":"https://api.github.com/repos/zwennesm/bokchoi/pulls{/number}","milestones_url":"https://api.github.com/repos/zwennesm/bokchoi/milestones{/number}","notifications_url":"https://api.github.com/repos/zwennesm/bokchoi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zwennesm/bokchoi/labels{/name}","releases_url":"https://api.github.com/repos/zwennesm/bokchoi/releases{/id}","deployments_url":"https://api.github.com/repos/zwennesm/bokchoi/deployments","created_at":"2018-04-24T09:12:56Z","updated_at":"2018-04-24T09:12:58Z","pushed_at":"2018-04-30T08:40:33Z","git_url":"git://github.com/zwennesm/bokchoi.git","ssh_url":"git@github.com:zwennesm/bokchoi.git","clone_url":"https://github.com/zwennesm/bokchoi.git","svn_url":"https://github.com/zwennesm/bokchoi","homepage":"","size":111,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"TimNooren:0.3","ref":"0.3","sha":"f3f71561815b90ec293f1c2baf6ec031419c0ab2","user":{"login":"TimNooren","id":17043587,"avatar_url":"https://avatars1.githubusercontent.com/u/17043587?v=4","gravatar_id":"","url":"https://api.github.com/users/TimNooren","html_url":"https://github.com/TimNooren","followers_url":"https://api.github.com/users/TimNooren/followers","following_url":"https://api.github.com/users/TimNooren/following{/other_user}","gists_url":"https://api.github.com/users/TimNooren/gists{/gist_id}","starred_url":"https://api.github.com/users/TimNooren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TimNooren/subscriptions","organizations_url":"https://api.github.com/users/TimNooren/orgs","repos_url":"https://api.github.com/users/TimNooren/repos","events_url":"https://api.github.com/users/TimNooren/events{/privacy}","received_events_url":"https://api.github.com/users/TimNooren/received_events","type":"User","site_admin":false},"repo":{"id":95788456,"name":"bokchoi","full_name":"TimNooren/bokchoi","owner":{"login":"TimNooren","id":17043587,"avatar_url":"https://avatars1.githubusercontent.com/u/17043587?v=4","gravatar_id":"","url":"https://api.github.com/users/TimNooren","html_url":"https://github.com/TimNooren","followers_url":"https://api.github.com/users/TimNooren/followers","following_url":"https://api.github.com/users/TimNooren/following{/other_user}","gists_url":"https://api.github.com/users/TimNooren/gists{/gist_id}","starred_url":"https://api.github.com/users/TimNooren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TimNooren/subscriptions","organizations_url":"https://api.github.com/users/TimNooren/orgs","repos_url":"https://api.github.com/users/TimNooren/repos","events_url":"https://api.github.com/users/TimNooren/events{/privacy}","received_events_url":"https://api.github.com/users/TimNooren/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/TimNooren/bokchoi","description":"Machine learning on AWS spot instances","fork":false,"url":"https://api.github.com/repos/TimNooren/bokchoi","forks_url":"https://api.github.com/repos/TimNooren/bokchoi/forks","keys_url":"https://api.github.com/repos/TimNooren/bokchoi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/TimNooren/bokchoi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/TimNooren/bokchoi/teams","hooks_url":"https://api.github.com/repos/TimNooren/bokchoi/hooks","issue_events_url":"https://api.github.com/repos/TimNooren/bokchoi/issues/events{/number}","events_url":"https://api.github.com/repos/TimNooren/bokchoi/events","assignees_url":"https://api.github.com/repos/TimNooren/bokchoi/assignees{/user}","branches_url":"https://api.github.com/repos/TimNooren/bokchoi/branches{/branch}","tags_url":"https://api.github.com/repos/TimNooren/bokchoi/tags","blobs_url":"https://api.github.com/repos/TimNooren/bokchoi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/TimNooren/bokchoi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/TimNooren/bokchoi/git/refs{/sha}","trees_url":"https://api.github.com/repos/TimNooren/bokchoi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/TimNooren/bokchoi/statuses/{sha}","languages_url":"https://api.github.com/repos/TimNooren/bokchoi/languages","stargazers_url":"https://api.github.com/repos/TimNooren/bokchoi/stargazers","contributors_url":"https://api.github.com/repos/TimNooren/bokchoi/contributors","subscribers_url":"https://api.github.com/repos/TimNooren/bokchoi/subscribers","subscription_url":"https://api.github.com/repos/TimNooren/bokchoi/subscription","commits_url":"https://api.github.com/repos/TimNooren/bokchoi/commits{/sha}","git_commits_url":"https://api.github.com/repos/TimNooren/bokchoi/git/commits{/sha}","comments_url":"https://api.github.com/repos/TimNooren/bokchoi/comments{/number}","issue_comment_url":"https://api.github.com/repos/TimNooren/bokchoi/issues/comments{/number}","contents_url":"https://api.github.com/repos/TimNooren/bokchoi/contents/{+path}","compare_url":"https://api.github.com/repos/TimNooren/bokchoi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/TimNooren/bokchoi/merges","archive_url":"https://api.github.com/repos/TimNooren/bokchoi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/TimNooren/bokchoi/downloads","issues_url":"https://api.github.com/repos/TimNooren/bokchoi/issues{/number}","pulls_url":"https://api.github.com/repos/TimNooren/bokchoi/pulls{/number}","milestones_url":"https://api.github.com/repos/TimNooren/bokchoi/milestones{/number}","notifications_url":"https://api.github.com/repos/TimNooren/bokchoi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/TimNooren/bokchoi/labels{/name}","releases_url":"https://api.github.com/repos/TimNooren/bokchoi/releases{/id}","deployments_url":"https://api.github.com/repos/TimNooren/bokchoi/deployments","created_at":"2017-06-29T14:52:21Z","updated_at":"2018-04-04T06:17:37Z","pushed_at":"2018-04-30T08:44:01Z","git_url":"git://github.com/TimNooren/bokchoi.git","ssh_url":"git@github.com:TimNooren/bokchoi.git","clone_url":"https://github.com/TimNooren/bokchoi.git","svn_url":"https://github.com/TimNooren/bokchoi","homepage":"","size":101,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":1,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/TimNooren/bokchoi/pulls/8"},"html":{"href":"https://github.com/TimNooren/bokchoi/pull/8"},"issue":{"href":"https://api.github.com/repos/TimNooren/bokchoi/issues/8"},"comments":{"href":"https://api.github.com/repos/TimNooren/bokchoi/issues/8/comments"},"review_comments":{"href":"https://api.github.com/repos/TimNooren/bokchoi/pulls/8/comments"},"review_comment":{"href":"https://api.github.com/repos/TimNooren/bokchoi/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/TimNooren/bokchoi/pulls/8/commits"},"statuses":{"href":"https://api.github.com/repos/TimNooren/bokchoi/statuses/1976e2621f77665c27e20a194983f96e15d3a02c"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"TimNooren"}}