コード例 #1
0
ファイル: stack-configure.go プロジェクト: sgtpepper43/cx
func runUploadManifestYaml(c *cli.Context, stackUid string) {
	manifestYamlFile := c.Args().First()
	if manifestYamlFile == "" {
		printFatal("manifest_yaml file path is required")
	} else {
		manifestYamlFile = expandPath(manifestYamlFile)
	}
	manifestYamlBytes, err := ioutil.ReadFile(manifestYamlFile)
	must(err)
	manifestYaml := string(manifestYamlBytes)

	comments := c.String("comments")
	if comments == "" {
		fmt.Println("\nComments can't be blank, Please add one:")
		if term.IsTerminal(os.Stdin) {
			fmt.Printf("> ")
		}

		reader := bufio.NewReader(os.Stdin)
		if comments, err = reader.ReadString('\n'); err != nil {
			printFatal(err.Error())
		}
	}

	_, err = client.CreateManifestYaml(stackUid, manifestYaml, comments)
	must(err)
}
コード例 #2
0
ファイル: stack-create.go プロジェクト: sgtpepper43/cx
func askForCloud(accountInfo cloud66.Account) (*cloud66.Cloud, error) {
	cloudsInfo, err := client.GetCloudsInfo()
	if err != nil {
		return nil, errors.New("No available cloud providers in current account, please add via the Cloud 66 UI")
	}

	fmt.Println("\nPlease select your target cloud:")
	cloudMap := make(map[string]cloud66.Cloud)
	for index, usedCloud := range cloudsInfo {
		stringIndex := strconv.Itoa(index + 1)
		cloudMap[stringIndex] = usedCloud
		fmt.Printf("%s. %s (%s)\n", stringIndex, usedCloud.Id, usedCloud.KeyName)
	}
	if term.IsTerminal(os.Stdin) {
		fmt.Printf("> ")
	}
	var selection string
	if _, err := fmt.Scanln(&selection); err != nil {
		printFatal(err.Error())
	}
	cloudInfo := cloudMap[selection]
	if cloudInfo.Id == "" {
		return nil, errors.New("Invalid selection!")
	}
	return &cloudInfo, nil
}
コード例 #3
0
ファイル: stack-create.go プロジェクト: sgtpepper43/cx
func askForSizeAndRegion(cloudInfo cloud66.Cloud) (string, string, error) {
	fmt.Println("\nPlease select your cloud region:")
	regionMap := make(map[string]string)
	for index, region := range cloudInfo.Regions {
		stringIndex := strconv.Itoa(index + 1)
		regionMap[stringIndex] = region.Id
		fmt.Printf("%s. %s\n", stringIndex, region.Name)
	}
	if term.IsTerminal(os.Stdin) {
		fmt.Printf("> ")
	}
	var selection string
	if _, err := fmt.Scanln(&selection); err != nil {
		printFatal(err.Error())
	}
	if regionMap[selection] == "" {
		return "", "", errors.New("Invalid selection!")
	}
	// store for return
	region := regionMap[selection]

	fmt.Println("\nPlease select your server size:")
	sizeMap := make(map[string]string)
	for index, serverSize := range cloudInfo.ServerSizes {
		stringIndex := strconv.Itoa(index + 1)
		sizeMap[stringIndex] = serverSize.Id
		fmt.Printf("%s. %s\n", stringIndex, serverSize.Name)
	}
	if term.IsTerminal(os.Stdin) {
		fmt.Printf("> ")
	}
	if _, err := fmt.Scanln(&selection); err != nil {
		printFatal(err.Error())
	}
	if sizeMap[selection] == "" {
		return "", "", errors.New("Invalid selection!")
	}
	// store for return
	size := sizeMap[selection]

	return region, size, nil
}
コード例 #4
0
ファイル: util.go プロジェクト: magiccreater/cx
func mustConfirm(warning, desired string) {
	if term.IsTerminal(os.Stdin) {
		printWarning(warning)
		fmt.Printf("> ")
	}
	var confirm string
	if _, err := fmt.Scanln(&confirm); err != nil {
		printFatal(err.Error())
	}

	if confirm != desired {
		printFatal("Confirmation did not match %q.", desired)
	}
}
コード例 #5
0
ファイル: stack-create.go プロジェクト: sgtpepper43/cx
// values are standalone or dedicated
func askForBuildType() (string, error) {
	fmt.Println("\nPlease select your server build type: ")

	serverMap := make(map[string]string)
	serverMap["1"] = "multi"
	fmt.Printf("1. %s\n", "Each database type on its own server")
	serverMap["2"] = "single"
	fmt.Printf("2. %s\n", "Everything on a single server (not recommended for production)")
	if term.IsTerminal(os.Stdin) {
		fmt.Printf("> ")
	}
	var selection string
	if _, err := fmt.Scanln(&selection); err != nil {
		printFatal(err.Error())
	}

	if serverMap[selection] == "" {
		return "", errors.New("Invalid selection!")
	}
	return serverMap[selection], nil
}