{"action":"created","comment":{"url":"https://api.github.com/repos/ClusterHQ/flocker/pulls/comments/36642245","id":36642245,"diff_hunk":"@@ -144,4 +150,127 @@ def synchronize_state(self):\n                 maximum_size=dataset.maximum_size,\n                 path=FilePath(b\"/flocker/{}\".format(dataset.dataset_id)))\n             for dataset in self._configured_datasets.values()]\n-        return succeed(None)\n+\n+\n+class ResponseError(Exception):\n+    \"\"\"\n+    An unexpected response from the REST API.\n+    \"\"\"\n+    def __init__(self, code, body):\n+        Exception.__init__(self, \"Unexpected response code {}:\\n{}\\n\".format(\n+            code, body))\n+        self.code = code\n+\n+\n+@implementer(IFlockerAPIV1Client)\n+class FlockerClient(object):\n+    \"\"\"\n+    A client for the Flocker V1 REST API.\n+    \"\"\"\n+    def __init__(self, reactor, host, port,\n+                 ca_cluster_path, cert_path, key_path):\n+        \"\"\"\n+        :param reactor: Reactor to use for connections.\n+        :param bytes host: Host to connect to.\n+        :param int port: Port to connect to:\n+        :param FilePath ca_cluster_path: Path to cluster's CA certificate.\n+        :param FilePath cert_path: Path to user certificate.\n+        :param FilePath key_path: Path to user private key.\n+        \"\"\"\n+        self._treq = treq_with_authentication(reactor, ca_cluster_path,\n+                                              cert_path, key_path)\n+        self._base_url = b\"https://{}:{}/v1\".format(host, port)\n+\n+    def _request(self, method, path, body, success_code, error_codes={}):\n+        \"\"\"\n+        Send a HTTP request to the Flocker API, return decoded JSON body.\n+\n+        :param bytes method: HTTP method, e.g. PUT.\n+        :param bytes path: Path to add to base URL.\n+        :param body: If not ``None``, JSON encode this and send as the\n+            body of the request.\n+        :param int success_code: Expected success response code.\n+        :param error_codes: Mapping from HTTP response code to exception to be\n+            raised if it is present.\n+\n+        :return: ``Deferred`` firing with decoded JSON.\n+        \"\"\"\n+        def error(body, code):\n+            if code in error_codes:\n+                raise error_codes[code](body)\n+            raise ResponseError(code, body)\n+\n+        def got_result(result):\n+            if result.code == success_code:\n+                return json_content(result)\n+            else:\n+                d = content(result)\n+                d.addCallback(error, result.code)\n+                return d\n+\n+        headers = None\n+        data = None\n+        if body is not None:\n+            headers = {b\"content-type\": b\"application/json\"}\n+            data = dumps(body)\n+        request = self._treq.request(\n+            method, self._base_url + path,\n+            data=data, headers=headers,\n+            # Keep tests from having dirty reactor problems:\n+            persistent=False\n+        )\n+        request.addCallback(got_result)\n+        return request\n+\n+    def _parse_configuration_dataset(self, dataset_dict):\n+        \"\"\"\n+        Convert a dictionary decoded from JSON with a dataset's configuration.\n+\n+        :param dataset_dict: Dictionary describing a dataset.\n+        :return: ``Dataset`` instance.\n+        \"\"\"\n+        return Dataset(primary=UUID(dataset_dict[u\"primary\"]),\n+                       maximum_size=dataset_dict[u\"maximum_size\"],\n+                       dataset_id=UUID(dataset_dict[u\"dataset_id\"]),\n+                       metadata=dataset_dict[u\"metadata\"])\n+\n+    def create_dataset(self, primary, maximum_size, dataset_id=None,\n+                       metadata=pmap()):\n+        dataset = {u\"primary\": unicode(primary),\n+                   u\"maximum_size\": maximum_size,\n+                   u\"metadata\": dict(metadata)}\n+        if dataset_id is not None:\n+            dataset[u\"dataset_id\"] = unicode(dataset_id)\n+\n+        request = self._request(b\"POST\", b\"/configuration/datasets\",","path":"flocker/apiclient/_client.py","position":117,"original_position":117,"commit_id":"bee9e8afa1ecf6ef8f7a07e817e8c7656485debb","original_commit_id":"bee9e8afa1ecf6ef8f7a07e817e8c7656485debb","user":{"login":"itamarst","id":3266662,"avatar_url":"https://avatars.githubusercontent.com/u/3266662?v=3","gravatar_id":"","url":"https://api.github.com/users/itamarst","html_url":"https://github.com/itamarst","followers_url":"https://api.github.com/users/itamarst/followers","following_url":"https://api.github.com/users/itamarst/following{/other_user}","gists_url":"https://api.github.com/users/itamarst/gists{/gist_id}","starred_url":"https://api.github.com/users/itamarst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/itamarst/subscriptions","organizations_url":"https://api.github.com/users/itamarst/orgs","repos_url":"https://api.github.com/users/itamarst/repos","events_url":"https://api.github.com/users/itamarst/events{/privacy}","received_events_url":"https://api.github.com/users/itamarst/received_events","type":"User","site_admin":false},"body":"Just response codes AFAICT.","created_at":"2015-08-10T15:11:29Z","updated_at":"2015-08-10T15:11:29Z","html_url":"https://github.com/ClusterHQ/flocker/pull/1832#discussion_r36642245","pull_request_url":"https://api.github.com/repos/ClusterHQ/flocker/pulls/1832","_links":{"self":{"href":"https://api.github.com/repos/ClusterHQ/flocker/pulls/comments/36642245"},"html":{"href":"https://github.com/ClusterHQ/flocker/pull/1832#discussion_r36642245"},"pull_request":{"href":"https://api.github.com/repos/ClusterHQ/flocker/pulls/1832"}}},"pull_request":{"url":"https://api.github.com/repos/ClusterHQ/flocker/pulls/1832","id":41790028,"html_url":"https://github.com/ClusterHQ/flocker/pull/1832","diff_url":"https://github.com/ClusterHQ/flocker/pull/1832.diff","patch_url":"https://github.com/ClusterHQ/flocker/pull/1832.patch","issue_url":"https://api.github.com/repos/ClusterHQ/flocker/issues/1832","number":1832,"state":"open","locked":false,"title":"[FLOC-2753] Real Flocker client","user":{"login":"itamarst","id":3266662,"avatar_url":"https://avatars.githubusercontent.com/u/3266662?v=3","gravatar_id":"","url":"https://api.github.com/users/itamarst","html_url":"https://github.com/itamarst","followers_url":"https://api.github.com/users/itamarst/followers","following_url":"https://api.github.com/users/itamarst/following{/other_user}","gists_url":"https://api.github.com/users/itamarst/gists{/gist_id}","starred_url":"https://api.github.com/users/itamarst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/itamarst/subscriptions","organizations_url":"https://api.github.com/users/itamarst/orgs","repos_url":"https://api.github.com/users/itamarst/repos","events_url":"https://api.github.com/users/itamarst/events{/privacy}","received_events_url":"https://api.github.com/users/itamarst/received_events","type":"User","site_admin":false},"body":"https://clusterhq.atlassian.net/browse/FLOC-2753\r\n\r\nI filed a follow-up issue to replace as much of possible of the existing acceptance code's client with the new client, now that it is implemented.","created_at":"2015-08-06T13:55:05Z","updated_at":"2015-08-10T15:11:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"14c079ebdbf0fa5e8da08e76cede6e20c8fa0699","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ClusterHQ/flocker/pulls/1832/commits","review_comments_url":"https://api.github.com/repos/ClusterHQ/flocker/pulls/1832/comments","review_comment_url":"https://api.github.com/repos/ClusterHQ/flocker/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ClusterHQ/flocker/issues/1832/comments","statuses_url":"https://api.github.com/repos/ClusterHQ/flocker/statuses/bee9e8afa1ecf6ef8f7a07e817e8c7656485debb","head":{"label":"ClusterHQ:flocker-client-FLOC-2753","ref":"flocker-client-FLOC-2753","sha":"bee9e8afa1ecf6ef8f7a07e817e8c7656485debb","user":{"login":"ClusterHQ","id":7913449,"avatar_url":"https://avatars.githubusercontent.com/u/7913449?v=3","gravatar_id":"","url":"https://api.github.com/users/ClusterHQ","html_url":"https://github.com/ClusterHQ","followers_url":"https://api.github.com/users/ClusterHQ/followers","following_url":"https://api.github.com/users/ClusterHQ/following{/other_user}","gists_url":"https://api.github.com/users/ClusterHQ/gists{/gist_id}","starred_url":"https://api.github.com/users/ClusterHQ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ClusterHQ/subscriptions","organizations_url":"https://api.github.com/users/ClusterHQ/orgs","repos_url":"https://api.github.com/users/ClusterHQ/repos","events_url":"https://api.github.com/users/ClusterHQ/events{/privacy}","received_events_url":"https://api.github.com/users/ClusterHQ/received_events","type":"Organization","site_admin":false},"repo":{"id":19248542,"name":"flocker","full_name":"ClusterHQ/flocker","owner":{"login":"ClusterHQ","id":7913449,"avatar_url":"https://avatars.githubusercontent.com/u/7913449?v=3","gravatar_id":"","url":"https://api.github.com/users/ClusterHQ","html_url":"https://github.com/ClusterHQ","followers_url":"https://api.github.com/users/ClusterHQ/followers","following_url":"https://api.github.com/users/ClusterHQ/following{/other_user}","gists_url":"https://api.github.com/users/ClusterHQ/gists{/gist_id}","starred_url":"https://api.github.com/users/ClusterHQ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ClusterHQ/subscriptions","organizations_url":"https://api.github.com/users/ClusterHQ/orgs","repos_url":"https://api.github.com/users/ClusterHQ/repos","events_url":"https://api.github.com/users/ClusterHQ/events{/privacy}","received_events_url":"https://api.github.com/users/ClusterHQ/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ClusterHQ/flocker","description":"Easily manage Docker containers & their data","fork":false,"url":"https://api.github.com/repos/ClusterHQ/flocker","forks_url":"https://api.github.com/repos/ClusterHQ/flocker/forks","keys_url":"https://api.github.com/repos/ClusterHQ/flocker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ClusterHQ/flocker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ClusterHQ/flocker/teams","hooks_url":"https://api.github.com/repos/ClusterHQ/flocker/hooks","issue_events_url":"https://api.github.com/repos/ClusterHQ/flocker/issues/events{/number}","events_url":"https://api.github.com/repos/ClusterHQ/flocker/events","assignees_url":"https://api.github.com/repos/ClusterHQ/flocker/assignees{/user}","branches_url":"https://api.github.com/repos/ClusterHQ/flocker/branches{/branch}","tags_url":"https://api.github.com/repos/ClusterHQ/flocker/tags","blobs_url":"https://api.github.com/repos/ClusterHQ/flocker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ClusterHQ/flocker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ClusterHQ/flocker/git/refs{/sha}","trees_url":"https://api.github.com/repos/ClusterHQ/flocker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ClusterHQ/flocker/statuses/{sha}","languages_url":"https://api.github.com/repos/ClusterHQ/flocker/languages","stargazers_url":"https://api.github.com/repos/ClusterHQ/flocker/stargazers","contributors_url":"https://api.github.com/repos/ClusterHQ/flocker/contributors","subscribers_url":"https://api.github.com/repos/ClusterHQ/flocker/subscribers","subscription_url":"https://api.github.com/repos/ClusterHQ/flocker/subscription","commits_url":"https://api.github.com/repos/ClusterHQ/flocker/commits{/sha}","git_commits_url":"https://api.github.com/repos/ClusterHQ/flocker/git/commits{/sha}","comments_url":"https://api.github.com/repos/ClusterHQ/flocker/comments{/number}","issue_comment_url":"https://api.github.com/repos/ClusterHQ/flocker/issues/comments{/number}","contents_url":"https://api.github.com/repos/ClusterHQ/flocker/contents/{+path}","compare_url":"https://api.github.com/repos/ClusterHQ/flocker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ClusterHQ/flocker/merges","archive_url":"https://api.github.com/repos/ClusterHQ/flocker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ClusterHQ/flocker/downloads","issues_url":"https://api.github.com/repos/ClusterHQ/flocker/issues{/number}","pulls_url":"https://api.github.com/repos/ClusterHQ/flocker/pulls{/number}","milestones_url":"https://api.github.com/repos/ClusterHQ/flocker/milestones{/number}","notifications_url":"https://api.github.com/repos/ClusterHQ/flocker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ClusterHQ/flocker/labels{/name}","releases_url":"https://api.github.com/repos/ClusterHQ/flocker/releases{/id}","created_at":"2014-04-28T18:02:14Z","updated_at":"2015-08-10T13:08:32Z","pushed_at":"2015-08-10T14:53:37Z","git_url":"git://github.com/ClusterHQ/flocker.git","ssh_url":"git@github.com:ClusterHQ/flocker.git","clone_url":"https://github.com/ClusterHQ/flocker.git","svn_url":"https://github.com/ClusterHQ/flocker","homepage":"https://clusterhq.com","size":62024,"stargazers_count":1763,"watchers_count":1763,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":117,"mirror_url":null,"open_issues_count":25,"forks":117,"open_issues":25,"watchers":1763,"default_branch":"master"}},"base":{"label":"ClusterHQ:master","ref":"master","sha":"fa0ec7cfcdacdf1b8d65c5d01a6e21320504850d","user":{"login":"ClusterHQ","id":7913449,"avatar_url":"https://avatars.githubusercontent.com/u/7913449?v=3","gravatar_id":"","url":"https://api.github.com/users/ClusterHQ","html_url":"https://github.com/ClusterHQ","followers_url":"https://api.github.com/users/ClusterHQ/followers","following_url":"https://api.github.com/users/ClusterHQ/following{/other_user}","gists_url":"https://api.github.com/users/ClusterHQ/gists{/gist_id}","starred_url":"https://api.github.com/users/ClusterHQ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ClusterHQ/subscriptions","organizations_url":"https://api.github.com/users/ClusterHQ/orgs","repos_url":"https://api.github.com/users/ClusterHQ/repos","events_url":"https://api.github.com/users/ClusterHQ/events{/privacy}","received_events_url":"https://api.github.com/users/ClusterHQ/received_events","type":"Organization","site_admin":false},"repo":{"id":19248542,"name":"flocker","full_name":"ClusterHQ/flocker","owner":{"login":"ClusterHQ","id":7913449,"avatar_url":"https://avatars.githubusercontent.com/u/7913449?v=3","gravatar_id":"","url":"https://api.github.com/users/ClusterHQ","html_url":"https://github.com/ClusterHQ","followers_url":"https://api.github.com/users/ClusterHQ/followers","following_url":"https://api.github.com/users/ClusterHQ/following{/other_user}","gists_url":"https://api.github.com/users/ClusterHQ/gists{/gist_id}","starred_url":"https://api.github.com/users/ClusterHQ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ClusterHQ/subscriptions","organizations_url":"https://api.github.com/users/ClusterHQ/orgs","repos_url":"https://api.github.com/users/ClusterHQ/repos","events_url":"https://api.github.com/users/ClusterHQ/events{/privacy}","received_events_url":"https://api.github.com/users/ClusterHQ/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ClusterHQ/flocker","description":"Easily manage Docker containers & their data","fork":false,"url":"https://api.github.com/repos/ClusterHQ/flocker","forks_url":"https://api.github.com/repos/ClusterHQ/flocker/forks","keys_url":"https://api.github.com/repos/ClusterHQ/flocker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ClusterHQ/flocker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ClusterHQ/flocker/teams","hooks_url":"https://api.github.com/repos/ClusterHQ/flocker/hooks","issue_events_url":"https://api.github.com/repos/ClusterHQ/flocker/issues/events{/number}","events_url":"https://api.github.com/repos/ClusterHQ/flocker/events","assignees_url":"https://api.github.com/repos/ClusterHQ/flocker/assignees{/user}","branches_url":"https://api.github.com/repos/ClusterHQ/flocker/branches{/branch}","tags_url":"https://api.github.com/repos/ClusterHQ/flocker/tags","blobs_url":"https://api.github.com/repos/ClusterHQ/flocker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ClusterHQ/flocker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ClusterHQ/flocker/git/refs{/sha}","trees_url":"https://api.github.com/repos/ClusterHQ/flocker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ClusterHQ/flocker/statuses/{sha}","languages_url":"https://api.github.com/repos/ClusterHQ/flocker/languages","stargazers_url":"https://api.github.com/repos/ClusterHQ/flocker/stargazers","contributors_url":"https://api.github.com/repos/ClusterHQ/flocker/contributors","subscribers_url":"https://api.github.com/repos/ClusterHQ/flocker/subscribers","subscription_url":"https://api.github.com/repos/ClusterHQ/flocker/subscription","commits_url":"https://api.github.com/repos/ClusterHQ/flocker/commits{/sha}","git_commits_url":"https://api.github.com/repos/ClusterHQ/flocker/git/commits{/sha}","comments_url":"https://api.github.com/repos/ClusterHQ/flocker/comments{/number}","issue_comment_url":"https://api.github.com/repos/ClusterHQ/flocker/issues/comments{/number}","contents_url":"https://api.github.com/repos/ClusterHQ/flocker/contents/{+path}","compare_url":"https://api.github.com/repos/ClusterHQ/flocker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ClusterHQ/flocker/merges","archive_url":"https://api.github.com/repos/ClusterHQ/flocker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ClusterHQ/flocker/downloads","issues_url":"https://api.github.com/repos/ClusterHQ/flocker/issues{/number}","pulls_url":"https://api.github.com/repos/ClusterHQ/flocker/pulls{/number}","milestones_url":"https://api.github.com/repos/ClusterHQ/flocker/milestones{/number}","notifications_url":"https://api.github.com/repos/ClusterHQ/flocker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ClusterHQ/flocker/labels{/name}","releases_url":"https://api.github.com/repos/ClusterHQ/flocker/releases{/id}","created_at":"2014-04-28T18:02:14Z","updated_at":"2015-08-10T13:08:32Z","pushed_at":"2015-08-10T14:53:37Z","git_url":"git://github.com/ClusterHQ/flocker.git","ssh_url":"git@github.com:ClusterHQ/flocker.git","clone_url":"https://github.com/ClusterHQ/flocker.git","svn_url":"https://github.com/ClusterHQ/flocker","homepage":"https://clusterhq.com","size":62024,"stargazers_count":1763,"watchers_count":1763,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":117,"mirror_url":null,"open_issues_count":25,"forks":117,"open_issues":25,"watchers":1763,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ClusterHQ/flocker/pulls/1832"},"html":{"href":"https://github.com/ClusterHQ/flocker/pull/1832"},"issue":{"href":"https://api.github.com/repos/ClusterHQ/flocker/issues/1832"},"comments":{"href":"https://api.github.com/repos/ClusterHQ/flocker/issues/1832/comments"},"review_comments":{"href":"https://api.github.com/repos/ClusterHQ/flocker/pulls/1832/comments"},"review_comment":{"href":"https://api.github.com/repos/ClusterHQ/flocker/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ClusterHQ/flocker/pulls/1832/commits"},"statuses":{"href":"https://api.github.com/repos/ClusterHQ/flocker/statuses/bee9e8afa1ecf6ef8f7a07e817e8c7656485debb"}}}}