{"action":"created","comment":{"url":"https://api.github.com/repos/open-craft/opencraft/pulls/comments/38263334","id":38263334,"diff_hunk":"@@ -0,0 +1,476 @@\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+Instance app models - Instance\n+\"\"\"\n+\n+# Imports #####################################################################\n+\n+import os\n+\n+from django.conf import settings\n+from django.core.validators import RegexValidator\n+from django.db import models\n+from django.template import loader\n+from django.utils import timezone\n+from django_extensions.db.models import TimeStampedModel\n+\n+from instance import ansible, github\n+from instance.gandi import GandiAPI\n+from instance.github import fork_name2tuple, get_username_list_from_team\n+from instance.log_exception import log_exception\n+from instance.repo import clone_configuration_repo\n+from instance.models.logging_mixin import LoggerInstanceMixin\n+from instance.models.utils import ValidateModelMixin\n+\n+\n+# Constants ###################################################################\n+\n+PROTOCOL_CHOICES = (\n+    ('http', 'HTTP - Unencrypted clear text'),\n+    ('https', 'HTTPS - Encrypted'),\n+)\n+\n+gandi = GandiAPI()\n+\n+\n+# Exceptions ##################################################################\n+\n+class InconsistentInstanceState(Exception):\n+    \"\"\"\n+    Indicates that the status of an instance can't be determined\n+    \"\"\"\n+    pass\n+\n+\n+# Validators ##################################################################\n+\n+sha1_validator = RegexValidator(regex='^[0-9a-f]{40}$', message='Full SHA1 hash required')\n+\n+\n+# Models ######################################################################\n+\n+class Instance(ValidateModelMixin, TimeStampedModel):\n+    \"\"\"\n+    Instance - Group of servers running an application made of multiple services\n+    \"\"\"\n+    EMPTY = 'empty'\n+    NEW = 'new'\n+    STARTED = 'started'\n+    ACTIVE = 'active'\n+    BOOTED = 'booted'\n+    PROVISIONED = 'provisioned'\n+    REBOOTING = 'rebooting'\n+    READY = 'ready'\n+    LIVE = 'live'\n+    STOPPING = 'stopping'\n+    STOPPED = 'stopped'\n+    TERMINATING = 'terminating'","path":"instance/models/instance.py","position":85,"original_position":84,"commit_id":"9d19cba65f1d77c52d6b4ebc7d73ca64919718b3","original_commit_id":"d50f36d0f367e8a9f73ed66f183537589bac5c22","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":"@bradenmacdonald Ok, I have added a comment to this section, to make sure someone reading this is aware that fuller descriptions are available in `server.py`.","created_at":"2015-08-29T15:56:38Z","updated_at":"2015-08-29T15:56:38Z","html_url":"https://github.com/open-craft/opencraft/pull/1#discussion_r38263334","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/38263334"},"html":{"href":"https://github.com/open-craft/opencraft/pull/1#discussion_r38263334"},"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.\r\n\r\n### Discussions\r\n\r\nReviewers input needed:\r\n\r\n- [X] ~~Pylint configuration~~\r\n  - [X] ~~[Which warnings to ignore](https://github.com/open-craft/opencraft/pull/1#discussion-diff-36737650)~~\r\n  - [X] ~~[Max locals](https://github.com/open-craft/opencraft/pull/1#discussion-diff-36738319) & [Max branches](https://github.com/open-craft/opencraft/pull/1#discussion-diff-36738464)~~\r\n\r\n### TODO - Current PR\r\n\r\n- [X] ~~Small nits~~\r\n- [X] ~~[Clearing temporary files & directories](https://github.com/open-craft/opencraft/pull/1#discussion-diff-36727282)~~\r\n- [X] ~~Use constants for instance & server model status~~\r\n- [X] ~~Web UI loading indicator~~\r\n- [X] ~~Integration tests~~\r\n  - [X] ~~Add an integration test that fully instantiates a sandbox~~\r\n  - [X] ~~Setup CircleCI to run integration tests~~\r\n  - [X] ~~Make CircleCI builds reliable (they currently timeout)~~\r\n- [x] ~~Display a \"Please wait\" page while DNS are being set for the first time, initially~~\r\n- [x] ~~Add hostname to `/etc/hosts` to avoid warning _\"sudo: unable to resolve host xxxx\"_~~\r\n- [ ] ~~[Add comment for instance statuses, pointing to server status descriptions](https://github.com/open-craft/opencraft/pull/1#discussion_r37565261)~~\r\n- [ ] ~~[Shorter & updated sandbox names](https://github.com/open-craft/opencraft/pull/1#discussion_r36607416)~~\r\n\r\n### TODO - Future tasks\r\n\r\n- [Improve logging management](https://github.com/open-craft/opencraft/pull/1#discussion_r36728597)\r\n  - [Use custom constants for logging levels](https://github.com/open-craft/opencraft/pull/1#discussion-diff-36729765)\r\n- [Switch to OpenStack CLI instead of class](https://github.com/open-craft/opencraft/pull/1#discussion_r36623788)\r\n  - [Use OS_* variables for OpenStack configuration](https://github.com/open-craft/opencraft/pull/1#discussion-diff-36625380)\r\n  - [Use vanilla Ubuntu image from upstream](https://github.com/open-craft/opencraft/pull/1#discussion-diff-36625198)\r\n  - [Implementation-agnostic public IP retreival](https://github.com/open-craft/opencraft/pull/1#discussion_r36624339)\r\n\r\n### Suggestions & ideas\r\n\r\n- [Links to PRs in Web UI](https://github.com/open-craft/opencraft/pull/1#discussion_r36713342) & Better PR handling via dedicated model\r\n- [Get the build to fail when the ansible run fails (might also require error states for VMs & retries)](https://github.com/open-craft/opencraft/pull/1#discussion_r36624887)\r\n- OpenCraft logo & \"Powered by\"/licensing footer & as a favicon\r\n- [Relax regex syntax for configuration variables in PRs](https://github.com/open-craft/opencraft/pull/1#discussion_r37372753)\r\n- [Better status transition management - state machine?](https://github.com/open-craft/opencraft/pull/1#discussion_r36733250)\r\n- [Better approach for reboot detection](https://github.com/open-craft/opencraft/pull/1#discussion_r36733404)\r\n- [Load XBlocks by default](https://github.com/open-craft/opencraft/pull/1#discussion_r36607383)","created_at":"2015-08-09T19:44:02Z","updated_at":"2015-08-29T15:56:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9aec8c0bcdcd0b8f703585c021f1e1c66ebfe8b4","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/9d19cba65f1d77c52d6b4ebc7d73ca64919718b3","head":{"label":"open-craft:master","ref":"master","sha":"9d19cba65f1d77c52d6b4ebc7d73ca64919718b3","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-29T14:47:04Z","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":816,"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-29T14:47:04Z","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":816,"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/9d19cba65f1d77c52d6b4ebc7d73ca64919718b3"}}}}