in pkg/question/question.go [369:420]
func AskInstanceTypeInstanceSelector(h *ec2helper.EC2Helper, instanceSelector ec2helper.InstanceSelector,
vcpus, memory string) (*string, error) {
// Parse string to numbers
vcpusInt, err := strconv.Atoi(vcpus)
if err != nil {
return nil, err
}
memoryInt, err := strconv.Atoi(memory)
if err != nil {
return nil, err
}
// get instance types from instance selector
instanceTypes, err := h.GetInstanceTypesFromInstanceSelector(instanceSelector, vcpusInt, memoryInt)
if err != nil {
return nil, err
}
data := [][]string{}
indexedOptions := []string{}
var optionsText string
if len(instanceTypes) > 0 {
for index, instanceType := range instanceTypes {
// Fill the data with properties
data = append(data, []string{
fmt.Sprintf("%d.", index+1),
*instanceType.InstanceType,
strconv.FormatInt(*instanceType.VCpuInfo.DefaultVCpus, 10),
strconv.FormatFloat(float64(*instanceType.MemoryInfo.SizeInMiB)/1024, 'f', 2, 64) + " GiB",
strconv.FormatBool(*instanceType.InstanceStorageSupported),
})
indexedOptions = append(indexedOptions, *instanceType.InstanceType)
}
optionsText = table.BuildTable(data, []string{"Option", "Instance Type", "vCPUs",
"Memory", "Instance Storage"})
} else {
return nil, errors.New("No suggested instance types available. Please enter vCPUs and memory again. ")
}
question := "Instance Type"
answer := AskQuestion(&AskQuestionInput{
QuestionString: question,
OptionsString: &optionsText,
IndexedOptions: indexedOptions,
})
return &answer, nil
}