예제 #1
0
			os.Exit(-3)
		}

		params := api.TemplateParams{}
		res, err := api.TemplateFind(templateUpdateID)
		if err != nil {
			errorColor := color.New(color.FgRed, color.Bold).SprintFunc()
			fmt.Println(errorColor("An error occured:"), err.Error())
			return
		}
		params.ID = res.Path("id").Data().(string)
		params.Name = res.Path("name").Data().(string)
		params.ImageID = res.Path("image_id").Data().(string)
		params.ShortDescription = res.Path("short_description").Data().(string)
		params.Description = res.Path("description").Data().(string)
		params.CloudConfig = res.Path("cloud_config").Data().(string)

		if templateUpdateName != "" {
			params.Name = templateUpdateName
		}
		if templateUpdateImageId != "" {
			params.ImageID = templateUpdateImageId
		}
		if templateUpdateShortDescription != "" {
			params.ShortDescription = templateUpdateShortDescription
		}
		if templateUpdateDescription != "" {
			params.Description = templateUpdateDescription
		}

		if templateUpdateCloudInitFile != "" {
예제 #2
0
			os.Exit(-3)
		}

		params := api.TemplateParams{
			ID:               templateCreateID,
			Name:             templateCreateName,
			ImageID:          templateCreateImageId,
			ShortDescription: templateCreateShortDescription,
			Description:      templateCreateDescription,
		}
		if templateCreateCloudInitFile != "" {
			filename := strings.Replace(templateCreateCloudInitFile, "~", "$HOME", -1)
			filename = os.ExpandEnv(filename)
			buf, err := ioutil.ReadFile(filename)
			if err == nil {
				params.CloudConfig = string(buf)
			}
		}

		_, err := api.TemplateCreate(params)
		if err != nil {
			errorColor := color.New(color.FgRed, color.Bold).SprintFunc()
			fmt.Println(errorColor("An error occured:"), err.Error())
			return
		}
		fmt.Printf("Created template called `%s`\n", templateCreateName)
	},
}

func init() {
	templateCmd.AddCommand(templateCreateCmd)