mirror of
https://github.com/rancher/os.git
synced 2025-07-22 02:41:33 +00:00
Implement config export
This commit is contained in:
parent
f47ea34ac4
commit
d3b42ca16c
66
cmd/control/cli.go
Normal file
66
cmd/control/cli.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package control
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/codegangsta/cli"
|
||||||
|
"github.com/rancherio/os/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Main() {
|
||||||
|
app := cli.NewApp()
|
||||||
|
|
||||||
|
app.Name = os.Args[0]
|
||||||
|
app.Usage = "Control and configure RancherOS"
|
||||||
|
app.Version = config.VERSION
|
||||||
|
app.Author = "Rancher Labs, Inc."
|
||||||
|
app.Email = "darren@rancher.com"
|
||||||
|
|
||||||
|
app.Commands = []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "config",
|
||||||
|
ShortName: "c",
|
||||||
|
Usage: "configure settings",
|
||||||
|
Subcommands: configSubcommands(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "module",
|
||||||
|
ShortName: "m",
|
||||||
|
Usage: "module settings",
|
||||||
|
Subcommands: []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "activate",
|
||||||
|
Usage: "turn on a module and possibly reboot",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "deactivate",
|
||||||
|
Usage: "turn off a module and possibly reboot",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "list",
|
||||||
|
Usage: "list modules and state",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "os",
|
||||||
|
Usage: "operating system upgrade/downgrade",
|
||||||
|
Subcommands: []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "list",
|
||||||
|
Usage: "list available RancherOS versions and state",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "update",
|
||||||
|
Usage: "download the latest new version of RancherOS",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "activate",
|
||||||
|
Usage: "switch to a new version of RancherOS and reboot",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Run(os.Args)
|
||||||
|
}
|
71
cmd/control/config.go
Normal file
71
cmd/control/config.go
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
package control
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
|
||||||
|
log "github.com/Sirupsen/logrus"
|
||||||
|
|
||||||
|
"github.com/codegangsta/cli"
|
||||||
|
"github.com/rancherio/os/config"
|
||||||
|
"github.com/rancherio/os/docker"
|
||||||
|
)
|
||||||
|
|
||||||
|
func configSubcommands() []cli.Command {
|
||||||
|
return []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "get",
|
||||||
|
Usage: "get value",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "import",
|
||||||
|
Usage: "list values",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "export",
|
||||||
|
Usage: "dump full configuration",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "output, o",
|
||||||
|
Usage: "File to which to save",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "full",
|
||||||
|
Usage: "Include full configuration, not just writable fields",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: configSave,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func configSave(c *cli.Context) {
|
||||||
|
cfg, err := config.LoadConfig()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range cfg.SystemContainers {
|
||||||
|
container := docker.NewContainer("", &c)
|
||||||
|
if container.Err != nil {
|
||||||
|
log.Fatalf("Failed to parse [%s] : %v", c.Cmd, container.Err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !c.Bool("full") {
|
||||||
|
cfg.ClearReadOnly()
|
||||||
|
}
|
||||||
|
|
||||||
|
content, err := cfg.Dump()
|
||||||
|
|
||||||
|
output := c.String("output")
|
||||||
|
if output == "" {
|
||||||
|
fmt.Println(content)
|
||||||
|
} else {
|
||||||
|
err := ioutil.WriteFile(output, []byte(content), 0400)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user