mirror of
https://github.com/rancher/os.git
synced 2025-07-21 10:29:04 +00:00
Small cloud init fixes
This commit is contained in:
parent
bc15f3b115
commit
7f3ee5d9ef
@ -20,6 +20,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -52,17 +53,19 @@ var (
|
|||||||
outputFile string
|
outputFile string
|
||||||
save bool
|
save bool
|
||||||
sshKeyName string
|
sshKeyName string
|
||||||
|
flags *flag.FlagSet
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.StringVar(&outputDir, "dir", "/var/lib/rancher/conf", "working directory")
|
flags = flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
|
||||||
flag.StringVar(&outputFile, "file", "/var/lib/rancher/conf/cloud-config.yml", "cloud config file name")
|
flags.StringVar(&outputDir, "dir", "/var/lib/rancher/conf", "working directory")
|
||||||
flag.StringVar(&sshKeyName, "ssh-key-name", "rancheros-cloud-config", "SSH key name")
|
flags.StringVar(&outputFile, "file", "cloud-config.yml", "cloud config file name")
|
||||||
flag.BoolVar(&save, "save", false, "save cloud config and exit")
|
flags.StringVar(&sshKeyName, "ssh-key-name", "rancheros-cloud-config", "SSH key name")
|
||||||
|
flags.BoolVar(&save, "save", false, "save cloud config and exit")
|
||||||
}
|
}
|
||||||
|
|
||||||
func Main() {
|
func Main() {
|
||||||
flag.Parse()
|
flags.Parse(os.Args[1:])
|
||||||
|
|
||||||
cfg, err := rancherConfig.LoadConfig()
|
cfg, err := rancherConfig.LoadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -71,6 +74,7 @@ func Main() {
|
|||||||
|
|
||||||
dss := getDatasources(cfg)
|
dss := getDatasources(cfg)
|
||||||
if len(dss) == 0 {
|
if len(dss) == 0 {
|
||||||
|
log.Infof("No datasources available %v", cfg.CloudInit.Datasources)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +84,7 @@ func Main() {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("Fetching user-data from datasource %s", ds.Type())
|
log.Infof("Fetching user-data from datasource %v", ds.Type())
|
||||||
userdataBytes, err := ds.FetchUserdata()
|
userdataBytes, err := ds.FetchUserdata()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed fetching user-data from datasource: %v", err)
|
log.Fatalf("Failed fetching user-data from datasource: %v", err)
|
||||||
@ -139,7 +143,8 @@ func Main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ioutil.WriteFile(outputFile, fileData, 400); err != nil {
|
output := path.Join(outputDir, outputFile)
|
||||||
|
if err := ioutil.WriteFile(output, fileData, 400); err != nil {
|
||||||
log.Fatalf("Error while writing file %v", err)
|
log.Fatalf("Error while writing file %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,7 +189,7 @@ func getDatasources(cfg *rancherConfig.Config) []datasource.Datasource {
|
|||||||
dss := make([]datasource.Datasource, 0, 5)
|
dss := make([]datasource.Datasource, 0, 5)
|
||||||
|
|
||||||
for _, ds := range cfg.CloudInit.Datasources {
|
for _, ds := range cfg.CloudInit.Datasources {
|
||||||
parts := strings.SplitN(ds, ":", 1)
|
parts := strings.SplitN(ds, ":", 2)
|
||||||
|
|
||||||
switch parts[0] {
|
switch parts[0] {
|
||||||
case "ec2":
|
case "ec2":
|
||||||
|
Loading…
Reference in New Issue
Block a user