{"action":"created","comment":{"url":"https://api.github.com/repos/onefinestay/gonzo/pulls/comments/39726984","id":39726984,"diff_hunk":"@@ -278,6 +286,65 @@ def create_volume(self, instance, vol_name,\n             ex_volume_type=vol_type,\n         )\n \n+    def create_if_not_exist_security_group(self, group_name, subnet_id=None):\n+        if subnet_id is not None:\n+            subnet = self.compute_session.ex_list_subnets([subnet_id])[0]\n+            subnet_vpc = subnet.extra['vpc_id']\n+        else:\n+            subnet_vpc = None\n+\n+        try:\n+            desc = \"Rules for {}\".format(group_name)\n+            self.compute_session.ex_create_security_group(\n+                group_name,\n+                desc,\n+                subnet_vpc,\n+            )\n+        except Exception as exc:  # libcloud doesn't raise anything better\n+            if not (\"exists\" in str(exc)):\n+                raise\n+\n+    def get_subnet(self, subnet_id):\n+        for subnet in self.compute_session.ex_list_subnets():\n+            if subnet.id == subnet_id:\n+                return subnet\n+        raise LookupError(\"Subnet containting subnet: {} not found\".format(\n+            subnet_id))\n+\n+    def get_security_group(self, group_name, subnet_id=None):\n+        filters = None\n+        if subnet_id:\n+            filters = {'vpc-id': self.get_vpc_for_subnet(subnet_id)}\n+\n+        sec_groups = self.compute_session.ex_get_security_groups(\n+            filters=filters)\n+\n+        for sec_group in sec_groups:\n+            if sec_group.name == group_name:\n+                return sec_group\n+\n+    def get_vpc_for_subnet(self, subnet_id):\n+        try:\n+            subnet = self.compute_session.ex_list_subnets([subnet_id])","path":"gonzo/clouds/compute.py","position":140,"original_position":140,"commit_id":"c542ee258a9c41ff839791e3e3707aa120390636","original_commit_id":"c542ee258a9c41ff839791e3e3707aa120390636","user":{"login":"noisyboiler","id":113480,"avatar_url":"https://avatars.githubusercontent.com/u/113480?v=3","gravatar_id":"","url":"https://api.github.com/users/noisyboiler","html_url":"https://github.com/noisyboiler","followers_url":"https://api.github.com/users/noisyboiler/followers","following_url":"https://api.github.com/users/noisyboiler/following{/other_user}","gists_url":"https://api.github.com/users/noisyboiler/gists{/gist_id}","starred_url":"https://api.github.com/users/noisyboiler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/noisyboiler/subscriptions","organizations_url":"https://api.github.com/users/noisyboiler/orgs","repos_url":"https://api.github.com/users/noisyboiler/repos","events_url":"https://api.github.com/users/noisyboiler/events{/privacy}","received_events_url":"https://api.github.com/users/noisyboiler/received_events","type":"User","site_admin":false},"body":"how come you prefer this to `get_subnet`? you could handle both the `LookUpError` and `IndexError` then.","created_at":"2015-09-17T09:36:15Z","updated_at":"2015-09-17T09:36:15Z","html_url":"https://github.com/onefinestay/gonzo/pull/51#discussion_r39726984","pull_request_url":"https://api.github.com/repos/onefinestay/gonzo/pulls/51","_links":{"self":{"href":"https://api.github.com/repos/onefinestay/gonzo/pulls/comments/39726984"},"html":{"href":"https://github.com/onefinestay/gonzo/pull/51#discussion_r39726984"},"pull_request":{"href":"https://api.github.com/repos/onefinestay/gonzo/pulls/51"}}},"pull_request":{"url":"https://api.github.com/repos/onefinestay/gonzo/pulls/51","id":44667160,"html_url":"https://github.com/onefinestay/gonzo/pull/51","diff_url":"https://github.com/onefinestay/gonzo/pull/51.diff","patch_url":"https://github.com/onefinestay/gonzo/pull/51.patch","issue_url":"https://api.github.com/repos/onefinestay/gonzo/issues/51","number":51,"state":"open","locked":false,"title":"Vpc compatibility","user":{"login":"amitofs","id":2317722,"avatar_url":"https://avatars.githubusercontent.com/u/2317722?v=3","gravatar_id":"","url":"https://api.github.com/users/amitofs","html_url":"https://github.com/amitofs","followers_url":"https://api.github.com/users/amitofs/followers","following_url":"https://api.github.com/users/amitofs/following{/other_user}","gists_url":"https://api.github.com/users/amitofs/gists{/gist_id}","starred_url":"https://api.github.com/users/amitofs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amitofs/subscriptions","organizations_url":"https://api.github.com/users/amitofs/orgs","repos_url":"https://api.github.com/users/amitofs/repos","events_url":"https://api.github.com/users/amitofs/events{/privacy}","received_events_url":"https://api.github.com/users/amitofs/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-09-10T13:27:57Z","updated_at":"2015-09-17T09:36:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4b87a7c6ceb905a3ea13ab9e7cfa7ebfa4c51989","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/onefinestay/gonzo/pulls/51/commits","review_comments_url":"https://api.github.com/repos/onefinestay/gonzo/pulls/51/comments","review_comment_url":"https://api.github.com/repos/onefinestay/gonzo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/onefinestay/gonzo/issues/51/comments","statuses_url":"https://api.github.com/repos/onefinestay/gonzo/statuses/c542ee258a9c41ff839791e3e3707aa120390636","head":{"label":"onefinestay:vpc-compatibility","ref":"vpc-compatibility","sha":"c542ee258a9c41ff839791e3e3707aa120390636","user":{"login":"onefinestay","id":634153,"avatar_url":"https://avatars.githubusercontent.com/u/634153?v=3","gravatar_id":"","url":"https://api.github.com/users/onefinestay","html_url":"https://github.com/onefinestay","followers_url":"https://api.github.com/users/onefinestay/followers","following_url":"https://api.github.com/users/onefinestay/following{/other_user}","gists_url":"https://api.github.com/users/onefinestay/gists{/gist_id}","starred_url":"https://api.github.com/users/onefinestay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/onefinestay/subscriptions","organizations_url":"https://api.github.com/users/onefinestay/orgs","repos_url":"https://api.github.com/users/onefinestay/repos","events_url":"https://api.github.com/users/onefinestay/events{/privacy}","received_events_url":"https://api.github.com/users/onefinestay/received_events","type":"Organization","site_admin":false},"repo":{"id":9224196,"name":"gonzo","full_name":"onefinestay/gonzo","owner":{"login":"onefinestay","id":634153,"avatar_url":"https://avatars.githubusercontent.com/u/634153?v=3","gravatar_id":"","url":"https://api.github.com/users/onefinestay","html_url":"https://github.com/onefinestay","followers_url":"https://api.github.com/users/onefinestay/followers","following_url":"https://api.github.com/users/onefinestay/following{/other_user}","gists_url":"https://api.github.com/users/onefinestay/gists{/gist_id}","starred_url":"https://api.github.com/users/onefinestay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/onefinestay/subscriptions","organizations_url":"https://api.github.com/users/onefinestay/orgs","repos_url":"https://api.github.com/users/onefinestay/repos","events_url":"https://api.github.com/users/onefinestay/events{/privacy}","received_events_url":"https://api.github.com/users/onefinestay/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/onefinestay/gonzo","description":"Instance and release management made easy","fork":false,"url":"https://api.github.com/repos/onefinestay/gonzo","forks_url":"https://api.github.com/repos/onefinestay/gonzo/forks","keys_url":"https://api.github.com/repos/onefinestay/gonzo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/onefinestay/gonzo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/onefinestay/gonzo/teams","hooks_url":"https://api.github.com/repos/onefinestay/gonzo/hooks","issue_events_url":"https://api.github.com/repos/onefinestay/gonzo/issues/events{/number}","events_url":"https://api.github.com/repos/onefinestay/gonzo/events","assignees_url":"https://api.github.com/repos/onefinestay/gonzo/assignees{/user}","branches_url":"https://api.github.com/repos/onefinestay/gonzo/branches{/branch}","tags_url":"https://api.github.com/repos/onefinestay/gonzo/tags","blobs_url":"https://api.github.com/repos/onefinestay/gonzo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/onefinestay/gonzo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/onefinestay/gonzo/git/refs{/sha}","trees_url":"https://api.github.com/repos/onefinestay/gonzo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/onefinestay/gonzo/statuses/{sha}","languages_url":"https://api.github.com/repos/onefinestay/gonzo/languages","stargazers_url":"https://api.github.com/repos/onefinestay/gonzo/stargazers","contributors_url":"https://api.github.com/repos/onefinestay/gonzo/contributors","subscribers_url":"https://api.github.com/repos/onefinestay/gonzo/subscribers","subscription_url":"https://api.github.com/repos/onefinestay/gonzo/subscription","commits_url":"https://api.github.com/repos/onefinestay/gonzo/commits{/sha}","git_commits_url":"https://api.github.com/repos/onefinestay/gonzo/git/commits{/sha}","comments_url":"https://api.github.com/repos/onefinestay/gonzo/comments{/number}","issue_comment_url":"https://api.github.com/repos/onefinestay/gonzo/issues/comments{/number}","contents_url":"https://api.github.com/repos/onefinestay/gonzo/contents/{+path}","compare_url":"https://api.github.com/repos/onefinestay/gonzo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/onefinestay/gonzo/merges","archive_url":"https://api.github.com/repos/onefinestay/gonzo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/onefinestay/gonzo/downloads","issues_url":"https://api.github.com/repos/onefinestay/gonzo/issues{/number}","pulls_url":"https://api.github.com/repos/onefinestay/gonzo/pulls{/number}","milestones_url":"https://api.github.com/repos/onefinestay/gonzo/milestones{/number}","notifications_url":"https://api.github.com/repos/onefinestay/gonzo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/onefinestay/gonzo/labels{/name}","releases_url":"https://api.github.com/repos/onefinestay/gonzo/releases{/id}","created_at":"2013-04-04T17:56:06Z","updated_at":"2015-08-23T19:56:36Z","pushed_at":"2015-09-10T13:27:57Z","git_url":"git://github.com/onefinestay/gonzo.git","ssh_url":"git@github.com:onefinestay/gonzo.git","clone_url":"https://github.com/onefinestay/gonzo.git","svn_url":"https://github.com/onefinestay/gonzo","homepage":null,"size":1812,"stargazers_count":16,"watchers_count":16,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":15,"forks":3,"open_issues":15,"watchers":16,"default_branch":"master"}},"base":{"label":"onefinestay:master","ref":"master","sha":"0f2eb189581e7833a9dec8dafa52ba8ca1765afa","user":{"login":"onefinestay","id":634153,"avatar_url":"https://avatars.githubusercontent.com/u/634153?v=3","gravatar_id":"","url":"https://api.github.com/users/onefinestay","html_url":"https://github.com/onefinestay","followers_url":"https://api.github.com/users/onefinestay/followers","following_url":"https://api.github.com/users/onefinestay/following{/other_user}","gists_url":"https://api.github.com/users/onefinestay/gists{/gist_id}","starred_url":"https://api.github.com/users/onefinestay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/onefinestay/subscriptions","organizations_url":"https://api.github.com/users/onefinestay/orgs","repos_url":"https://api.github.com/users/onefinestay/repos","events_url":"https://api.github.com/users/onefinestay/events{/privacy}","received_events_url":"https://api.github.com/users/onefinestay/received_events","type":"Organization","site_admin":false},"repo":{"id":9224196,"name":"gonzo","full_name":"onefinestay/gonzo","owner":{"login":"onefinestay","id":634153,"avatar_url":"https://avatars.githubusercontent.com/u/634153?v=3","gravatar_id":"","url":"https://api.github.com/users/onefinestay","html_url":"https://github.com/onefinestay","followers_url":"https://api.github.com/users/onefinestay/followers","following_url":"https://api.github.com/users/onefinestay/following{/other_user}","gists_url":"https://api.github.com/users/onefinestay/gists{/gist_id}","starred_url":"https://api.github.com/users/onefinestay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/onefinestay/subscriptions","organizations_url":"https://api.github.com/users/onefinestay/orgs","repos_url":"https://api.github.com/users/onefinestay/repos","events_url":"https://api.github.com/users/onefinestay/events{/privacy}","received_events_url":"https://api.github.com/users/onefinestay/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/onefinestay/gonzo","description":"Instance and release management made easy","fork":false,"url":"https://api.github.com/repos/onefinestay/gonzo","forks_url":"https://api.github.com/repos/onefinestay/gonzo/forks","keys_url":"https://api.github.com/repos/onefinestay/gonzo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/onefinestay/gonzo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/onefinestay/gonzo/teams","hooks_url":"https://api.github.com/repos/onefinestay/gonzo/hooks","issue_events_url":"https://api.github.com/repos/onefinestay/gonzo/issues/events{/number}","events_url":"https://api.github.com/repos/onefinestay/gonzo/events","assignees_url":"https://api.github.com/repos/onefinestay/gonzo/assignees{/user}","branches_url":"https://api.github.com/repos/onefinestay/gonzo/branches{/branch}","tags_url":"https://api.github.com/repos/onefinestay/gonzo/tags","blobs_url":"https://api.github.com/repos/onefinestay/gonzo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/onefinestay/gonzo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/onefinestay/gonzo/git/refs{/sha}","trees_url":"https://api.github.com/repos/onefinestay/gonzo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/onefinestay/gonzo/statuses/{sha}","languages_url":"https://api.github.com/repos/onefinestay/gonzo/languages","stargazers_url":"https://api.github.com/repos/onefinestay/gonzo/stargazers","contributors_url":"https://api.github.com/repos/onefinestay/gonzo/contributors","subscribers_url":"https://api.github.com/repos/onefinestay/gonzo/subscribers","subscription_url":"https://api.github.com/repos/onefinestay/gonzo/subscription","commits_url":"https://api.github.com/repos/onefinestay/gonzo/commits{/sha}","git_commits_url":"https://api.github.com/repos/onefinestay/gonzo/git/commits{/sha}","comments_url":"https://api.github.com/repos/onefinestay/gonzo/comments{/number}","issue_comment_url":"https://api.github.com/repos/onefinestay/gonzo/issues/comments{/number}","contents_url":"https://api.github.com/repos/onefinestay/gonzo/contents/{+path}","compare_url":"https://api.github.com/repos/onefinestay/gonzo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/onefinestay/gonzo/merges","archive_url":"https://api.github.com/repos/onefinestay/gonzo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/onefinestay/gonzo/downloads","issues_url":"https://api.github.com/repos/onefinestay/gonzo/issues{/number}","pulls_url":"https://api.github.com/repos/onefinestay/gonzo/pulls{/number}","milestones_url":"https://api.github.com/repos/onefinestay/gonzo/milestones{/number}","notifications_url":"https://api.github.com/repos/onefinestay/gonzo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/onefinestay/gonzo/labels{/name}","releases_url":"https://api.github.com/repos/onefinestay/gonzo/releases{/id}","created_at":"2013-04-04T17:56:06Z","updated_at":"2015-08-23T19:56:36Z","pushed_at":"2015-09-10T13:27:57Z","git_url":"git://github.com/onefinestay/gonzo.git","ssh_url":"git@github.com:onefinestay/gonzo.git","clone_url":"https://github.com/onefinestay/gonzo.git","svn_url":"https://github.com/onefinestay/gonzo","homepage":null,"size":1812,"stargazers_count":16,"watchers_count":16,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":15,"forks":3,"open_issues":15,"watchers":16,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/onefinestay/gonzo/pulls/51"},"html":{"href":"https://github.com/onefinestay/gonzo/pull/51"},"issue":{"href":"https://api.github.com/repos/onefinestay/gonzo/issues/51"},"comments":{"href":"https://api.github.com/repos/onefinestay/gonzo/issues/51/comments"},"review_comments":{"href":"https://api.github.com/repos/onefinestay/gonzo/pulls/51/comments"},"review_comment":{"href":"https://api.github.com/repos/onefinestay/gonzo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/onefinestay/gonzo/pulls/51/commits"},"statuses":{"href":"https://api.github.com/repos/onefinestay/gonzo/statuses/c542ee258a9c41ff839791e3e3707aa120390636"}}}}