{"action":"created","comment":{"url":"https://api.github.com/repos/zalando/patroni/pulls/comments/70237656","id":70237656,"diff_hunk":"@@ -162,18 +169,86 @@ def do_POST_reload(self):\n             response = str(e)\n         self._write_response(status_code, response)\n \n+    @staticmethod\n+    def parse_schedule(schedule, action):\n+        \"\"\" parses the given schedule and validates at \"\"\"\n+        error = None\n+        scheduled_at = None\n+        try:\n+            scheduled_at = dateutil.parser.parse(schedule)\n+            if scheduled_at.tzinfo is None:\n+                error = 'Timezone information is mandatory for the scheduled {0}'.format(action)\n+                status_code = 400\n+            elif scheduled_at < datetime.datetime.now(pytz.utc):\n+                error = 'Cannot schedule {0} in the past'.format(action)\n+                status_code = 422\n+            else:\n+                status_code = None\n+        except (ValueError, TypeError):\n+            logger.exception('Invalid scheduled %s time: %s', action, schedule)\n+            error = 'Unable to parse scheduled timestamp. It should be in an unambiguous format, e.g. ISO 8601'\n+            status_code = 422\n+        return (status_code, error, scheduled_at)\n+\n     @check_auth\n     def do_POST_restart(self):\n         status_code = 500\n         data = 'restart failed'\n-        try:\n-            status, data = self.server.patroni.ha.restart()\n-            status_code = 200 if status else 503\n-        except Exception:\n-            logger.exception('Exception during restart')\n+        request = self._read_json_content(body_is_optional=True)\n+        if request is None:\n+            # failed to parse the json\n+            return\n+        if request:\n+            logger.debug(\"received restart request: {0}\".format(request))\n+        for k in request:\n+            if k == 'schedule':\n+                (_, data, request[k]) = self.parse_schedule(request[k], \"restart\")\n+                if _:\n+                    status_code = _\n+                    break\n+            elif k == 'role':\n+                if request[k] not in ('master', 'replica'):\n+                    status_code = 400\n+                    data = \"PostgreSQL role should be either master or replica\"\n+                    break\n+            elif k == 'postgres_version':\n+                if not re.match(r'([1-9][0-9]?\\.){2}[1-9][0-9]?$', request[k]):","path":"patroni/api.py","position":99,"original_position":99,"commit_id":"6da2eecb9067ed950073151c443e4600b9fdff66","original_commit_id":"6da2eecb9067ed950073151c443e4600b9fdff66","user":{"login":"CyberDem0n","id":3407345,"avatar_url":"https://avatars.githubusercontent.com/u/3407345?v=3","gravatar_id":"","url":"https://api.github.com/users/CyberDem0n","html_url":"https://github.com/CyberDem0n","followers_url":"https://api.github.com/users/CyberDem0n/followers","following_url":"https://api.github.com/users/CyberDem0n/following{/other_user}","gists_url":"https://api.github.com/users/CyberDem0n/gists{/gist_id}","starred_url":"https://api.github.com/users/CyberDem0n/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CyberDem0n/subscriptions","organizations_url":"https://api.github.com/users/CyberDem0n/orgs","repos_url":"https://api.github.com/users/CyberDem0n/repos","events_url":"https://api.github.com/users/CyberDem0n/events{/privacy}","received_events_url":"https://api.github.com/users/CyberDem0n/received_events","type":"User","site_admin":false},"body":"This regexp will fail with 9.5.0...\r\n\r\nIt would be better to use something like `r'^[1-9][0-9]?(\\.[0-9]+){2}$'` but it also not 100% correct","created_at":"2016-07-11T10:57:40Z","updated_at":"2016-07-11T10:57:40Z","html_url":"https://github.com/zalando/patroni/pull/227#discussion_r70237656","pull_request_url":"https://api.github.com/repos/zalando/patroni/pulls/227","_links":{"self":{"href":"https://api.github.com/repos/zalando/patroni/pulls/comments/70237656"},"html":{"href":"https://github.com/zalando/patroni/pull/227#discussion_r70237656"},"pull_request":{"href":"https://api.github.com/repos/zalando/patroni/pulls/227"}}},"pull_request":{"url":"https://api.github.com/repos/zalando/patroni/pulls/227","id":75269575,"html_url":"https://github.com/zalando/patroni/pull/227","diff_url":"https://github.com/zalando/patroni/pull/227.diff","patch_url":"https://github.com/zalando/patroni/pull/227.patch","issue_url":"https://api.github.com/repos/zalando/patroni/issues/227","number":227,"state":"open","locked":false,"title":"Feature/scheduled restarts","user":{"login":"alexeyklyukin","id":339913,"avatar_url":"https://avatars.githubusercontent.com/u/339913?v=3","gravatar_id":"","url":"https://api.github.com/users/alexeyklyukin","html_url":"https://github.com/alexeyklyukin","followers_url":"https://api.github.com/users/alexeyklyukin/followers","following_url":"https://api.github.com/users/alexeyklyukin/following{/other_user}","gists_url":"https://api.github.com/users/alexeyklyukin/gists{/gist_id}","starred_url":"https://api.github.com/users/alexeyklyukin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexeyklyukin/subscriptions","organizations_url":"https://api.github.com/users/alexeyklyukin/orgs","repos_url":"https://api.github.com/users/alexeyklyukin/repos","events_url":"https://api.github.com/users/alexeyklyukin/events{/privacy}","received_events_url":"https://api.github.com/users/alexeyklyukin/received_events","type":"User","site_admin":false},"body":"Implement scheduled and conditional restarts. The following conditions are supported for both:\r\n\r\n- with_pending_restart_flag: restart only if the pending restart flag is set (because of the configuration change)\r\n- role: restart if the Postgres role is set to a certain value\r\n- postgres_version (x.y.z) - restart if the current Postgres version is less than the one specified. ","created_at":"2016-06-27T07:56:15Z","updated_at":"2016-07-11T10:57:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"329d116f63b9a7f677ecb7fdb9d9e4b245cce91c","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/zalando/patroni/pulls/227/commits","review_comments_url":"https://api.github.com/repos/zalando/patroni/pulls/227/comments","review_comment_url":"https://api.github.com/repos/zalando/patroni/pulls/comments{/number}","comments_url":"https://api.github.com/repos/zalando/patroni/issues/227/comments","statuses_url":"https://api.github.com/repos/zalando/patroni/statuses/6da2eecb9067ed950073151c443e4600b9fdff66","head":{"label":"zalando:feature/scheduled_restarts","ref":"feature/scheduled_restarts","sha":"6da2eecb9067ed950073151c443e4600b9fdff66","user":{"login":"zalando","id":1564818,"avatar_url":"https://avatars.githubusercontent.com/u/1564818?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando","html_url":"https://github.com/zalando","followers_url":"https://api.github.com/users/zalando/followers","following_url":"https://api.github.com/users/zalando/following{/other_user}","gists_url":"https://api.github.com/users/zalando/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando/subscriptions","organizations_url":"https://api.github.com/users/zalando/orgs","repos_url":"https://api.github.com/users/zalando/repos","events_url":"https://api.github.com/users/zalando/events{/privacy}","received_events_url":"https://api.github.com/users/zalando/received_events","type":"Organization","site_admin":false},"repo":{"id":38744670,"name":"patroni","full_name":"zalando/patroni","owner":{"login":"zalando","id":1564818,"avatar_url":"https://avatars.githubusercontent.com/u/1564818?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando","html_url":"https://github.com/zalando","followers_url":"https://api.github.com/users/zalando/followers","following_url":"https://api.github.com/users/zalando/following{/other_user}","gists_url":"https://api.github.com/users/zalando/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando/subscriptions","organizations_url":"https://api.github.com/users/zalando/orgs","repos_url":"https://api.github.com/users/zalando/repos","events_url":"https://api.github.com/users/zalando/events{/privacy}","received_events_url":"https://api.github.com/users/zalando/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zalando/patroni","description":"A template for PostgreSQL High Availability with ZooKeeper, etcd or Consul","fork":false,"url":"https://api.github.com/repos/zalando/patroni","forks_url":"https://api.github.com/repos/zalando/patroni/forks","keys_url":"https://api.github.com/repos/zalando/patroni/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zalando/patroni/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zalando/patroni/teams","hooks_url":"https://api.github.com/repos/zalando/patroni/hooks","issue_events_url":"https://api.github.com/repos/zalando/patroni/issues/events{/number}","events_url":"https://api.github.com/repos/zalando/patroni/events","assignees_url":"https://api.github.com/repos/zalando/patroni/assignees{/user}","branches_url":"https://api.github.com/repos/zalando/patroni/branches{/branch}","tags_url":"https://api.github.com/repos/zalando/patroni/tags","blobs_url":"https://api.github.com/repos/zalando/patroni/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zalando/patroni/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zalando/patroni/git/refs{/sha}","trees_url":"https://api.github.com/repos/zalando/patroni/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zalando/patroni/statuses/{sha}","languages_url":"https://api.github.com/repos/zalando/patroni/languages","stargazers_url":"https://api.github.com/repos/zalando/patroni/stargazers","contributors_url":"https://api.github.com/repos/zalando/patroni/contributors","subscribers_url":"https://api.github.com/repos/zalando/patroni/subscribers","subscription_url":"https://api.github.com/repos/zalando/patroni/subscription","commits_url":"https://api.github.com/repos/zalando/patroni/commits{/sha}","git_commits_url":"https://api.github.com/repos/zalando/patroni/git/commits{/sha}","comments_url":"https://api.github.com/repos/zalando/patroni/comments{/number}","issue_comment_url":"https://api.github.com/repos/zalando/patroni/issues/comments{/number}","contents_url":"https://api.github.com/repos/zalando/patroni/contents/{+path}","compare_url":"https://api.github.com/repos/zalando/patroni/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zalando/patroni/merges","archive_url":"https://api.github.com/repos/zalando/patroni/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zalando/patroni/downloads","issues_url":"https://api.github.com/repos/zalando/patroni/issues{/number}","pulls_url":"https://api.github.com/repos/zalando/patroni/pulls{/number}","milestones_url":"https://api.github.com/repos/zalando/patroni/milestones{/number}","notifications_url":"https://api.github.com/repos/zalando/patroni/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zalando/patroni/labels{/name}","releases_url":"https://api.github.com/repos/zalando/patroni/releases{/id}","deployments_url":"https://api.github.com/repos/zalando/patroni/deployments","created_at":"2015-07-08T09:27:19Z","updated_at":"2016-07-11T08:38:49Z","pushed_at":"2016-07-11T08:51:02Z","git_url":"git://github.com/zalando/patroni.git","ssh_url":"git@github.com:zalando/patroni.git","clone_url":"https://github.com/zalando/patroni.git","svn_url":"https://github.com/zalando/patroni","homepage":"","size":1662,"stargazers_count":237,"watchers_count":237,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":24,"mirror_url":null,"open_issues_count":35,"forks":24,"open_issues":35,"watchers":237,"default_branch":"master"}},"base":{"label":"zalando:master","ref":"master","sha":"5683880de63b2ea8827d6ac62fc100103726856e","user":{"login":"zalando","id":1564818,"avatar_url":"https://avatars.githubusercontent.com/u/1564818?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando","html_url":"https://github.com/zalando","followers_url":"https://api.github.com/users/zalando/followers","following_url":"https://api.github.com/users/zalando/following{/other_user}","gists_url":"https://api.github.com/users/zalando/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando/subscriptions","organizations_url":"https://api.github.com/users/zalando/orgs","repos_url":"https://api.github.com/users/zalando/repos","events_url":"https://api.github.com/users/zalando/events{/privacy}","received_events_url":"https://api.github.com/users/zalando/received_events","type":"Organization","site_admin":false},"repo":{"id":38744670,"name":"patroni","full_name":"zalando/patroni","owner":{"login":"zalando","id":1564818,"avatar_url":"https://avatars.githubusercontent.com/u/1564818?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando","html_url":"https://github.com/zalando","followers_url":"https://api.github.com/users/zalando/followers","following_url":"https://api.github.com/users/zalando/following{/other_user}","gists_url":"https://api.github.com/users/zalando/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando/subscriptions","organizations_url":"https://api.github.com/users/zalando/orgs","repos_url":"https://api.github.com/users/zalando/repos","events_url":"https://api.github.com/users/zalando/events{/privacy}","received_events_url":"https://api.github.com/users/zalando/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zalando/patroni","description":"A template for PostgreSQL High Availability with ZooKeeper, etcd or Consul","fork":false,"url":"https://api.github.com/repos/zalando/patroni","forks_url":"https://api.github.com/repos/zalando/patroni/forks","keys_url":"https://api.github.com/repos/zalando/patroni/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zalando/patroni/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zalando/patroni/teams","hooks_url":"https://api.github.com/repos/zalando/patroni/hooks","issue_events_url":"https://api.github.com/repos/zalando/patroni/issues/events{/number}","events_url":"https://api.github.com/repos/zalando/patroni/events","assignees_url":"https://api.github.com/repos/zalando/patroni/assignees{/user}","branches_url":"https://api.github.com/repos/zalando/patroni/branches{/branch}","tags_url":"https://api.github.com/repos/zalando/patroni/tags","blobs_url":"https://api.github.com/repos/zalando/patroni/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zalando/patroni/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zalando/patroni/git/refs{/sha}","trees_url":"https://api.github.com/repos/zalando/patroni/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zalando/patroni/statuses/{sha}","languages_url":"https://api.github.com/repos/zalando/patroni/languages","stargazers_url":"https://api.github.com/repos/zalando/patroni/stargazers","contributors_url":"https://api.github.com/repos/zalando/patroni/contributors","subscribers_url":"https://api.github.com/repos/zalando/patroni/subscribers","subscription_url":"https://api.github.com/repos/zalando/patroni/subscription","commits_url":"https://api.github.com/repos/zalando/patroni/commits{/sha}","git_commits_url":"https://api.github.com/repos/zalando/patroni/git/commits{/sha}","comments_url":"https://api.github.com/repos/zalando/patroni/comments{/number}","issue_comment_url":"https://api.github.com/repos/zalando/patroni/issues/comments{/number}","contents_url":"https://api.github.com/repos/zalando/patroni/contents/{+path}","compare_url":"https://api.github.com/repos/zalando/patroni/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zalando/patroni/merges","archive_url":"https://api.github.com/repos/zalando/patroni/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zalando/patroni/downloads","issues_url":"https://api.github.com/repos/zalando/patroni/issues{/number}","pulls_url":"https://api.github.com/repos/zalando/patroni/pulls{/number}","milestones_url":"https://api.github.com/repos/zalando/patroni/milestones{/number}","notifications_url":"https://api.github.com/repos/zalando/patroni/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zalando/patroni/labels{/name}","releases_url":"https://api.github.com/repos/zalando/patroni/releases{/id}","deployments_url":"https://api.github.com/repos/zalando/patroni/deployments","created_at":"2015-07-08T09:27:19Z","updated_at":"2016-07-11T08:38:49Z","pushed_at":"2016-07-11T08:51:02Z","git_url":"git://github.com/zalando/patroni.git","ssh_url":"git@github.com:zalando/patroni.git","clone_url":"https://github.com/zalando/patroni.git","svn_url":"https://github.com/zalando/patroni","homepage":"","size":1662,"stargazers_count":237,"watchers_count":237,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":24,"mirror_url":null,"open_issues_count":35,"forks":24,"open_issues":35,"watchers":237,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/zalando/patroni/pulls/227"},"html":{"href":"https://github.com/zalando/patroni/pull/227"},"issue":{"href":"https://api.github.com/repos/zalando/patroni/issues/227"},"comments":{"href":"https://api.github.com/repos/zalando/patroni/issues/227/comments"},"review_comments":{"href":"https://api.github.com/repos/zalando/patroni/pulls/227/comments"},"review_comment":{"href":"https://api.github.com/repos/zalando/patroni/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/zalando/patroni/pulls/227/commits"},"statuses":{"href":"https://api.github.com/repos/zalando/patroni/statuses/6da2eecb9067ed950073151c443e4600b9fdff66"}}}}
{"actor":{"display_login":"CyberDem0n"}}