1
0
mirror of https://github.com/rancher/os.git synced 2025-06-26 06:51:40 +00:00

Implement rancherctl config import

This commit is contained in:
Darren Shepherd 2015-02-17 18:42:26 -07:00
parent 9f1a38f8c8
commit 529ce4336d
4 changed files with 73 additions and 25 deletions

View File

@ -2,7 +2,9 @@ package control
import ( import (
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"os"
"strings" "strings"
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
@ -26,8 +28,15 @@ func configSubcommands() []cli.Command {
Action: configSet, Action: configSet,
}, },
{ {
Name: "import", Name: "import",
Usage: "list values", Usage: "import configuration from standard in or a file",
Action: configImport,
Flags: []cli.Flag{
cli.StringFlag{
Name: "input, i",
Usage: "File from which to read",
},
},
}, },
{ {
Name: "export", Name: "export",
@ -64,6 +73,60 @@ func getConfigData() (map[interface{}]interface{}, error) {
return data, err return data, err
} }
func configImport(c *cli.Context) {
var input io.Reader
var err error
input = os.Stdin
inputFile := c.String("input")
if inputFile != "" {
input, err = os.Open(inputFile)
if err != nil {
log.Fatal(err)
}
}
bytes, err := ioutil.ReadAll(input)
if err != nil {
log.Fatal(err)
}
err = mergeConfig(bytes)
if err != nil {
log.Fatal(err)
}
}
func mergeConfig(bytes []byte) error {
var newConfig config.Config
err := yaml.Unmarshal(bytes, &newConfig)
if err != nil {
return err
}
cfg, err := config.LoadConfig()
if err != nil {
return err
}
reboot, err := cfg.Merge(newConfig)
if err != nil {
return err
}
err = cfg.Save()
if err != nil {
return err
}
if reboot {
fmt.Println("Reboot needed")
}
return err
}
func configSet(c *cli.Context) { func configSet(c *cli.Context) {
key := c.Args().Get(0) key := c.Args().Get(0)
value := c.Args().Get(1) value := c.Args().Get(1)
@ -79,30 +142,10 @@ func configSet(c *cli.Context) {
log.Fatal(err) log.Fatal(err)
} }
var newConfig config.Config err = mergeConfig(bytes)
err = yaml.Unmarshal(bytes, &newConfig)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
cfg, err := config.LoadConfig()
if err != nil {
log.Fatal(err)
}
reboot, err := cfg.Merge(newConfig)
if err != nil {
log.Fatal(err)
}
err = cfg.Save()
if err != nil {
log.Fatal(err)
}
if reboot {
fmt.Println("Reboot needed")
}
} }
func configGet(c *cli.Context) { func configGet(c *cli.Context) {

View File

@ -19,6 +19,7 @@ func NewConfig() *Config {
Cmd: "--name=system-state " + Cmd: "--name=system-state " +
"--net=none " + "--net=none " +
"--read-only " + "--read-only " +
"-v=/var/lib/rancher/etc:/var/lib/rancher/etc " +
"state", "state",
}, },
{ {

View File

@ -271,11 +271,14 @@ func RunInit() error {
return err return err
}, },
setResolvConf,
extractModules,
mountCgroups, mountCgroups,
extractModules,
loadModules, loadModules,
mountState, mountState,
func(cfg *config.Config) error {
return cfg.Reload()
},
setResolvConf,
createSymlinks, createSymlinks,
remountRo, remountRo,
sysInit, sysInit,

View File

@ -1,5 +1,6 @@
FROM base FROM base
VOLUME /home VOLUME /home
VOLUME /opt
VOLUME /var/lib/docker VOLUME /var/lib/docker
VOLUME /var/run VOLUME /var/run
CMD ["echo"] CMD ["echo"]