GitHub PullRequestReviewCommentEvent at 2014-09-18 15:59:46
Repository: juju
Actor: fwereade
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/juju/juju/pulls/comments/17736361","id":17736361,"diff_hunk":"@@ -0,0 +1,206 @@\n+package reboot\n+\n+import (\n+\t\"os/exec\"\n+\t\"regexp\"\n+\t\"runtime\"\n+\t\"time\"\n+\n+\t\"github.com/juju/loggo\"\n+\t\"github.com/juju/names\"\n+\n+\t\"github.com/juju/juju/agent\"\n+\t\"github.com/juju/juju/api\"\n+\t\"github.com/juju/juju/api/reboot\"\n+\t\"github.com/juju/juju/container\"\n+\t\"github.com/juju/juju/container/factory\"\n+\t\"github.com/juju/juju/container/kvm\"\n+\t\"github.com/juju/juju/instance\"\n+\t\"github.com/juju/juju/service\"\n+\t\"github.com/juju/juju/service/common\"\n+\t\"github.com/juju/juju/service/upstart\"\n+\t\"github.com/juju/juju/state\"\n+)\n+\n+var logger = loggo.GetLogger(\"juju.cmd.jujud.reboot\")\n+var unitRe = regexp.MustCompile(\"^(jujud-.*unit-([a-z0-9-]+)-([0-9]+))$\")\n+\n+func runCommand(args []string) error {\n+\t_, err := exec.Command(args[0], args[1:]...).Output()\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\treturn nil\n+}\n+\n+func isUnit(val string) bool {\n+\tif groups := unitRe.FindStringSubmatch(val); len(groups) > 0 {\n+\t\treturn true\n+\t}\n+\treturn false\n+}\n+\n+type Reboot struct {\n+\tacfg     agent.Config\n+\tst       *reboot.State\n+\ttag      names.MachineTag\n+\tapistate *api.State\n+}\n+\n+func NewRebootWaiter(apistate *api.State, acfg agent.Config, tag names.MachineTag) *Reboot {\n+\trebootState := apistate.Reboot()\n+\treturn &Reboot{\n+\t\tacfg:     acfg,\n+\t\tst:       rebootState,\n+\t\ttag:      tag,\n+\t\tapistate: apistate,\n+\t}\n+}\n+\n+func (r *Reboot) ExecuteReboot() error {\n+\tst := r.apistate.Reboot()\n+\taction, err := st.GetRebootAction()\n+\tif err != nil {\n+\t\tlogger.Errorf(\"Reboot: Error getting reboot action: %v\", err)\n+\t\treturn err\n+\t}\n+\n+\terr = r.waitForContainersOrTimeout()\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\t// TODO (gsamfira): Maybe we should clear the flag before issuing the reboot?\n+\t//\n+\t// Execute reboot or shutdown. We do this after 10 seconds\n+\t// to allow the machine agent to clear its reboot flag\n+\tdelayBeforeAction := 10\n+\tc := scheduleReboot(action, delayBeforeAction)\n+\n+\t// Clear the reboot flag.\n+\terr = r.st.ClearReboot()\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\t// Wait for the reboot to return\n+\terr = <-c\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\treturn nil\n+}\n+\n+func (r *Reboot) StopAllUnits() error {\n+\tservices, err := service.ListServices(upstart.InitDir)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\tlogger.Infof(\"Trying to stop units\")\n+\tfor _, val := range services {\n+\t\tif !isUnit(val) {\n+\t\t\tcontinue\n+\t\t}\n+\t\tcfg := common.Conf{InitDir: upstart.InitDir}\n+\t\tsvc := service.NewService(val, cfg)\n+\t\tlogger.Infof(\"Stopping unit: %v\", val)\n+\t\terr = svc.Stop()\n+\t\tif err != nil {\n+\t\t\tlogger.Warningf(\"Failed to stop service %q: %q\", val, err)\n+\t\t}\n+\t}\n+\treturn nil\n+}\n+\n+func (r *Reboot) supportedContainers() ([]instance.ContainerType, error) {\n+\tvar supportedContainers []instance.ContainerType\n+\n+\tentity, err := r.apistate.Agent().Entity(r.tag)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\tif entity.ContainerType() != instance.LXC && runtime.GOOS != \"windows\" {\n+\t\tsupportedContainers = append(supportedContainers, instance.LXC)\n+\t}\n+\tsupportsKvm, err := kvm.IsKVMSupported()\n+\tif err == nil && supportsKvm {\n+\t\tsupportedContainers = append(supportedContainers, instance.KVM)\n+\t}\n+\treturn supportedContainers, nil\n+}\n+\n+func (r *Reboot) runningContainers() ([]instance.Instance, error) {\n+\trunningInstances := []instance.Instance{}\n+\tsupportedContainers, err := r.supportedContainers()\n+\tif err != nil {\n+\t\treturn runningInstances, err\n+\t}\n+\tif len(supportedContainers) == 0 {\n+\t\treturn runningInstances, nil\n+\t}\n+\n+\tfor _, val := range supportedContainers {\n+\t\tmanagerConfig := container.ManagerConfig{container.ConfigName: \"juju\"}\n+\t\tif namespace := r.acfg.Value(agent.Namespace); namespace != \"\" {\n+\t\t\tmanagerConfig[container.ConfigName] = namespace\n+\t\t}\n+\t\tcfg := container.ManagerConfig(managerConfig)\n+\t\tmanager, err := factory.NewContainerManager(val, cfg)\n+\t\tif err != nil {\n+\t\t\tlogger.Warningf(\"Failed to get manager for container type %v: %v\", val, err)\n+\t\t\tcontinue\n+\t\t}\n+\t\tinstances, err := manager.ListContainers()\n+\t\tif err != nil {\n+\t\t\tlogger.Warningf(\"Failed to list containers: %v\", err)\n+\t\t}\n+\t\trunningInstances = append(runningInstances, instances...)\n+\t}\n+\treturn runningInstances, nil\n+}\n+\n+func (r *Reboot) waitForContainersOrTimeout() error {\n+\ttimeout := 0 * time.Minute\n+\tnestingLvl := state.NestingLevel(r.tag.Id())\n+\tswitch nestingLvl {\n+\tcase 0:\n+\t\t// wait a maximum of 10 minutes if we are bare metal\n+\t\t// We need to wait for our containers to shutdown, which\n+\t\t// in turn may have containers of its own to shutdown\n+\t\ttimeout = 10 * time.Minute\n+\tcase 1:\n+\t\t// We are first level containers. Allow for out containers\n+\t\t// to shutdown before returning\n+\t\ttimeout = 5 * time.Minute\n+\tcase 2:\n+\t\t// Maximum nesting level. No containers can exist here (yet)","path":"cmd/jujud/reboot/reboot.go","position":175,"original_position":175,"commit_id":"59944af318cbcc302fc1ef7ba9ace77a2471af0b","original_commit_id":"59944af318cbcc302fc1ef7ba9ace77a2471af0b","user":{"login":"fwereade","id":372078,"avatar_url":"https://avatars.githubusercontent.com/u/372078?v=2","gravatar_id":"03af18c15a18647cba5a741110e84bfa","url":"https://api.github.com/users/fwereade","html_url":"https://github.com/fwereade","followers_url":"https://api.github.com/users/fwereade/followers","following_url":"https://api.github.com/users/fwereade/following{/other_user}","gists_url":"https://api.github.com/users/fwereade/gists{/gist_id}","starred_url":"https://api.github.com/users/fwereade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fwereade/subscriptions","organizations_url":"https://api.github.com/users/fwereade/orgs","repos_url":"https://api.github.com/users/fwereade/repos","events_url":"https://api.github.com/users/fwereade/events{/privacy}","received_events_url":"https://api.github.com/users/fwereade/received_events","type":"User","site_admin":false},"body":"/me raises eyebrow","created_at":"2014-09-18T15:59:46Z","updated_at":"2014-09-18T15:59:46Z","html_url":"https://github.com/juju/juju/pull/782#discussion_r17736361","pull_request_url":"https://api.github.com/repos/juju/juju/pulls/782","_links":{"self":{"href":"https://api.github.com/repos/juju/juju/pulls/comments/17736361"},"html":{"href":"https://github.com/juju/juju/pull/782#discussion_r17736361"},"pull_request":{"href":"https://api.github.com/repos/juju/juju/pulls/782"}}},"pull_request":{"url":"https://api.github.com/repos/juju/juju/pulls/782","id":21405703,"html_url":"https://github.com/juju/juju/pull/782","diff_url":"https://github.com/juju/juju/pull/782.diff","patch_url":"https://github.com/juju/juju/pull/782.patch","issue_url":"https://api.github.com/repos/juju/juju/issues/782","number":782,"state":"open","locked":false,"title":"WiP: initial reboot worker and uniter","user":{"login":"gabriel-samfira","id":903160,"avatar_url":"https://avatars.githubusercontent.com/u/903160?v=2","gravatar_id":"13d9239250c467304917edc76a5af163","url":"https://api.github.com/users/gabriel-samfira","html_url":"https://github.com/gabriel-samfira","followers_url":"https://api.github.com/users/gabriel-samfira/followers","following_url":"https://api.github.com/users/gabriel-samfira/following{/other_user}","gists_url":"https://api.github.com/users/gabriel-samfira/gists{/gist_id}","starred_url":"https://api.github.com/users/gabriel-samfira/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gabriel-samfira/subscriptions","organizations_url":"https://api.github.com/users/gabriel-samfira/orgs","repos_url":"https://api.github.com/users/gabriel-samfira/repos","events_url":"https://api.github.com/users/gabriel-samfira/events{/privacy}","received_events_url":"https://api.github.com/users/gabriel-samfira/received_events","type":"User","site_admin":false},"body":"This is the final PR for the reboot functionallity. It add a Reboot worker that waits for the machines reboot flag to be changed, and reacts. It also adds the tool to trigger the reboot.\r\n\r\n The juju-reboot command has only one option\r\n\r\nTo trigger a reboot immediately, use:\r\n\r\n```shell\r\njuju-reboot --now\r\n```\r\n\r\nThis will block untill the unit agent kills the hook invoking this tool. If ```--now``` is used, the hook calling this tool will be requeued. Omitting this flag, will allow the hook to finish and only then reboot.\r\n\r\nThis branch depends on:\r\n\r\nhttps://github.com/juju/juju/pull/707\r\nhttps://github.com/juju/juju/pull/728\r\nhttps://github.com/juju/juju/pull/744","created_at":"2014-09-18T00:33:24Z","updated_at":"2014-09-18T15:59:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7860d82f7cea63e7f21b420da18fbbdc84357f56","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/juju/juju/pulls/782/commits","review_comments_url":"https://api.github.com/repos/juju/juju/pulls/782/comments","review_comment_url":"https://api.github.com/repos/juju/juju/pulls/comments/{number}","comments_url":"https://api.github.com/repos/juju/juju/issues/782/comments","statuses_url":"https://api.github.com/repos/juju/juju/statuses/59944af318cbcc302fc1ef7ba9ace77a2471af0b","head":{"label":"gabriel-samfira:reboot-worker","ref":"reboot-worker","sha":"59944af318cbcc302fc1ef7ba9ace77a2471af0b","user":{"login":"gabriel-samfira","id":903160,"avatar_url":"https://avatars.githubusercontent.com/u/903160?v=2","gravatar_id":"13d9239250c467304917edc76a5af163","url":"https://api.github.com/users/gabriel-samfira","html_url":"https://github.com/gabriel-samfira","followers_url":"https://api.github.com/users/gabriel-samfira/followers","following_url":"https://api.github.com/users/gabriel-samfira/following{/other_user}","gists_url":"https://api.github.com/users/gabriel-samfira/gists{/gist_id}","starred_url":"https://api.github.com/users/gabriel-samfira/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gabriel-samfira/subscriptions","organizations_url":"https://api.github.com/users/gabriel-samfira/orgs","repos_url":"https://api.github.com/users/gabriel-samfira/repos","events_url":"https://api.github.com/users/gabriel-samfira/events{/privacy}","received_events_url":"https://api.github.com/users/gabriel-samfira/received_events","type":"User","site_admin":false},"repo":{"id":20686648,"name":"juju","full_name":"gabriel-samfira/juju","owner":{"login":"gabriel-samfira","id":903160,"avatar_url":"https://avatars.githubusercontent.com/u/903160?v=2","gravatar_id":"13d9239250c467304917edc76a5af163","url":"https://api.github.com/users/gabriel-samfira","html_url":"https://github.com/gabriel-samfira","followers_url":"https://api.github.com/users/gabriel-samfira/followers","following_url":"https://api.github.com/users/gabriel-samfira/following{/other_user}","gists_url":"https://api.github.com/users/gabriel-samfira/gists{/gist_id}","starred_url":"https://api.github.com/users/gabriel-samfira/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gabriel-samfira/subscriptions","organizations_url":"https://api.github.com/users/gabriel-samfira/orgs","repos_url":"https://api.github.com/users/gabriel-samfira/repos","events_url":"https://api.github.com/users/gabriel-samfira/events{/privacy}","received_events_url":"https://api.github.com/users/gabriel-samfira/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gabriel-samfira/juju","description":"juju is devops distilled","fork":true,"url":"https://api.github.com/repos/gabriel-samfira/juju","forks_url":"https://api.github.com/repos/gabriel-samfira/juju/forks","keys_url":"https://api.github.com/repos/gabriel-samfira/juju/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gabriel-samfira/juju/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gabriel-samfira/juju/teams","hooks_url":"https://api.github.com/repos/gabriel-samfira/juju/hooks","issue_events_url":"https://api.github.com/repos/gabriel-samfira/juju/issues/events{/number}","events_url":"https://api.github.com/repos/gabriel-samfira/juju/events","assignees_url":"https://api.github.com/repos/gabriel-samfira/juju/assignees{/user}","branches_url":"https://api.github.com/repos/gabriel-samfira/juju/branches{/branch}","tags_url":"https://api.github.com/repos/gabriel-samfira/juju/tags","blobs_url":"https://api.github.com/repos/gabriel-samfira/juju/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gabriel-samfira/juju/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gabriel-samfira/juju/git/refs{/sha}","trees_url":"https://api.github.com/repos/gabriel-samfira/juju/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gabriel-samfira/juju/statuses/{sha}","languages_url":"https://api.github.com/repos/gabriel-samfira/juju/languages","stargazers_url":"https://api.github.com/repos/gabriel-samfira/juju/stargazers","contributors_url":"https://api.github.com/repos/gabriel-samfira/juju/contributors","subscribers_url":"https://api.github.com/repos/gabriel-samfira/juju/subscribers","subscription_url":"https://api.github.com/repos/gabriel-samfira/juju/subscription","commits_url":"https://api.github.com/repos/gabriel-samfira/juju/commits{/sha}","git_commits_url":"https://api.github.com/repos/gabriel-samfira/juju/git/commits{/sha}","comments_url":"https://api.github.com/repos/gabriel-samfira/juju/comments{/number}","issue_comment_url":"https://api.github.com/repos/gabriel-samfira/juju/issues/comments/{number}","contents_url":"https://api.github.com/repos/gabriel-samfira/juju/contents/{+path}","compare_url":"https://api.github.com/repos/gabriel-samfira/juju/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gabriel-samfira/juju/merges","archive_url":"https://api.github.com/repos/gabriel-samfira/juju/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gabriel-samfira/juju/downloads","issues_url":"https://api.github.com/repos/gabriel-samfira/juju/issues{/number}","pulls_url":"https://api.github.com/repos/gabriel-samfira/juju/pulls{/number}","milestones_url":"https://api.github.com/repos/gabriel-samfira/juju/milestones{/number}","notifications_url":"https://api.github.com/repos/gabriel-samfira/juju/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gabriel-samfira/juju/labels{/name}","releases_url":"https://api.github.com/repos/gabriel-samfira/juju/releases{/id}","created_at":"2014-06-10T13:41:36Z","updated_at":"2014-08-01T13:48:50Z","pushed_at":"2014-09-18T08:38:45Z","git_url":"git://github.com/gabriel-samfira/juju.git","ssh_url":"git@github.com:gabriel-samfira/juju.git","clone_url":"https://github.com/gabriel-samfira/juju.git","svn_url":"https://github.com/gabriel-samfira/juju","homepage":"juju.ubuntu.com","size":31108,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"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":"juju:master","ref":"master","sha":"ae6e4a8014db774583c4a39abdca8ec3a25f71b5","user":{"login":"juju","id":4604548,"avatar_url":"https://avatars.githubusercontent.com/u/4604548?v=2","gravatar_id":"b095d1e26e5705abe0ad2de7d87aac2e","url":"https://api.github.com/users/juju","html_url":"https://github.com/juju","followers_url":"https://api.github.com/users/juju/followers","following_url":"https://api.github.com/users/juju/following{/other_user}","gists_url":"https://api.github.com/users/juju/gists{/gist_id}","starred_url":"https://api.github.com/users/juju/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juju/subscriptions","organizations_url":"https://api.github.com/users/juju/orgs","repos_url":"https://api.github.com/users/juju/repos","events_url":"https://api.github.com/users/juju/events{/privacy}","received_events_url":"https://api.github.com/users/juju/received_events","type":"Organization","site_admin":false},"repo":{"id":20445947,"name":"juju","full_name":"juju/juju","owner":{"login":"juju","id":4604548,"avatar_url":"https://avatars.githubusercontent.com/u/4604548?v=2","gravatar_id":"b095d1e26e5705abe0ad2de7d87aac2e","url":"https://api.github.com/users/juju","html_url":"https://github.com/juju","followers_url":"https://api.github.com/users/juju/followers","following_url":"https://api.github.com/users/juju/following{/other_user}","gists_url":"https://api.github.com/users/juju/gists{/gist_id}","starred_url":"https://api.github.com/users/juju/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juju/subscriptions","organizations_url":"https://api.github.com/users/juju/orgs","repos_url":"https://api.github.com/users/juju/repos","events_url":"https://api.github.com/users/juju/events{/privacy}","received_events_url":"https://api.github.com/users/juju/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/juju/juju","description":"juju is devops distilled","fork":false,"url":"https://api.github.com/repos/juju/juju","forks_url":"https://api.github.com/repos/juju/juju/forks","keys_url":"https://api.github.com/repos/juju/juju/keys{/key_id}","collaborators_url":"https://api.github.com/repos/juju/juju/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/juju/juju/teams","hooks_url":"https://api.github.com/repos/juju/juju/hooks","issue_events_url":"https://api.github.com/repos/juju/juju/issues/events{/number}","events_url":"https://api.github.com/repos/juju/juju/events","assignees_url":"https://api.github.com/repos/juju/juju/assignees{/user}","branches_url":"https://api.github.com/repos/juju/juju/branches{/branch}","tags_url":"https://api.github.com/repos/juju/juju/tags","blobs_url":"https://api.github.com/repos/juju/juju/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/juju/juju/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/juju/juju/git/refs{/sha}","trees_url":"https://api.github.com/repos/juju/juju/git/trees{/sha}","statuses_url":"https://api.github.com/repos/juju/juju/statuses/{sha}","languages_url":"https://api.github.com/repos/juju/juju/languages","stargazers_url":"https://api.github.com/repos/juju/juju/stargazers","contributors_url":"https://api.github.com/repos/juju/juju/contributors","subscribers_url":"https://api.github.com/repos/juju/juju/subscribers","subscription_url":"https://api.github.com/repos/juju/juju/subscription","commits_url":"https://api.github.com/repos/juju/juju/commits{/sha}","git_commits_url":"https://api.github.com/repos/juju/juju/git/commits{/sha}","comments_url":"https://api.github.com/repos/juju/juju/comments{/number}","issue_comment_url":"https://api.github.com/repos/juju/juju/issues/comments/{number}","contents_url":"https://api.github.com/repos/juju/juju/contents/{+path}","compare_url":"https://api.github.com/repos/juju/juju/compare/{base}...{head}","merges_url":"https://api.github.com/repos/juju/juju/merges","archive_url":"https://api.github.com/repos/juju/juju/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/juju/juju/downloads","issues_url":"https://api.github.com/repos/juju/juju/issues{/number}","pulls_url":"https://api.github.com/repos/juju/juju/pulls{/number}","milestones_url":"https://api.github.com/repos/juju/juju/milestones{/number}","notifications_url":"https://api.github.com/repos/juju/juju/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/juju/juju/labels{/name}","releases_url":"https://api.github.com/repos/juju/juju/releases{/id}","created_at":"2014-06-03T14:28:10Z","updated_at":"2014-09-14T02:01:56Z","pushed_at":"2014-09-18T13:45:51Z","git_url":"git://github.com/juju/juju.git","ssh_url":"git@github.com:juju/juju.git","clone_url":"https://github.com/juju/juju.git","svn_url":"https://github.com/juju/juju","homepage":"juju.ubuntu.com","size":46812,"stargazers_count":206,"watchers_count":206,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":57,"mirror_url":null,"open_issues_count":63,"forks":57,"open_issues":63,"watchers":206,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/juju/juju/pulls/782"},"html":{"href":"https://github.com/juju/juju/pull/782"},"issue":{"href":"https://api.github.com/repos/juju/juju/issues/782"},"comments":{"href":"https://api.github.com/repos/juju/juju/issues/782/comments"},"review_comments":{"href":"https://api.github.com/repos/juju/juju/pulls/782/comments"},"review_comment":{"href":"https://api.github.com/repos/juju/juju/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/juju/juju/pulls/782/commits"},"statuses":{"href":"https://api.github.com/repos/juju/juju/statuses/59944af318cbcc302fc1ef7ba9ace77a2471af0b"}}}}