Beispiel #1
0
func saveCloudConfig() error {
	var userDataBytes []byte
	var metadata datasource.Metadata

	ds, err := currentDatasource()
	if err != nil {
		log.Errorf("Failed to select datasource: %v", err)
		return err
	}

	if ds != nil {
		log.Infof("Fetching user-data from datasource %v", ds.Type())
		userDataBytes, err = ds.FetchUserdata()
		if err != nil {
			log.Errorf("Failed fetching user-data from datasource: %v", err)
			return err
		}

		log.Infof("Fetching meta-data from datasource of type %v", ds.Type())
		metadata, err = ds.FetchMetadata()
		if err != nil {
			log.Errorf("Failed fetching meta-data from datasource: %v", err)
			return err
		}
	}

	userDataBytes = substituteUserDataVars(userDataBytes, metadata)
	userData := string(userDataBytes)
	scriptBytes := []byte{}

	if config.IsScript(userData) {
		scriptBytes = userDataBytes
		userDataBytes = []byte{}
	} else if isCompose(userData) {
		if userDataBytes, err = toCompose(userDataBytes); err != nil {
			log.Errorf("Failed to convert to compose syntax: %v", err)
			return err
		}
	} else if config.IsCloudConfig(userData) {
		if rancherConfig.ReadConfig(userDataBytes) == nil {
			log.WithFields(log.Fields{"cloud-config": userData}).Warn("Failed to parse cloud-config, not saving.")
			userDataBytes = []byte{}
		}
	} else {
		log.Errorf("Unrecognized cloud-init\n%s", userData)
		userDataBytes = []byte{}
	}

	userDataBytesMerged, scriptBytes, err := mergeBaseConfig(userDataBytes, scriptBytes)
	if err != nil {
		log.Errorf("Failed to merge base config: %v", err)
	} else if rancherConfig.ReadConfig(userDataBytesMerged) == nil {
		log.WithFields(log.Fields{"cloud-config": userData}).Warn("Failed to parse merged cloud-config, not merging.")
	} else {
		userDataBytes = userDataBytesMerged
	}

	return saveFiles(userDataBytes, scriptBytes, metadata)
}
Beispiel #2
0
func runImages(c *cli.Context) {
	configFile := c.String("input")
	cfg := config.ReadConfig(configFile)
	if cfg == nil {
		log.Fatalf("Could not read config from file %v", configFile)
	}
	images := imagesFromConfig(cfg)
	fmt.Println(strings.Join(images, " "))
}
Beispiel #3
0
func runImages(c *cli.Context) {
	configFile := c.String("input")
	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, " "))
}