func NewUserTask(name string, contents string, meta string) (fi.Task, error) { s := &UserTask{Name: name} err := utils.YamlUnmarshal([]byte(contents), s) if err != nil { return nil, fmt.Errorf("error parsing json for service %q: %v", name, err) } return s, nil }
func (c *CreateClusterCmd) LoadConfig(configFile string) error { conf, err := ioutil.ReadFile(configFile) if err != nil { return fmt.Errorf("error loading configuration file %q: %v", configFile, err) } err = utils.YamlUnmarshal(conf, c.Cluster) if err != nil { return fmt.Errorf("error parsing configuration file %q: %v", configFile, err) } return nil }
func (l *Loader) loadYamlObjects(key string, data string) (map[string]interface{}, error) { var o map[string]interface{} if strings.TrimSpace(data) != "" { err := utils.YamlUnmarshal([]byte(data), &o) if err != nil { // TODO: It would be nice if yaml returned us the line number here glog.Infof("error parsing yaml. yaml follows:") for i, line := range strings.Split(string(data), "\n") { fmt.Fprintf(os.Stderr, "%3d: %s\n", i, line) } return nil, fmt.Errorf("error parsing yaml %q: %v", key, err) } } return l.loadObjectMap(key, o) }
func NewFileTask(name string, src fi.Resource, destPath string, meta string) (*File, error) { f := &File{ //Name: name, Contents: src, Path: destPath, } if meta != "" { err := utils.YamlUnmarshal([]byte(meta), f) if err != nil { return nil, fmt.Errorf("error parsing meta for file %q: %v", name, err) } } if f.Symlink != nil && f.Type == "" { f.Type = FileType_Symlink } return f, nil }
func (s *VFSStateStore) ReadConfig(path string, config interface{}) error { configPath := s.location.Join(path) data, err := configPath.ReadFile() if err != nil { if os.IsNotExist(err) { return nil } return fmt.Errorf("error reading configuration file %s: %v", configPath, err) } // Yaml can't parse empty strings configString := string(data) configString = strings.TrimSpace(configString) if configString != "" { err = utils.YamlUnmarshal([]byte(configString), config) if err != nil { return fmt.Errorf("error parsing configuration: %v", err) } } return nil }
func (c *NodeUpCommand) Run(out io.Writer) error { if c.FSRoot == "" { return fmt.Errorf("FSRoot is required") } if c.ConfigLocation != "" { config, err := vfs.Context.ReadFile(c.ConfigLocation) if err != nil { return fmt.Errorf("error loading configuration %q: %v", c.ConfigLocation, err) } err = utils.YamlUnmarshal(config, &c.config) if err != nil { return fmt.Errorf("error parsing configuration %q: %v", c.ConfigLocation, err) } } else { return fmt.Errorf("ConfigLocation is required") } if c.AssetDir == "" { return fmt.Errorf("AssetDir is required") } assets := fi.NewAssetStore(c.AssetDir) for _, asset := range c.config.Assets { err := assets.Add(asset) if err != nil { return fmt.Errorf("error adding asset %q: %v", asset, err) } } //c.nodeset = &cloudup.NodeSetConfig{} //if c.config.NodeSetLocation != "" { // b, err := vfs.Context.ReadFile(c.config.NodeSetLocation) // if err != nil { // return fmt.Errorf("error loading NodeSet %q: %v", c.config.NodeSetLocation, err) // } // // err = utils.YamlUnmarshal(b, c.nodeset) // if err != nil { // return fmt.Errorf("error parsing NodeSet %q: %v", c.config.NodeSetLocation, err) // } //} else { // return fmt.Errorf("NodeSetLocation is required") //} c.cluster = &api.Cluster{} if c.config.ClusterLocation != "" { b, err := vfs.Context.ReadFile(c.config.ClusterLocation) if err != nil { return fmt.Errorf("error loading Cluster %q: %v", c.config.ClusterLocation, err) } err = utils.YamlUnmarshal(b, c.cluster) if err != nil { return fmt.Errorf("error parsing Cluster %q: %v", c.config.ClusterLocation, err) } } else { // TODO Infer this from NodeSetLocation? return fmt.Errorf("ClusterLocation is required") } //if c.Config.ConfigurationStore != "" { // // TODO: If we ever delete local files, we need to filter so we only copy // // certain directories (i.e. not secrets / keys), because dest is a parent dir! // p, err := c.buildPath(c.Config.ConfigurationStore) // if err != nil { // return fmt.Errorf("error building config store: %v", err) // } // // dest := vfs.NewFSPath("/etc/kubernetes") // scanner := vfs.NewVFSScan(p) // err = vfs.SyncDir(scanner, dest) // if err != nil { // return fmt.Errorf("error copying config store: %v", err) // } // // c.Config.Tags = append(c.Config.Tags, "_config_store") //} else { // c.Config.Tags = append(c.Config.Tags, "_not_config_store") //} osTags, err := FindOSTags(c.FSRoot) if err != nil { return fmt.Errorf("error determining OS tags: %v", err) } tags := make(map[string]struct{}) for _, tag := range osTags { tags[tag] = struct{}{} } for _, tag := range c.config.Tags { tags[tag] = struct{}{} } loader := NewLoader(c.config, c.cluster, assets, tags) tf, err := newTemplateFunctions(c.config, c.cluster, tags) if err != nil { return fmt.Errorf("error initializing: %v", err) } tf.populate(loader.TemplateFunctions) taskMap, err := loader.Build(c.ModelDir) if err != nil { return fmt.Errorf("error building loader: %v", err) } var cloud fi.Cloud var caStore fi.CAStore var secretStore fi.SecretStore var target fi.Target checkExisting := true switch c.Target { case "direct": target = &local.LocalTarget{} case "dryrun": target = fi.NewDryRunTarget(out) case "cloudinit": checkExisting = false target = cloudinit.NewCloudInitTarget(out) default: return fmt.Errorf("unsupported target type %q", c.Target) } context, err := fi.NewContext(target, cloud, caStore, secretStore, checkExisting) if err != nil { glog.Exitf("error building context: %v", err) } defer context.Close() err = context.RunTasks(taskMap) if err != nil { glog.Exitf("error running tasks: %v", err) } err = target.Finish(taskMap) if err != nil { glog.Exitf("error closing target: %v", err) } return nil }