本文整理匯總了Golang中github.com/dorzheh/deployer/ui/dialog_ui.DialogUi.Output方法的典型用法代碼示例。如果您正苦於以下問題:Golang DialogUi.Output方法的具體用法?Golang DialogUi.Output怎麽用?Golang DialogUi.Output使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/dorzheh/deployer/ui/dialog_ui.DialogUi
的用法示例。
在下文中一共展示了DialogUi.Output方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: UiApplianceName
func UiApplianceName(ui *gui.DialogUi, defaultName string, driver deployer.EnvDriver) (string, error) {
var name string
var err error
for {
ui.SetSize(8, len(defaultName)+10)
ui.SetTitle("Virtual machine name")
ui.HelpButton(true)
ui.SetHelpLabel("Back")
name, err = ui.Inputbox(defaultName)
if err != nil {
return "", err
}
if name != "" {
name = strings.Replace(name, ".", "-", -1)
if driver != nil {
if driver.DomainExists(name) {
ui.Output(gui.Warning, "domain "+name+" already exists.", "Press <OK> to return to menu.")
continue
}
}
break
}
}
return name, nil
}
示例2: uiDiskNotOK
func uiDiskNotOK(ui *gui.DialogUi, selectedDiskInMb, minDiskInMb, maxDiskInMb int) bool {
if selectedDiskInMb < minDiskInMb {
ui.Output(gui.Warning, fmt.Sprintf("Minimum disk size requirement is %dGB.", minDiskInMb/1024), "Press <OK> to return to menu.")
return true
}
if selectedDiskInMb > maxDiskInMb {
ui.Output(gui.Warning, fmt.Sprintf("Maximum disk size requirement is %dGB.", maxDiskInMb/1024), "Press <OK> to return to menu.")
return true
}
return false
}
示例3: uiCpuNotOK
func uiCpuNotOK(ui *gui.DialogUi, selectedCpus, installedCpus, minCpus, maxCpus int) bool {
if selectedCpus < minCpus {
ui.Output(gui.Warning, fmt.Sprintf("Minimum vCPUs requirement is %d.", minCpus), "Press <OK> to return to menu.")
return true
}
if selectedCpus > maxCpus {
ui.Output(gui.Warning, fmt.Sprintf("Amount of vCPUs exceeds maximum supported vCPUs(%d).", maxCpus), "Press <OK> to return to menu.")
return true
}
if selectedCpus > installedCpus {
if !UiVCPUsOvercommit(ui, installedCpus) {
return true
}
}
return false
}
示例4: UiRemoteMode
func UiRemoteMode(ui *gui.DialogUi) (bool, error) {
ui.SetTitle("Deployment Mode")
ui.SetSize(9, 28)
answer, err := ui.Menu(2, "1", "Local", "2", "Remote")
if err != nil {
return false, err
}
if answer == "1" {
return false, nil
}
if _, err := exec.LookPath("sshfs"); err != nil {
ui.Output(gui.Error, "sshfs utility is not installed")
}
return true, nil
}
示例5: uiRamNotOK
func uiRamNotOK(ui *gui.DialogUi, selectedRamInMb, installedRamMb, minRamInMb, maxRamInMb int) bool {
if selectedRamInMb > installedRamMb {
ui.Output(gui.Warning, "Required RAM exceeds host machine available memory.", "Press <OK> to return to menu.")
return true
}
if selectedRamInMb < minRamInMb {
ui.Output(gui.Warning, fmt.Sprintf("Minimum RAM requirement is %0.1fGB.", float64(minRamInMb)/1024), "Press <OK> to return to menu.")
return true
}
if selectedRamInMb > maxRamInMb {
ui.Output(gui.Warning, fmt.Sprintf("Maximum RAM requirement is %0.1fGB.", float64(maxRamInMb)/1024), "Press <OK> to return to menu.")
return true
}
return false
}
示例6: UiNUMATopology
func UiNUMATopology(ui *gui.DialogUi, c *guest.Config, d deployer.EnvDriver, totalCpusOnHost int) (bool, error) {
var list []string
// file, err := os.Create("/tmp/UiNUMATopology.txt")
// if err != nil {
// return false, nil
// }
// defer file.Close()
isChanged := false
hCPUnotOnce := ""
CheckIfCPUdoubleUsed := true
MainLoop:
for {
// file.WriteString("[UiNUMATopology] MainLoop: \n")
list = make([]string, 0)
tempData := make(map[int]map[int]string)
// file.WriteString("[UiNUMATopology] totalCpusOnHost: " + strconv.Itoa(totalCpusOnHost) + " \n")
for _, n := range c.NUMAs {
// file.WriteString("[UiNUMATopology] c.NUMAs\n")
// file.WriteString("[UiNUMATopology] len(n.CPUPin): " + strconv.Itoa(len(n.CPUPin)) + "\n")
keys := make([]int, 0)
for vcpu, _ := range n.CPUPin {
keys = append(keys, vcpu)
// file.WriteString("[UiNUMATopology] vcpu: " + strconv.Itoa(vcpu) + "\n")
}
sort.Ints(keys)
var hostCpu string
for _, k := range keys {
if len(n.CPUPin[k]) > 1 {
if len(n.CPUPin[k]) == totalCpusOnHost {
CheckIfCPUdoubleUsed = false
hostCpu = "0-" + strconv.Itoa(totalCpusOnHost-1)
} else {
var tmpStrSlice []string
for _, c := range n.CPUPin[k] {
tmpStrSlice = append(tmpStrSlice, strconv.Itoa(c))
}
hostCpu = strings.Join(tmpStrSlice, ",")
}
} else {
hostCpu = strconv.Itoa(n.CPUPin[k][0])
}
// file.WriteString("[UiNUMATopology] hostCpu: " + hostCpu + "\n")
tempData[k] = make(map[int]string)
tempData[k][n.CellID] = hostCpu
// file.WriteString("tempData[" + strconv.Itoa(k) + "][" + strconv.Itoa(n.CellID) + "] = " + hostCpu + " \n")
}
}
// we need to represent sorted vCPU IDs and not vNUMA IDs
keys := make([]int, 0)
for k, _ := range tempData {
keys = append(keys, k)
}
duplicate_frequency := make(map[string]int)
sort.Ints(keys)
for _, key := range keys {
for k, v := range tempData[key] {
list = append(list, strconv.Itoa(key), fmt.Sprintf("%-10s%-18d%-7s", " ", k, v))
temphCPU := v
_, exist := duplicate_frequency[temphCPU]
if exist {
duplicate_frequency[temphCPU] += 1 // increase counter by 1 if already in the map
} else {
duplicate_frequency[temphCPU] = 1 // else start counting from 1
}
// file.WriteString("k: " + strconv.Itoa(k) + " v: " + v + " \n")
}
}
hCPUnotOnce = ""
for k_dup, v_dup := range duplicate_frequency {
if v_dup > 1 {
hCPUnotOnce = k_dup
break
}
}
ui.SetLabel(uiNUMATopologyHeader(ui, c))
result, err := ui.Menu(len(list), list[0:]...)
// file.WriteString("[UiNUMATopology] result: " + result + " err: " + err.Error() + " len(list): " + strconv.Itoa(len(list)) + " \n")
if err == nil {
if hCPUnotOnce != "" && isChanged && CheckIfCPUdoubleUsed {
ui.Output(gui.Warning, "CPU "+hCPUnotOnce+" is assigned to more than one vCPU")
continue
}
break
}
if err.Error() != gui.DialogNext {
// file.WriteString("[UiNUMATopology] err.Error() != gui.DialogNext " + err.Error() + " \n")
return isChanged, err
}
InternalLoop:
//.........這裏部分代碼省略.........
示例7: UiDeploymentResult
func UiDeploymentResult(ui *gui.DialogUi, msg string, err error) {
if err != nil {
ui.Output(gui.Error, err.Error())
}
ui.Output(gui.Success, msg)
}
示例8: uiNicSelectMenu
func uiNicSelectMenu(ui *gui.DialogUi, data *xmlinput.XMLInputData, guestPortCounter *int,
guestPciSlotCounter *int, hnics host.NICList, net *xmlinput.Network, index int) (guest.NICList, error) {
list := make([]string, 0)
keeper := make(map[string]*host.NIC)
indexStrToInt := make(map[string][]int)
indexInt := 1
for _, hnic := range hnics {
indexStr := strconv.Itoa(indexInt)
list = append(list, indexStr, fmt.Sprintf("%-22s%-15s%-68s%-10s", hnic.Name, hnic.PCIAddr, hnic.Desc, uiNUMAIntToString(hnic.NUMANode)))
keeper[indexStr] = hnic
if indexInt == 1 {
// index 0 - element index in the list
// index 1 - element counter
// index 2 - PCI slot number represented as integer
indexStrToInt[indexStr] = []int{1, 0, 0}
} else {
indexStrToInt[indexStr] = []int{indexInt*2 - 1, 0, 0}
}
indexInt++
}
listLength := len(list)
gnics := guest.NewNICList()
var disjuncNicVendor string
var disjuncNicModel string
for {
if index > 0 {
ui.HelpButton(true)
ui.SetHelpLabel("Back")
}
width := uiHeaderSelectNics(ui)
ui.SetSize(listLength+8, width+5)
ui.SetTitle(fmt.Sprintf("Select interface for network \"%s\"", net.Name))
nicNumStr, err := ui.Menu(listLength+5, list[0:]...)
if err != nil {
if err.Error() == gui.DialogNext {
if len(gnics) == 0 && net.Optional == false {
continue
}
break
}
*guestPciSlotCounter -= len(gnics)
*guestPortCounter -= len(gnics)
return nil, err
}
hnic := keeper[nicNumStr]
// verify that we need to proceed with "disjunction"
if net.NicsDisjunction && (hnic.Type == host.NicTypePhys || hnic.Type == host.NicTypePhysVF) &&
(hnic.Vendor != disjuncNicVendor && hnic.Model != disjuncNicModel) {
// back to menu in case "disjunction" entries already exist
if host_hwfilter.NicDisjunctionFound(hnic, data.HostNics.Allowed) && disjuncNicVendor != "" {
msg := fmt.Sprintf("'%s' cannot be selected alongside '%s %s'", hnic.Desc, disjuncNicVendor, disjuncNicModel)
ui.Output(gui.Warning, msg, "Press <OK> to return to menu.")
continue
}
// set the new entries
disjuncNicVendor = hnic.Vendor
disjuncNicModel = hnic.Model
}
delNicCounter := indexStrToInt[nicNumStr][1]
// counter for the NIC found,we should remove the NIC object and its references
if delNicCounter > 0 {
// find the guest NIC object in the guest NICs list
if _, index, err := gnics.NicByHostNicObj(hnic); err == nil {
// if found :
// - remove the object
// - decrement guestPortCounter
// - decriment guestPciSlotCounter
gnics.Remove(index)
if *guestPortCounter > 0 {
*guestPortCounter--
}
if *guestPciSlotCounter > data.GuestNic.PCI.FirstSlot {
*guestPciSlotCounter--
}
// update the list with the new entry containing deselected NIC
list[indexStrToInt[nicNumStr][0]] = fmt.Sprintf("%-22s%-15s%-68s%-10s", hnic.Name, hnic.PCIAddr, hnic.Desc, uiNUMAIntToString(hnic.NUMANode))
// - reset element counter
// - reset PCI slot number
indexStrToInt[nicNumStr][1] = 0
indexStrToInt[nicNumStr][2] = 0
}
// iterate over the map and update entries
for nicIndex, data := range indexStrToInt {
nicCounter := data[1]
if nicCounter > delNicCounter {
tmpNic := keeper[nicIndex]
nicCounter--
list[data[0]] = fmt.Sprintf("%-22s%-15s%-68s%-9s%d", tmpNic.Name, tmpNic.PCIAddr,
tmpNic.Desc, uiNUMAIntToString(tmpNic.NUMANode), nicCounter)
indexStrToInt[nicIndex][1] = nicCounter
indexStrToInt[nicIndex][2]--
if gnic, _, err := gnics.NicByHostNicObj(tmpNic); err == nil {
gnic.PCIAddr.Slot = utils.IntToHexString(indexStrToInt[nicIndex][2])
}
}
}
//.........這裏部分代碼省略.........
示例9: UiValidateUser
// UiValidateUser intended for validate the ID
// of the user executing deployer binary
func UiValidateUser(ui *gui.DialogUi, userId int) {
if err := infrautils.ValidateUserID(userId); err != nil {
ui.Output(gui.Error, err.Error())
}
}
示例10: UiNetworks
func UiNetworks(ui *gui.DialogUi, data *xmlinput.XMLInputData, allowedNics host.NICList, gconf *guest.Config) error {
guestPciSlotCounter := data.GuestNic.PCI.FirstSlot
lastGuestPciSlotCounter := guestPciSlotCounter
portCounter := 1
lastPortCounter := portCounter
i := 0
MainLoop:
for i < len(data.Networks.Configs) {
net := data.Networks.Configs[i]
PolicyLoop:
for {
var modes []xmlinput.ConnectionMode
if net.UiModeBinding == nil || len(net.UiModeBinding) == 0 {
for _, mode := range net.Modes {
modes = append(modes, mode.Type)
}
} else {
var err error
modes, err = uiNetworkPolicySelector(ui, net)
if err != nil {
switch err.Error() {
case gui.DialogMoveBack:
gconf.Networks = gconf.Networks[:i]
gconf.NICLists = gconf.NICLists[:i]
portCounter = lastPortCounter - 1
guestPciSlotCounter = lastGuestPciSlotCounter - 1
if i == 0 {
return err
}
i--
continue MainLoop
case gui.DialogNext:
i++
continue MainLoop
case gui.DialogExit:
os.Exit(1)
default:
return err
}
}
}
retainedNics, err := host_hwfilter.NicsByType(allowedNics, modes)
if err != nil {
return utils.FormatError(err)
}
if len(retainedNics) == 0 {
ui.Output(gui.Warning, "No interfaces have been found.", "Press <OK> to return to menu.")
continue MainLoop
}
if net.UiResetCounter {
portCounter = 1
}
list, err := uiNicSelectMenu(ui, data, &portCounter, &guestPciSlotCounter, retainedNics, net, i)
if err != nil {
switch err.Error() {
case gui.DialogMoveBack:
if i == 0 {
return err
}
gconf.Networks = gconf.Networks[:i]
gconf.NICLists = gconf.NICLists[:i]
continue PolicyLoop
case gui.DialogExit:
os.Exit(1)
}
}
gconf.Networks = append(gconf.Networks, net)
gconf.NICLists = append(gconf.NICLists, list)
lastPortCounter = portCounter
lastGuestPciSlotCounter = guestPciSlotCounter
i++
break
}
}
return nil
}
示例11: 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
}