1
0
mirror of https://github.com/rancher/os.git synced 2025-09-02 23:34:57 +00:00

Move more commands to subcommands of ros

This commit is contained in:
Josh Curl
2016-10-20 11:58:34 -07:00
parent b767e5e1a7
commit 21fb3ebfa9
10 changed files with 78 additions and 59 deletions

View File

@@ -0,0 +1,48 @@
package control
import (
"errors"
log "github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
"github.com/docker/libcompose/project/options"
"github.com/rancher/os/compose"
"github.com/rancher/os/config"
"golang.org/x/net/context"
)
func switchConsoleAction(c *cli.Context) error {
if len(c.Args()) != 1 {
return errors.New("Must specify exactly one existing container")
}
newConsole := c.Args()[0]
cfg := config.LoadConfig()
project, err := compose.GetProject(cfg, true, false)
if err != nil {
return err
}
if newConsole != "default" {
if err = compose.LoadSpecialService(project, cfg, "console", newConsole); err != nil {
return err
}
}
if err = config.Set("rancher.console", newConsole); err != nil {
log.Errorf("Failed to update 'rancher.console': %v", err)
}
if err = project.Up(context.Background(), options.Up{
Log: true,
}, "console"); err != nil {
return err
}
if err = project.Restart(context.Background(), 10, "docker"); err != nil {
log.Errorf("Failed to restart Docker: %v", err)
}
return nil
}