{"action":"created","comment":{"url":"https://api.github.com/repos/Metaswitch/calico-docker/pulls/comments/30834575","id":30834575,"diff_hunk":"@@ -0,0 +1,76 @@\n+import sh\n+from sh import docker\n+\n+\n+class DockerHost(object):\n+    \"\"\"\n+    A host container which will hold workload containers to be networked by calico.\n+    \"\"\"\n+    def __init__(self, name):\n+        \"\"\"\n+        Create a container using an image made for docker-in-docker. Load saved images into it.\n+        \"\"\"\n+        self.name = name\n+\n+        pwd = sh.pwd().stdout.rstrip()\n+        docker.run(\"--privileged\", \"-v\", pwd+\":/code\", \"--name\", self.name, \"-tid\", \"jpetazzo/dind\")\n+\n+        self.execute(\"while ! docker ps; do sleep 1; done && \"\n+                   \"docker load --input /code/calico-node.tar && \"\n+                   \"docker load --input /code/busybox.tar && \"\n+                   \"docker load --input /code/nsenter.tar\")\n+\n+    def execute(self, command, **kwargs):\n+        \"\"\"\n+        Pass a command into a host container.\n+        \"\"\"\n+        return docker(\"exec\", \"-t\", self.name, \"bash\", c=command, **kwargs)\n+\n+    def listen(self, stdin, **kwargs):\n+        \"\"\"\n+        Feed a command to a container via stdin. Used when `bash -c` in\n+        DockerHost.execute has bad parsing behavior.\n+        \"\"\"\n+        return docker(\"exec\", \"-i\", self.name, \"bash\", s=True, _in=stdin, **kwargs)\n+\n+    def delete(self):\n+        \"\"\"\n+        Have a container delete itself.\n+        \"\"\"\n+        self.__class__.delete_container(self.name)\n+\n+    def start_etcd(self):\n+        \"\"\"\n+        Start etcd on this host. Not tested for multiple etcd nodes.\n+        \"\"\"\n+        self.execute(\"docker load --input /code/etcd.tar\")\n+\n+        host_ip = docker.inspect(\"--format\", \"'{{ .NetworkSettings.IPAddress }}'\", self.name).stdout.rstrip()\n+        cmd = (\"--name calico \"\n+               \"--advertise-client-urls http://%s:2379 \"\n+               \"--listen-client-urls http://0.0.0.0:2379 \"\n+               \"--initial-advertise-peer-urls http://%s:2380 \"\n+               \"--listen-peer-urls http://0.0.0.0:2380 \"\n+               \"--initial-cluster-token etcd-cluster-2 \"\n+               \"--initial-cluster calico=http://%s:2380 \"\n+               \"--initial-cluster-state new\" % (host_ip, host_ip, host_ip))\n+        self.execute(\"docker run -d -p 2379:2379 quay.io/coreos/etcd:v2.0.10 %s\" % cmd)\n+\n+    @classmethod","path":"calico_containers/tests/fv/docker_host.py","position":59,"original_position":59,"commit_id":"994c43404d6b11c1611d54d8d7e97315642412ab","original_commit_id":"a2239f4d30d2dddbea8416cde2f17c779c319967","user":{"login":"alexaltair","id":4567419,"avatar_url":"https://avatars.githubusercontent.com/u/4567419?v=3","gravatar_id":"","url":"https://api.github.com/users/alexaltair","html_url":"https://github.com/alexaltair","followers_url":"https://api.github.com/users/alexaltair/followers","following_url":"https://api.github.com/users/alexaltair/following{/other_user}","gists_url":"https://api.github.com/users/alexaltair/gists{/gist_id}","starred_url":"https://api.github.com/users/alexaltair/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexaltair/subscriptions","organizations_url":"https://api.github.com/users/alexaltair/orgs","repos_url":"https://api.github.com/users/alexaltair/repos","events_url":"https://api.github.com/users/alexaltair/events{/privacy}","received_events_url":"https://api.github.com/users/alexaltair/received_events","type":"User","site_admin":false},"body":"Partly it felt like it was good to have this class be responsible for deleting hosts, and partly I didn't want to make a *forth* new file.\r\n\r\nThere's an instance method delete in here also.","created_at":"2015-05-21T18:52:03Z","updated_at":"2015-05-21T18:52:03Z","html_url":"https://github.com/Metaswitch/calico-docker/pull/139#discussion_r30834575","pull_request_url":"https://api.github.com/repos/Metaswitch/calico-docker/pulls/139","_links":{"self":{"href":"https://api.github.com/repos/Metaswitch/calico-docker/pulls/comments/30834575"},"html":{"href":"https://github.com/Metaswitch/calico-docker/pull/139#discussion_r30834575"},"pull_request":{"href":"https://api.github.com/repos/Metaswitch/calico-docker/pulls/139"}}},"pull_request":{"url":"https://api.github.com/repos/Metaswitch/calico-docker/pulls/139","id":35779670,"html_url":"https://github.com/Metaswitch/calico-docker/pull/139","diff_url":"https://github.com/Metaswitch/calico-docker/pull/139.diff","patch_url":"https://github.com/Metaswitch/calico-docker/pull/139.patch","issue_url":"https://api.github.com/repos/Metaswitch/calico-docker/issues/139","number":139,"state":"open","locked":false,"title":"Add multi-host test in python","user":{"login":"alexaltair","id":4567419,"avatar_url":"https://avatars.githubusercontent.com/u/4567419?v=3","gravatar_id":"","url":"https://api.github.com/users/alexaltair","html_url":"https://github.com/alexaltair","followers_url":"https://api.github.com/users/alexaltair/followers","following_url":"https://api.github.com/users/alexaltair/following{/other_user}","gists_url":"https://api.github.com/users/alexaltair/gists{/gist_id}","starred_url":"https://api.github.com/users/alexaltair/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexaltair/subscriptions","organizations_url":"https://api.github.com/users/alexaltair/orgs","repos_url":"https://api.github.com/users/alexaltair/repos","events_url":"https://api.github.com/users/alexaltair/events{/privacy}","received_events_url":"https://api.github.com/users/alexaltair/received_events","type":"User","site_admin":false},"body":"Add multi-host test in python.","created_at":"2015-05-19T22:01:18Z","updated_at":"2015-05-21T18:52:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"561476961a9bf377e91c5b75865fa6bd4804abeb","assignee":{"login":"robbrockbank","id":3227729,"avatar_url":"https://avatars.githubusercontent.com/u/3227729?v=3","gravatar_id":"","url":"https://api.github.com/users/robbrockbank","html_url":"https://github.com/robbrockbank","followers_url":"https://api.github.com/users/robbrockbank/followers","following_url":"https://api.github.com/users/robbrockbank/following{/other_user}","gists_url":"https://api.github.com/users/robbrockbank/gists{/gist_id}","starred_url":"https://api.github.com/users/robbrockbank/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robbrockbank/subscriptions","organizations_url":"https://api.github.com/users/robbrockbank/orgs","repos_url":"https://api.github.com/users/robbrockbank/repos","events_url":"https://api.github.com/users/robbrockbank/events{/privacy}","received_events_url":"https://api.github.com/users/robbrockbank/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/Metaswitch/calico-docker/pulls/139/commits","review_comments_url":"https://api.github.com/repos/Metaswitch/calico-docker/pulls/139/comments","review_comment_url":"https://api.github.com/repos/Metaswitch/calico-docker/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Metaswitch/calico-docker/issues/139/comments","statuses_url":"https://api.github.com/repos/Metaswitch/calico-docker/statuses/994c43404d6b11c1611d54d8d7e97315642412ab","head":{"label":"Metaswitch:aa1-multi-host","ref":"aa1-multi-host","sha":"994c43404d6b11c1611d54d8d7e97315642412ab","user":{"login":"Metaswitch","id":453759,"avatar_url":"https://avatars.githubusercontent.com/u/453759?v=3","gravatar_id":"","url":"https://api.github.com/users/Metaswitch","html_url":"https://github.com/Metaswitch","followers_url":"https://api.github.com/users/Metaswitch/followers","following_url":"https://api.github.com/users/Metaswitch/following{/other_user}","gists_url":"https://api.github.com/users/Metaswitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Metaswitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Metaswitch/subscriptions","organizations_url":"https://api.github.com/users/Metaswitch/orgs","repos_url":"https://api.github.com/users/Metaswitch/repos","events_url":"https://api.github.com/users/Metaswitch/events{/privacy}","received_events_url":"https://api.github.com/users/Metaswitch/received_events","type":"Organization","site_admin":false},"repo":{"id":29629333,"name":"calico-docker","full_name":"Metaswitch/calico-docker","owner":{"login":"Metaswitch","id":453759,"avatar_url":"https://avatars.githubusercontent.com/u/453759?v=3","gravatar_id":"","url":"https://api.github.com/users/Metaswitch","html_url":"https://github.com/Metaswitch","followers_url":"https://api.github.com/users/Metaswitch/followers","following_url":"https://api.github.com/users/Metaswitch/following{/other_user}","gists_url":"https://api.github.com/users/Metaswitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Metaswitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Metaswitch/subscriptions","organizations_url":"https://api.github.com/users/Metaswitch/orgs","repos_url":"https://api.github.com/users/Metaswitch/repos","events_url":"https://api.github.com/users/Metaswitch/events{/privacy}","received_events_url":"https://api.github.com/users/Metaswitch/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Metaswitch/calico-docker","description":"Docker version of Project Calico","fork":false,"url":"https://api.github.com/repos/Metaswitch/calico-docker","forks_url":"https://api.github.com/repos/Metaswitch/calico-docker/forks","keys_url":"https://api.github.com/repos/Metaswitch/calico-docker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Metaswitch/calico-docker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Metaswitch/calico-docker/teams","hooks_url":"https://api.github.com/repos/Metaswitch/calico-docker/hooks","issue_events_url":"https://api.github.com/repos/Metaswitch/calico-docker/issues/events{/number}","events_url":"https://api.github.com/repos/Metaswitch/calico-docker/events","assignees_url":"https://api.github.com/repos/Metaswitch/calico-docker/assignees{/user}","branches_url":"https://api.github.com/repos/Metaswitch/calico-docker/branches{/branch}","tags_url":"https://api.github.com/repos/Metaswitch/calico-docker/tags","blobs_url":"https://api.github.com/repos/Metaswitch/calico-docker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Metaswitch/calico-docker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Metaswitch/calico-docker/git/refs{/sha}","trees_url":"https://api.github.com/repos/Metaswitch/calico-docker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Metaswitch/calico-docker/statuses/{sha}","languages_url":"https://api.github.com/repos/Metaswitch/calico-docker/languages","stargazers_url":"https://api.github.com/repos/Metaswitch/calico-docker/stargazers","contributors_url":"https://api.github.com/repos/Metaswitch/calico-docker/contributors","subscribers_url":"https://api.github.com/repos/Metaswitch/calico-docker/subscribers","subscription_url":"https://api.github.com/repos/Metaswitch/calico-docker/subscription","commits_url":"https://api.github.com/repos/Metaswitch/calico-docker/commits{/sha}","git_commits_url":"https://api.github.com/repos/Metaswitch/calico-docker/git/commits{/sha}","comments_url":"https://api.github.com/repos/Metaswitch/calico-docker/comments{/number}","issue_comment_url":"https://api.github.com/repos/Metaswitch/calico-docker/issues/comments{/number}","contents_url":"https://api.github.com/repos/Metaswitch/calico-docker/contents/{+path}","compare_url":"https://api.github.com/repos/Metaswitch/calico-docker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Metaswitch/calico-docker/merges","archive_url":"https://api.github.com/repos/Metaswitch/calico-docker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Metaswitch/calico-docker/downloads","issues_url":"https://api.github.com/repos/Metaswitch/calico-docker/issues{/number}","pulls_url":"https://api.github.com/repos/Metaswitch/calico-docker/pulls{/number}","milestones_url":"https://api.github.com/repos/Metaswitch/calico-docker/milestones{/number}","notifications_url":"https://api.github.com/repos/Metaswitch/calico-docker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Metaswitch/calico-docker/labels{/name}","releases_url":"https://api.github.com/repos/Metaswitch/calico-docker/releases{/id}","created_at":"2015-01-21T23:46:47Z","updated_at":"2015-05-20T23:54:03Z","pushed_at":"2015-05-21T18:02:45Z","git_url":"git://github.com/Metaswitch/calico-docker.git","ssh_url":"git@github.com:Metaswitch/calico-docker.git","clone_url":"https://github.com/Metaswitch/calico-docker.git","svn_url":"https://github.com/Metaswitch/calico-docker","homepage":"http://www.projectcalico.org","size":15073,"stargazers_count":59,"watchers_count":59,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":16,"forks":7,"open_issues":16,"watchers":59,"default_branch":"master"}},"base":{"label":"Metaswitch:master","ref":"master","sha":"da0a49ea5b381897c72bb70daf04657a07c13354","user":{"login":"Metaswitch","id":453759,"avatar_url":"https://avatars.githubusercontent.com/u/453759?v=3","gravatar_id":"","url":"https://api.github.com/users/Metaswitch","html_url":"https://github.com/Metaswitch","followers_url":"https://api.github.com/users/Metaswitch/followers","following_url":"https://api.github.com/users/Metaswitch/following{/other_user}","gists_url":"https://api.github.com/users/Metaswitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Metaswitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Metaswitch/subscriptions","organizations_url":"https://api.github.com/users/Metaswitch/orgs","repos_url":"https://api.github.com/users/Metaswitch/repos","events_url":"https://api.github.com/users/Metaswitch/events{/privacy}","received_events_url":"https://api.github.com/users/Metaswitch/received_events","type":"Organization","site_admin":false},"repo":{"id":29629333,"name":"calico-docker","full_name":"Metaswitch/calico-docker","owner":{"login":"Metaswitch","id":453759,"avatar_url":"https://avatars.githubusercontent.com/u/453759?v=3","gravatar_id":"","url":"https://api.github.com/users/Metaswitch","html_url":"https://github.com/Metaswitch","followers_url":"https://api.github.com/users/Metaswitch/followers","following_url":"https://api.github.com/users/Metaswitch/following{/other_user}","gists_url":"https://api.github.com/users/Metaswitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Metaswitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Metaswitch/subscriptions","organizations_url":"https://api.github.com/users/Metaswitch/orgs","repos_url":"https://api.github.com/users/Metaswitch/repos","events_url":"https://api.github.com/users/Metaswitch/events{/privacy}","received_events_url":"https://api.github.com/users/Metaswitch/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Metaswitch/calico-docker","description":"Docker version of Project Calico","fork":false,"url":"https://api.github.com/repos/Metaswitch/calico-docker","forks_url":"https://api.github.com/repos/Metaswitch/calico-docker/forks","keys_url":"https://api.github.com/repos/Metaswitch/calico-docker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Metaswitch/calico-docker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Metaswitch/calico-docker/teams","hooks_url":"https://api.github.com/repos/Metaswitch/calico-docker/hooks","issue_events_url":"https://api.github.com/repos/Metaswitch/calico-docker/issues/events{/number}","events_url":"https://api.github.com/repos/Metaswitch/calico-docker/events","assignees_url":"https://api.github.com/repos/Metaswitch/calico-docker/assignees{/user}","branches_url":"https://api.github.com/repos/Metaswitch/calico-docker/branches{/branch}","tags_url":"https://api.github.com/repos/Metaswitch/calico-docker/tags","blobs_url":"https://api.github.com/repos/Metaswitch/calico-docker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Metaswitch/calico-docker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Metaswitch/calico-docker/git/refs{/sha}","trees_url":"https://api.github.com/repos/Metaswitch/calico-docker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Metaswitch/calico-docker/statuses/{sha}","languages_url":"https://api.github.com/repos/Metaswitch/calico-docker/languages","stargazers_url":"https://api.github.com/repos/Metaswitch/calico-docker/stargazers","contributors_url":"https://api.github.com/repos/Metaswitch/calico-docker/contributors","subscribers_url":"https://api.github.com/repos/Metaswitch/calico-docker/subscribers","subscription_url":"https://api.github.com/repos/Metaswitch/calico-docker/subscription","commits_url":"https://api.github.com/repos/Metaswitch/calico-docker/commits{/sha}","git_commits_url":"https://api.github.com/repos/Metaswitch/calico-docker/git/commits{/sha}","comments_url":"https://api.github.com/repos/Metaswitch/calico-docker/comments{/number}","issue_comment_url":"https://api.github.com/repos/Metaswitch/calico-docker/issues/comments{/number}","contents_url":"https://api.github.com/repos/Metaswitch/calico-docker/contents/{+path}","compare_url":"https://api.github.com/repos/Metaswitch/calico-docker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Metaswitch/calico-docker/merges","archive_url":"https://api.github.com/repos/Metaswitch/calico-docker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Metaswitch/calico-docker/downloads","issues_url":"https://api.github.com/repos/Metaswitch/calico-docker/issues{/number}","pulls_url":"https://api.github.com/repos/Metaswitch/calico-docker/pulls{/number}","milestones_url":"https://api.github.com/repos/Metaswitch/calico-docker/milestones{/number}","notifications_url":"https://api.github.com/repos/Metaswitch/calico-docker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Metaswitch/calico-docker/labels{/name}","releases_url":"https://api.github.com/repos/Metaswitch/calico-docker/releases{/id}","created_at":"2015-01-21T23:46:47Z","updated_at":"2015-05-20T23:54:03Z","pushed_at":"2015-05-21T18:02:45Z","git_url":"git://github.com/Metaswitch/calico-docker.git","ssh_url":"git@github.com:Metaswitch/calico-docker.git","clone_url":"https://github.com/Metaswitch/calico-docker.git","svn_url":"https://github.com/Metaswitch/calico-docker","homepage":"http://www.projectcalico.org","size":15073,"stargazers_count":59,"watchers_count":59,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":16,"forks":7,"open_issues":16,"watchers":59,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Metaswitch/calico-docker/pulls/139"},"html":{"href":"https://github.com/Metaswitch/calico-docker/pull/139"},"issue":{"href":"https://api.github.com/repos/Metaswitch/calico-docker/issues/139"},"comments":{"href":"https://api.github.com/repos/Metaswitch/calico-docker/issues/139/comments"},"review_comments":{"href":"https://api.github.com/repos/Metaswitch/calico-docker/pulls/139/comments"},"review_comment":{"href":"https://api.github.com/repos/Metaswitch/calico-docker/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Metaswitch/calico-docker/pulls/139/commits"},"statuses":{"href":"https://api.github.com/repos/Metaswitch/calico-docker/statuses/994c43404d6b11c1611d54d8d7e97315642412ab"}}}}