Example #1
0
func UiGatherHWInfo(ui *gui.DialogUi, hidriver deployer.HostinfoDriver, remote bool) error {
	errCh := make(chan error)
	defer close(errCh)
	go func() {
		errCh <- hidriver.Init()
	}()

	var msg string
	if remote {
		msg = "Gathering harwdare information from remote host.\nPlease wait..."
	} else {
		msg = "Gathering hardware information from local host.\nPlease wait..."
	}
	return ui.Wait(msg, time.Second*2, 0, errCh)
}
Example #2
0
// GetAllowedNICs responsible for fetching Network ports satisfying user configuration
func GetAllowedNICs(data *xmlinput.XMLInputData, hidriver deployer.HostinfoDriver) (host.NICList, error) {
	allowedNics := host.NewNICList()
	priorityNics := host.NewNICList()
	physicalNics := host.NewNICList()

	nics, err := hidriver.NICs()
	if err != nil {
		return nil, utils.FormatError(err)
	}
	for _, nic := range nics {
		if deniedNIC(nic, &data.HostNics) {
			continue
		}
		// if counfiguration exists, treat physical ports
		if nic.Type == host.NicTypePhys || nic.Type == host.NicTypePhysVF {
			if data.HostNics.Allowed != nil {
				for _, anic := range data.HostNics.Allowed {
					if (anic.Model == "" && strings.Contains(nic.Vendor, anic.Vendor)) || nic.Model == anic.Model {
						if anic.Priority {
							priorityNics.Add(nic)
						} else {
							physicalNics.Add(nic)
						}
					}
				}
			}
		} else {
			// allow all ports in case configuration is empty or the port is not physical
			allowedNics.Add(nic)
		}
	}
	// if found ports with priority append them
	if priorityNics.Length() > 0 {
		allowedNics.AppendList(priorityNics)
	} else {
		allowedNics.AppendList(physicalNics)
	}
	return allowedNics, nil
}
Example #3
0
func (b *DefaultBundle) Parse(d *deployer.CommonData, hidriver deployer.HostinfoDriver, xid *xmlinput.XMLInputData) (map[string]interface{}, error) {
	hostRamsizeMb, err := hidriver.RAMSize()
	if err != nil {
		return nil, utils.FormatError(err)
	}

	configs := b.getConfigs(hostRamsizeMb)
	amountOfConfigs := len(configs)
	if amountOfConfigs == 0 {
		return nil, utils.FormatError(errors.New("no eligable configuration is available for the host"))
	}

	installedCpus, err := hidriver.CPUs()
	if err != nil {
		return nil, utils.FormatError(err)
	}
	for {
		c, err := uiBundleConfig(d.Ui, configs, b.AdvancedConfig)
		if err != nil {
			return nil, utils.FormatError(err)
		}
		if c == nil {
			break
		}
		if c.CPUs > installedCpus {
			if !ui.UiVCPUsOvercommit(d.Ui, installedCpus) {
				continue
			}
		}
		m := make(map[string]interface{})
		m["name"] = c.Name
		m["cpus"] = c.CPUs
		m["ram_mb"] = c.RAM
		m["storage_config_index"] = c.StorageConfigIndex
		return m, nil
	}
	return nil, nil
}
Example #4
0
func UiNumaRamNotOK(ui *gui.DialogUi, driver deployer.HostinfoDriver, c *guest.Config, selectedRamInMb int) (bool, error) {
	// file, err := os.Create("/tmp/_setNUMATuneData.txt")
	// defer file.Close()

	numas, err := driver.NUMAInfo()
	if err != nil {
		return true, utils.FormatError(err)
	}
	NumaForCheck := make([]int, 0)
	// file.WriteString("uiNumaRamNotOK\n")
	for _, n := range c.NUMAs {
		// file.WriteString("c.NUMAs\n")
		for _, nic := range n.NICs {
			if nic.HostNIC.Type == host.NicTypePhys || nic.HostNIC.Type == host.NicTypePhysVF {
				isAdd := true
				for _, v := range NumaForCheck {
					if v == nic.HostNIC.NUMANode {
						isAdd = false
					}
				}
				if isAdd {
					NumaForCheck = append(NumaForCheck, nic.HostNIC.NUMANode)
					// file.WriteString("NumaForCheck: [" + strconv.Itoa(nic.HostNIC.NUMANode) + "]\n")
				}
			}
		}
	}
	// selectedRamInMb = 1
	var requiredMemory float64
	var freeRam float64
	numberOfNumas := len(NumaForCheck)
	if numberOfNumas < 1 {
		numberOfNumas = 1
	}
	requiredMemoryMB := selectedRamInMb / numberOfNumas
	requiredMemory = float64(selectedRamInMb / numberOfNumas)
	requiredMemoryStr := strconv.FormatFloat((requiredMemory / 1024), 'f', 1, 64)
	// file.WriteString("requiredMemoryStr: " + requiredMemoryStr + " selectedRamInMb:" + strconv.Itoa(selectedRamInMb) + " \n")
	for _, node := range numas {
		for _, CellID := range NumaForCheck {
			// file.WriteString("CellID: " + strconv.Itoa(CellID) + " node.CellID: " + strconv.Itoa(node.CellID) + "\n")
			if node.CellID != CellID {
				continue
			}
			numafreeRamMb := node.FreeRAM / 1024

			// file.WriteString("requiredMemoryMB: " + strconv.Itoa(requiredMemoryMB) + " node.FreeRAM:" + strconv.Itoa(numafreeRamMb) + " \n")
			// numafreeRamMb = 0
			if numafreeRamMb < requiredMemoryMB {
				freeRam = float64(node.FreeRAM / (1024 * 1024))
				freeRamStr := strconv.FormatFloat(freeRam, 'f', 1, 64)
				ui.SetTitle(gui.Warning)
				ui.SetSize(10, 80)
				ui.SetLabel("Virtual machine configuration can not be optimized.\n" + requiredMemoryStr + " GB RAM are required on NUMA " + strconv.Itoa(node.CellID) + " but just " + freeRamStr + "Gb are available\n\nDo you want to continue?")
				return ui.Yesno(), nil
			}
		}
	}

	return true, nil

}
Example #5
0
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
					}
					disks = append(disks, selectedDiskSizeMb*1024)
					resultIndex++
				}
				if conf.Storage, err = config.StorageConfig(pathToMainImage, 0, sconf, disks); err != nil {
					return err
				}
			}
			break
		}
	}
	return nil
}