本文整理匯總了Golang中github.com/dorzheh/deployer/ui/dialog_ui.DialogUi.Mixedform方法的典型用法代碼示例。如果您正苦於以下問題:Golang DialogUi.Mixedform方法的具體用法?Golang DialogUi.Mixedform怎麽用?Golang DialogUi.Mixedform使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/dorzheh/deployer/ui/dialog_ui.DialogUi
的用法示例。
在下文中一共展示了DialogUi.Mixedform方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: UiVmConfig
func UiVmConfig(ui *gui.DialogUi, driver deployer.HostinfoDriver, xidata *xmlinput.XMLInputData,
pathToMainImage string, sconf *image.Storage, conf *guest.Config) error {
var installedRamMb int
var maxRAM int
var err error
list := make([]string, 0)
index := 1
if xidata.CPU.Configure {
cpuStr := fmt.Sprintf(" %-9s | %d-%d", "CPU", xidata.CPU.Min, xidata.CPU.Max)
list = []string{cpuStr, strconv.Itoa(index), "1", strconv.Itoa(xidata.CPU.Default), "1", "30", "6", "0", "0"}
index++
} else if xidata.CPU.Default > 0 {
conf.CPUs = xidata.CPU.Default
}
if xidata.RAM.Configure {
installedRamMb, err = driver.RAMSize()
if err != nil {
return utils.FormatError(err)
}
if xidata.RAM.Max > installedRamMb || xidata.RAM.Max == xmlinput.UnlimitedAlloc {
maxRAM = installedRamMb
} else {
maxRAM = xidata.RAM.Max
}
ramStr := fmt.Sprintf(" %-9s | %d-%dG", "RAM", xidata.RAM.Min/1024, maxRAM/1024)
list = append(list, []string{ramStr, strconv.Itoa(index), "1", strconv.Itoa(xidata.RAM.Default / 1024), "2", "30", "6", "0", "0"}...)
index++
} else if xidata.RAM.Default > 0 {
conf.RamMb = xidata.RAM.Default
}
if xidata.Disks.Configure {
diskName := "Disk"
for i, disk := range xidata.Disks.Configs {
if i > 0 {
diskName = strconv.Itoa(i) + "_" + strconv.Itoa(i)
}
diskStr := fmt.Sprintf(" %-9s | %d-%dG", diskName, disk.Min/1024, disk.Max/1024)
indexStr := strconv.Itoa(index)
list = append(list, []string{diskStr, indexStr, "1", strconv.Itoa(disk.Default / 1024), indexStr, "30", "6", "0", "0"}...)
index++
}
}
str := " ______________________________________\n| Resource | Maximum | Allocated |"
installedCpus, err := driver.CPUs()
if err != nil {
return utils.FormatError(err)
}
index--
if index > 1 {
MainLoop:
for {
ui.SetSize(11, 46)
ui.SetTitle("Virtual Machine configuration")
ui.HelpButton(true)
ui.SetHelpLabel("Back")
resultIndex := 0
result, err := ui.Mixedform(str, false, list[0:]...)
if err != nil {
return err
}
if len(result) < index {
continue
}
if xidata.CPU.Configure {
selectedCpus, err := strconv.Atoi(result[resultIndex])
if err != nil {
continue
}
if uiCpuNotOK(ui, selectedCpus, installedCpus, xidata.CPU.Min, xidata.CPU.Max) {
continue
}
conf.CPUs = selectedCpus
resultIndex++
}
if xidata.RAM.Configure {
selectedRamMb, err := utils.FloatStringToInt(result[resultIndex], 1024)
if err != nil {
continue MainLoop
}
if uiRamNotOK(ui, selectedRamMb, installedRamMb, xidata.RAM.Min, maxRAM) {
continue
}
conf.RamMb = selectedRamMb
resultIndex++
}
if xidata.Disks.Configure {
disks := make([]int, 0)
for _, disk := range xidata.Disks.Configs {
selectedDiskSizeMb, err := utils.FloatStringToInt(result[resultIndex], 1024)
if err != nil {
continue MainLoop
}
if uiDiskNotOK(ui, selectedDiskSizeMb, disk.Min, disk.Max) {
continue MainLoop
//.........這裏部分代碼省略.........
示例2: UiNUMATopology
//.........這裏部分代碼省略.........
if index == 0 {
// vnumaMinus1 = vnumaIndex
for k, _ := range tempData[tempDataLen-1] {
vnumaTemp = strconv.Itoa(k)
}
if vnumaTemp != vnumaIndex {
vnumaMinus1 = vnumaIndex
} else {
vnumaMinus1 = "vnumaIndex"
}
}
} else {
vnumaMinus1 = "-1"
vnumaPlus1 = "+1"
}
// xxxxxx := d.Id()
// file.WriteString("d.Id(): (" + xxxxxx + ") ")
// file.WriteString("vnumaStr: (" + vnumaStr + ") vnumaPredecStr: (" + vnumaPredecStr + ") \n")
// file.WriteString("indexMinus1: (" + strconv.Itoa(indexMinus1) + ") index: (" + strconv.Itoa(index) + ") indexPlus1: (" + strconv.Itoa(indexPlus1) + ")\n")
// file.WriteString("vnumaMinus1: (" + vnumaMinus1 + ") vnumaPlus1: (" + vnumaPlus1 + ") \n")
// file.WriteString("tempDataLen: (" + strconv.Itoa(tempDataLen) + ") \n")
// if vnumaStr == vnumaPredecStr && d.Id() == "QEMU-Libvirt" {
if vnumaMinus1 == vnumaPlus1 && d.Id() == "QEMU-Libvirt" {
lst = []string{"VA vNUMA ID : ", "1", "1", vnumaStr, "1", "15", "2", "0", "2"}
label += "\n\nIMPORTANT! Some QEMU versions do not support\n" +
"disjoint NUMA CPU ranges therefore vNUMA configuration\n" +
"is disabled for this vCPU.\n"
} else {
lst = []string{"VA vNUMA ID : ", "1", "1", vnumaStr, "1", "15", "2", "0", "0"}
}
lst = append(lst, "Host CPU(s) : ", "2", "1", cpusStr, "2", "15", "30", "0", "0")
r, err := ui.Mixedform(label, false, lst[0:]...)
if err != nil {
if err.Error() == gui.DialogNext {
uiShowNumaTopologyHelpMsg(ui)
continue
}
return isChanged, err
}
if len(r) < 2 {
continue
}
vcpuInt, err := strconv.Atoi(result)
if err != nil {
continue
}
vnumaInt, err := strconv.Atoi(r[0])
if err != nil {
ui.Output(gui.Warning, "Illegal input \""+r[0]+"\"", "Press <OK> to return to menu.")
continue
}
if err := verifyRange(vnumaInt, len(c.NUMAs)); err != nil {
ui.Output(gui.Warning, err.Error(), "Press <OK> to return to menu.")
continue
}
hostCpus := r[1]
cpus := make([]int, 0)
if strings.Contains(hostCpus, ",") {
for _, e := range strings.Split(hostCpus, ",") {
if strings.Contains(e, "-") {
cpus, err = splitByHypen(e, totalCpusOnHost)
示例3: UiSshConfig
func UiSshConfig(ui *gui.DialogUi) (*sshconf.Config, error) {
cfg := new(sshconf.Config)
cfg.Port = "22"
cfg.User = "root"
origlist := []string{"IP : ", "1", "1", "", "1", "10", "22", "0", "0",
"SSH Port: ", "2", "1", cfg.Port, "2", "10", "22", "0", "0",
"Username: ", "3", "1", cfg.User, "3", "10", "22", "0", "0"}
MainLoop:
for {
ui.HelpButton(true)
ui.SetHelpLabel("Back")
reslist, err := ui.Mixedform("Remote session configuration", false, origlist[0:]...)
if err != nil {
return nil, err
}
if len(reslist) < 3 {
continue
}
if net.ParseIP(reslist[0]) == nil {
continue
}
cfg.Host = reslist[0]
portDig, err := strconv.Atoi(reslist[1])
if err != nil {
return nil, utils.FormatError(err)
}
if portDig > 65535 {
continue
}
AuthLoop:
for {
ui.SetTitle("Authentication method")
ui.SetSize(9, 18)
ui.HelpButton(true)
ui.SetHelpLabel("Back")
val, err := ui.Menu(2, "1", "Password", "2", "Private key")
if err != nil {
switch err.Error() {
case gui.DialogMoveBack:
continue MainLoop
case gui.DialogExit:
os.Exit(1)
}
}
switch val {
case "1":
cfg.Password, err = ui.GetPasswordFromInput(cfg.Host, cfg.User, "Back", "", false)
case "2":
cfg.PrvtKeyFile, err = ui.GetPathToFileFromInput("Path to ssh private key file", "Back", "")
}
if err != nil {
switch err.Error() {
case gui.DialogMoveBack:
continue AuthLoop
case gui.DialogExit:
os.Exit(1)
}
}
break MainLoop
}
}
run := utils.RunFunc(cfg)
errCh := make(chan error)
defer close(errCh)
go func() {
// verifying that user is able execute a command by using sudo
_, err := run("uname")
errCh <- err
}()
if err := ui.Wait("Trying to establish SSH connection to remote host.\nPlease wait...", time.Second*1, time.Second*5, errCh); err != nil {
ui.Output(gui.Warning, "Unable to establish SSH connection.", "Press <OK> to return to menu.")
goto MainLoop
}
return cfg, nil
}