1
0
mirror of https://github.com/rancher/os.git synced 2025-06-25 06:21:33 +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 (
"fmt"
"io"
"io/ioutil"
"os"
"strings"
log "github.com/Sirupsen/logrus"
@ -26,8 +28,15 @@ func configSubcommands() []cli.Command {
Action: configSet,
},
{
Name: "import",
Usage: "list values",
Name: "import",
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",
@ -64,6 +73,60 @@ func getConfigData() (map[interface{}]interface{}, error) {
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) {
key := c.Args().Get(0)
value := c.Args().Get(1)
@ -79,30 +142,10 @@ func configSet(c *cli.Context) {
log.Fatal(err)
}
var newConfig config.Config
err = yaml.Unmarshal(bytes, &newConfig)
err = mergeConfig(bytes)
if err != nil {
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) {

View File

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

View File

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

View File

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