{"action":"created","comment":{"url":"https://api.github.com/repos/open-craft/opencraft/pulls/comments/36835363","id":36835363,"diff_hunk":"@@ -0,0 +1,98 @@\n+# -*- coding: utf-8 -*-\n+#\n+# OpenCraft -- tools to aid developing and hosting free software projects\n+# Copyright (C) 2015 OpenCraft <xavier@opencraft.com>\n+#\n+# This program is free software: you can redistribute it and/or modify\n+# it under the terms of the GNU Affero General Public License as\n+# published by the Free Software Foundation, either version 3 of the\n+# License, or (at your option) any later version.\n+#\n+# This program is distributed in the hope that it will be useful,\n+# but WITHOUT ANY WARRANTY; without even the implied warranty of\n+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+# GNU Affero General Public License for more details.\n+#\n+# You should have received a copy of the GNU Affero General Public License\n+# along with this program.  If not, see <http://www.gnu.org/licenses/>.\n+#\n+\"\"\"\n+OpenStack - Helper functions\n+\"\"\"\n+\n+# Imports #####################################################################\n+\n+import requests\n+\n+from novaclient.v2.client import Client as NovaClient\n+\n+from django.conf import settings\n+\n+from instance.utils import get_requests_retry\n+\n+\n+# Logging #####################################################################\n+\n+import logging\n+logger = logging.getLogger(__name__)\n+\n+\n+# Functions ###################################################################\n+\n+def get_nova_client():\n+    \"\"\"\n+    Instanciate a python novaclient.Client() object with proper credentials\n+    \"\"\"\n+    nova = NovaClient(\n+        settings.OPENSTACK_USER,\n+        settings.OPENSTACK_PASSWORD,\n+        settings.OPENSTACK_TENANT,\n+        settings.OPENSTACK_AUTH_URL,\n+        region_name=settings.OPENSTACK_REGION,\n+    )\n+\n+    # API queries via the nova client occasionally get connection errors from the OpenStack provider.\n+    # To gracefully recover when the unavailability is short-lived, ensure safe requests (as per\n+    # urllib3's definition) are retried before giving up.\n+    adapter = requests.adapters.HTTPAdapter(max_retries=get_requests_retry())\n+    nova.client.open_session()\n+    nova.client._session.mount('http://', adapter)\n+    nova.client._session.mount('https://', adapter)\n+\n+    return nova\n+\n+\n+def create_server(nova, server_name, flavor_selector, image_selector, key_name=None):\n+    \"\"\"\n+    Create a VM via nova\n+    \"\"\"\n+    flavor = nova.flavors.find(**flavor_selector)\n+    image = nova.images.find(**image_selector)\n+\n+    logger.info('Creating OpenStack server: name=%s image=%s flavor=%s', server_name, image, flavor)\n+    return nova.servers.create(server_name, image, flavor, key_name=key_name)\n+\n+\n+def delete_servers_by_name(nova, server_name):\n+    \"\"\"\n+    Delete all servers with `server_name`\n+    \"\"\"\n+    for server in nova.servers.list():\n+        if server.name == server_name:\n+            logger.info('deleting server %s', server)\n+            nova.servers.delete(server)\n+\n+\n+def get_server_public_address(server):\n+    \"\"\"\n+    Retreive the public IP of `server`\n+    \"\"\"\n+    addresses = server.addresses\n+    if not addresses:\n+        return None\n+\n+    # TODO: Ensure it is public","path":"instance/openstack.py","position":94,"original_position":94,"commit_id":"c628168a91278cf575e9fe1f48ef1f17ff02cd48","original_commit_id":"cba0438676db46d3ee61d0472168dbea5f1e3a3b","user":{"login":"dachary","id":433594,"avatar_url":"https://avatars.githubusercontent.com/u/433594?v=3","gravatar_id":"","url":"https://api.github.com/users/dachary","html_url":"https://github.com/dachary","followers_url":"https://api.github.com/users/dachary/followers","following_url":"https://api.github.com/users/dachary/following{/other_user}","gists_url":"https://api.github.com/users/dachary/gists{/gist_id}","starred_url":"https://api.github.com/users/dachary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dachary/subscriptions","organizations_url":"https://api.github.com/users/dachary/orgs","repos_url":"https://api.github.com/users/dachary/repos","events_url":"https://api.github.com/users/dachary/events{/privacy}","received_events_url":"https://api.github.com/users/dachary/received_events","type":"User","site_admin":false},"body":"@antoviaque this is a hack that is not available via the OpenStack API though. I can see how they need that to allow their customers to migrate smoothly though.\r\n<pre>\r\n$ openstack ip floating pool list\r\n+---------+\r\n| Name    |\r\n+---------+\r\n| Ext-Net |\r\n+---------+\r\n$ openstack ip floating create Ext-Net\r\nERROR: openstack The server has either erred or is incapable of performing the requested operation. (HTTP 500) (Request-ID: req-33b3ffcf-76cb-43bf-b825-69f62c6af008)\r\n</pre>\r\n","created_at":"2015-08-12T08:09:00Z","updated_at":"2015-08-12T08:09:00Z","html_url":"https://github.com/open-craft/opencraft/pull/1#discussion_r36835363","pull_request_url":"https://api.github.com/repos/open-craft/opencraft/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/open-craft/opencraft/pulls/comments/36835363"},"html":{"href":"https://github.com/open-craft/opencraft/pull/1#discussion_r36835363"},"pull_request":{"href":"https://api.github.com/repos/open-craft/opencraft/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/open-craft/opencraft/pulls/1","id":41975809,"html_url":"https://github.com/open-craft/opencraft/pull/1","diff_url":"https://github.com/open-craft/opencraft/pull/1.diff","patch_url":"https://github.com/open-craft/opencraft/pull/1.patch","issue_url":"https://api.github.com/repos/open-craft/opencraft/issues/1","number":1,"state":"open","locked":false,"title":"OpenCraft MVP - Fake PR for review","user":{"login":"antoviaque","id":514483,"avatar_url":"https://avatars.githubusercontent.com/u/514483?v=3","gravatar_id":"","url":"https://api.github.com/users/antoviaque","html_url":"https://github.com/antoviaque","followers_url":"https://api.github.com/users/antoviaque/followers","following_url":"https://api.github.com/users/antoviaque/following{/other_user}","gists_url":"https://api.github.com/users/antoviaque/gists{/gist_id}","starred_url":"https://api.github.com/users/antoviaque/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antoviaque/subscriptions","organizations_url":"https://api.github.com/users/antoviaque/orgs","repos_url":"https://api.github.com/users/antoviaque/repos","events_url":"https://api.github.com/users/antoviaque/events{/privacy}","received_events_url":"https://api.github.com/users/antoviaque/received_events","type":"User","site_admin":false},"body":"See http://console.opencraft.com/ for a working example, and the README for installation instructions.","created_at":"2015-08-09T19:44:02Z","updated_at":"2015-08-12T08:09:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0607fff2ceef3c520d64fe0c3631185e4a3ae09d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/open-craft/opencraft/pulls/1/commits","review_comments_url":"https://api.github.com/repos/open-craft/opencraft/pulls/1/comments","review_comment_url":"https://api.github.com/repos/open-craft/opencraft/pulls/comments{/number}","comments_url":"https://api.github.com/repos/open-craft/opencraft/issues/1/comments","statuses_url":"https://api.github.com/repos/open-craft/opencraft/statuses/c628168a91278cf575e9fe1f48ef1f17ff02cd48","head":{"label":"open-craft:master","ref":"master","sha":"c628168a91278cf575e9fe1f48ef1f17ff02cd48","user":{"login":"open-craft","id":7414786,"avatar_url":"https://avatars.githubusercontent.com/u/7414786?v=3","gravatar_id":"","url":"https://api.github.com/users/open-craft","html_url":"https://github.com/open-craft","followers_url":"https://api.github.com/users/open-craft/followers","following_url":"https://api.github.com/users/open-craft/following{/other_user}","gists_url":"https://api.github.com/users/open-craft/gists{/gist_id}","starred_url":"https://api.github.com/users/open-craft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/open-craft/subscriptions","organizations_url":"https://api.github.com/users/open-craft/orgs","repos_url":"https://api.github.com/users/open-craft/repos","events_url":"https://api.github.com/users/open-craft/events{/privacy}","received_events_url":"https://api.github.com/users/open-craft/received_events","type":"Organization","site_admin":false},"repo":{"id":40447973,"name":"opencraft","full_name":"open-craft/opencraft","owner":{"login":"open-craft","id":7414786,"avatar_url":"https://avatars.githubusercontent.com/u/7414786?v=3","gravatar_id":"","url":"https://api.github.com/users/open-craft","html_url":"https://github.com/open-craft","followers_url":"https://api.github.com/users/open-craft/followers","following_url":"https://api.github.com/users/open-craft/following{/other_user}","gists_url":"https://api.github.com/users/open-craft/gists{/gist_id}","starred_url":"https://api.github.com/users/open-craft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/open-craft/subscriptions","organizations_url":"https://api.github.com/users/open-craft/orgs","repos_url":"https://api.github.com/users/open-craft/repos","events_url":"https://api.github.com/users/open-craft/events{/privacy}","received_events_url":"https://api.github.com/users/open-craft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/open-craft/opencraft","description":"OpenCraft - Instance Manager","fork":false,"url":"https://api.github.com/repos/open-craft/opencraft","forks_url":"https://api.github.com/repos/open-craft/opencraft/forks","keys_url":"https://api.github.com/repos/open-craft/opencraft/keys{/key_id}","collaborators_url":"https://api.github.com/repos/open-craft/opencraft/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/open-craft/opencraft/teams","hooks_url":"https://api.github.com/repos/open-craft/opencraft/hooks","issue_events_url":"https://api.github.com/repos/open-craft/opencraft/issues/events{/number}","events_url":"https://api.github.com/repos/open-craft/opencraft/events","assignees_url":"https://api.github.com/repos/open-craft/opencraft/assignees{/user}","branches_url":"https://api.github.com/repos/open-craft/opencraft/branches{/branch}","tags_url":"https://api.github.com/repos/open-craft/opencraft/tags","blobs_url":"https://api.github.com/repos/open-craft/opencraft/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/open-craft/opencraft/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/open-craft/opencraft/git/refs{/sha}","trees_url":"https://api.github.com/repos/open-craft/opencraft/git/trees{/sha}","statuses_url":"https://api.github.com/repos/open-craft/opencraft/statuses/{sha}","languages_url":"https://api.github.com/repos/open-craft/opencraft/languages","stargazers_url":"https://api.github.com/repos/open-craft/opencraft/stargazers","contributors_url":"https://api.github.com/repos/open-craft/opencraft/contributors","subscribers_url":"https://api.github.com/repos/open-craft/opencraft/subscribers","subscription_url":"https://api.github.com/repos/open-craft/opencraft/subscription","commits_url":"https://api.github.com/repos/open-craft/opencraft/commits{/sha}","git_commits_url":"https://api.github.com/repos/open-craft/opencraft/git/commits{/sha}","comments_url":"https://api.github.com/repos/open-craft/opencraft/comments{/number}","issue_comment_url":"https://api.github.com/repos/open-craft/opencraft/issues/comments{/number}","contents_url":"https://api.github.com/repos/open-craft/opencraft/contents/{+path}","compare_url":"https://api.github.com/repos/open-craft/opencraft/compare/{base}...{head}","merges_url":"https://api.github.com/repos/open-craft/opencraft/merges","archive_url":"https://api.github.com/repos/open-craft/opencraft/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/open-craft/opencraft/downloads","issues_url":"https://api.github.com/repos/open-craft/opencraft/issues{/number}","pulls_url":"https://api.github.com/repos/open-craft/opencraft/pulls{/number}","milestones_url":"https://api.github.com/repos/open-craft/opencraft/milestones{/number}","notifications_url":"https://api.github.com/repos/open-craft/opencraft/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/open-craft/opencraft/labels{/name}","releases_url":"https://api.github.com/repos/open-craft/opencraft/releases{/id}","created_at":"2015-08-09T19:35:05Z","updated_at":"2015-08-09T19:35:23Z","pushed_at":"2015-08-12T07:57:31Z","git_url":"git://github.com/open-craft/opencraft.git","ssh_url":"git@github.com:open-craft/opencraft.git","clone_url":"https://github.com/open-craft/opencraft.git","svn_url":"https://github.com/open-craft/opencraft","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"open-craft:first-commit","ref":"first-commit","sha":"6b98fa6fd444590401a3ddc8f4b8a47bd1e6633e","user":{"login":"open-craft","id":7414786,"avatar_url":"https://avatars.githubusercontent.com/u/7414786?v=3","gravatar_id":"","url":"https://api.github.com/users/open-craft","html_url":"https://github.com/open-craft","followers_url":"https://api.github.com/users/open-craft/followers","following_url":"https://api.github.com/users/open-craft/following{/other_user}","gists_url":"https://api.github.com/users/open-craft/gists{/gist_id}","starred_url":"https://api.github.com/users/open-craft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/open-craft/subscriptions","organizations_url":"https://api.github.com/users/open-craft/orgs","repos_url":"https://api.github.com/users/open-craft/repos","events_url":"https://api.github.com/users/open-craft/events{/privacy}","received_events_url":"https://api.github.com/users/open-craft/received_events","type":"Organization","site_admin":false},"repo":{"id":40447973,"name":"opencraft","full_name":"open-craft/opencraft","owner":{"login":"open-craft","id":7414786,"avatar_url":"https://avatars.githubusercontent.com/u/7414786?v=3","gravatar_id":"","url":"https://api.github.com/users/open-craft","html_url":"https://github.com/open-craft","followers_url":"https://api.github.com/users/open-craft/followers","following_url":"https://api.github.com/users/open-craft/following{/other_user}","gists_url":"https://api.github.com/users/open-craft/gists{/gist_id}","starred_url":"https://api.github.com/users/open-craft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/open-craft/subscriptions","organizations_url":"https://api.github.com/users/open-craft/orgs","repos_url":"https://api.github.com/users/open-craft/repos","events_url":"https://api.github.com/users/open-craft/events{/privacy}","received_events_url":"https://api.github.com/users/open-craft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/open-craft/opencraft","description":"OpenCraft - Instance Manager","fork":false,"url":"https://api.github.com/repos/open-craft/opencraft","forks_url":"https://api.github.com/repos/open-craft/opencraft/forks","keys_url":"https://api.github.com/repos/open-craft/opencraft/keys{/key_id}","collaborators_url":"https://api.github.com/repos/open-craft/opencraft/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/open-craft/opencraft/teams","hooks_url":"https://api.github.com/repos/open-craft/opencraft/hooks","issue_events_url":"https://api.github.com/repos/open-craft/opencraft/issues/events{/number}","events_url":"https://api.github.com/repos/open-craft/opencraft/events","assignees_url":"https://api.github.com/repos/open-craft/opencraft/assignees{/user}","branches_url":"https://api.github.com/repos/open-craft/opencraft/branches{/branch}","tags_url":"https://api.github.com/repos/open-craft/opencraft/tags","blobs_url":"https://api.github.com/repos/open-craft/opencraft/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/open-craft/opencraft/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/open-craft/opencraft/git/refs{/sha}","trees_url":"https://api.github.com/repos/open-craft/opencraft/git/trees{/sha}","statuses_url":"https://api.github.com/repos/open-craft/opencraft/statuses/{sha}","languages_url":"https://api.github.com/repos/open-craft/opencraft/languages","stargazers_url":"https://api.github.com/repos/open-craft/opencraft/stargazers","contributors_url":"https://api.github.com/repos/open-craft/opencraft/contributors","subscribers_url":"https://api.github.com/repos/open-craft/opencraft/subscribers","subscription_url":"https://api.github.com/repos/open-craft/opencraft/subscription","commits_url":"https://api.github.com/repos/open-craft/opencraft/commits{/sha}","git_commits_url":"https://api.github.com/repos/open-craft/opencraft/git/commits{/sha}","comments_url":"https://api.github.com/repos/open-craft/opencraft/comments{/number}","issue_comment_url":"https://api.github.com/repos/open-craft/opencraft/issues/comments{/number}","contents_url":"https://api.github.com/repos/open-craft/opencraft/contents/{+path}","compare_url":"https://api.github.com/repos/open-craft/opencraft/compare/{base}...{head}","merges_url":"https://api.github.com/repos/open-craft/opencraft/merges","archive_url":"https://api.github.com/repos/open-craft/opencraft/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/open-craft/opencraft/downloads","issues_url":"https://api.github.com/repos/open-craft/opencraft/issues{/number}","pulls_url":"https://api.github.com/repos/open-craft/opencraft/pulls{/number}","milestones_url":"https://api.github.com/repos/open-craft/opencraft/milestones{/number}","notifications_url":"https://api.github.com/repos/open-craft/opencraft/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/open-craft/opencraft/labels{/name}","releases_url":"https://api.github.com/repos/open-craft/opencraft/releases{/id}","created_at":"2015-08-09T19:35:05Z","updated_at":"2015-08-09T19:35:23Z","pushed_at":"2015-08-12T07:57:31Z","git_url":"git://github.com/open-craft/opencraft.git","ssh_url":"git@github.com:open-craft/opencraft.git","clone_url":"https://github.com/open-craft/opencraft.git","svn_url":"https://github.com/open-craft/opencraft","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/open-craft/opencraft/pulls/1"},"html":{"href":"https://github.com/open-craft/opencraft/pull/1"},"issue":{"href":"https://api.github.com/repos/open-craft/opencraft/issues/1"},"comments":{"href":"https://api.github.com/repos/open-craft/opencraft/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/open-craft/opencraft/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/open-craft/opencraft/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/open-craft/opencraft/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/open-craft/opencraft/statuses/c628168a91278cf575e9fe1f48ef1f17ff02cd48"}}}}