1
0
mirror of https://github.com/rancher/os.git synced 2025-09-01 14:48:55 +00:00

Reshuffle cloud-config

Read files cloud-config.d in alphanumeric order, then cloud-config.yml
`ros config` writes to cloud-config.yml (and cloud-config.d/private.yml - only private keys)

Add (c *CloudConfig) Save() method, use it to save the changed config

Read and apply metadata as part of LoadConfig()

Simplify ros config export logic
This commit is contained in:
Ivan Mikushin
2015-09-23 16:36:28 +05:00
parent 0ac4c783f9
commit 338abb758f
20 changed files with 658 additions and 695 deletions

View File

@@ -57,13 +57,17 @@ func configSubcommands() []cli.Command {
Name: "output, o",
Usage: "File to which to save",
},
cli.BoolFlag{
Name: "boot, b",
Usage: "Include cloud-config provided at boot",
},
cli.BoolFlag{
Name: "private, p",
Usage: "Include private information such as keys",
Usage: "Include the generated private keys",
},
cli.BoolFlag{
Name: "full, f",
Usage: "Include full configuration, including internal and default settings",
Usage: "Export full configuration, including internal and default settings",
},
},
Action: export,
@@ -101,9 +105,9 @@ func imagesFromConfig(cfg *config.CloudConfig) []string {
func runImages(c *cli.Context) {
configFile := c.String("input")
cfg := config.ReadConfig(nil, configFile)
if cfg == nil {
log.Fatalf("Could not read config from file %v", configFile)
cfg, err := config.ReadConfig(nil, false, configFile)
if err != nil {
log.WithFields(log.Fields{"err": err, "file": configFile}).Fatalf("Could not read config from file")
}
images := imagesFromConfig(cfg)
fmt.Println(strings.Join(images, " "))
@@ -133,10 +137,14 @@ func runImport(c *cli.Context) {
log.Fatal(err)
}
err = cfg.Import(bytes)
cfg, err = cfg.Import(bytes)
if err != nil {
log.Fatal(err)
}
if err := cfg.Save(); err != nil {
log.Fatal(err)
}
}
func configSet(c *cli.Context) {
@@ -151,10 +159,14 @@ func configSet(c *cli.Context) {
log.Fatal(err)
}
err = cfg.Set(key, value)
cfg, err = cfg.Set(key, value)
if err != nil {
log.Fatal(err)
}
if err := cfg.Save(); err != nil {
log.Fatal(err)
}
}
func configGet(c *cli.Context) {
@@ -203,14 +215,18 @@ func merge(c *cli.Context) {
log.Fatal(err)
}
err = cfg.Merge(bytes)
cfg, err = cfg.MergeBytes(bytes)
if err != nil {
log.Fatal(err)
}
if err := cfg.Save(); err != nil {
log.Fatal(err)
}
}
func export(c *cli.Context) {
content, err := config.Dump(c.Bool("private"), c.Bool("full"))
content, err := config.Dump(c.Bool("boot"), c.Bool("private"), c.Bool("full"))
if err != nil {
log.Fatal(err)
}