Пример #1
0
func CreateConfig(d *deployer.CommonData, i *metadata.InputData) (*metadata.Config, error) {
	if d.DefaultExportDir == "" {
		d.DefaultExportDir = "/var/lib/libvirt/images"
	}

	m, err := metadata.NewMetdataConfig(d, i.StorageConfigFile)
	if err != nil {
		return nil, utils.FormatError(err)
	}

	controller.RegisterSteps(func() func() error {
		return func() error {
			var err error
			m.Hwdriver, err = hwinfodriver.NewHostinfoDriver(m.SshConfig, i.Lshw, filepath.Join(d.RootDir, ".hwinfo.json"))
			if err != nil {
				return utils.FormatError(err)
			}

			m.Metadata = new(metadata.Metadata)
			m.EnvDriver = envdriver.NewDriver(m.SshConfig)
			if m.Metadata.EmulatorPath, err = m.EnvDriver.Emulator(d.Arch); err != nil {
				return utils.FormatError(err)
			}
			return controller.SkipStep
		}
	}())

	if err := metadata.RegisterSteps(d, i, m, &meta{}); err != nil {
		return nil, utils.FormatError(err)
	}
	return m, nil
}
Пример #2
0
func (c *FlowCreator) CreateConfig(d *deployer.CommonData) error {
	d.DefaultExportDir = "/var/lib/xen"
	data := new(metadata.InputData)
	data.Lshw = filepath.Join(d.RootDir, "install", d.Arch, "bin/lshw")
	data.InputDataConfigFile = filepath.Join(d.RootDir, mainConfig["input_data_config_file"])
	data.StorageConfigFile = filepath.Join(d.RootDir, mainConfig["storage_config_file"])

	var err error
	if c.config, err = xenconf.CreateConfig(d, data); err != nil {
		return err
	}

	controller.RegisterSteps(func() func() error {
		return func() error {
			fmt.Println("My step 1")
			return nil
		}
	}())

	controller.RegisterSteps(func() func() error {
		return func() error {
			fmt.Println("My step 2")
			return nil
		}
	}())

	if err := controller.RunSteps(); err != nil {
		return err
	}

	// Xen XL metadata requires that the RAM size will be represented in Megabytes
	c.config.Metadata.RAM /= 1024

	d.Ui.Pb.SetSleep("10s")
	d.Ui.Pb.SetStep(10)

	if c.config.RemoteMode {
		d.Ui.Pb.IncreaseSleep("5s")
		d.Ui.Pb.DecreaseStep(4)
	}
	return nil
}
Пример #3
0
func (c *FlowCreator) CreateConfig(d *deployer.CommonData) error {
	d.DefaultExportDir = "/var/lib/libvirt/images"
	data := new(metadata.InputData)
	data.Lshw = filepath.Join(d.RootDir, "install", d.Arch, "bin/lshw")
	data.InputDataConfigFile = filepath.Join(d.RootDir, mainConfig["input_data_config_file"])
	data.StorageConfigFile = filepath.Join(d.RootDir, mainConfig["storage_config_file"])
	data.TemplatesDir = filepath.Join(d.RootDir, mainConfig["metadata_dir"])

	var err error
	if c.config, err = libvirtconf.CreateConfig(d, data); err != nil {
		return err
	}

	controller.RegisterSteps(func() func() error {
		return func() error {
			fmt.Println("My step 1")
			return nil
		}
	}())

	controller.RegisterSteps(func() func() error {
		return func() error {
			fmt.Println("My step 2")
			return nil
		}
	}())

	if err := controller.RunSteps(); err != nil {
		return err
	}

	d.Ui.Pb.SetSleep("10s")
	d.Ui.Pb.SetStep(10)

	if c.config.RemoteMode {
		d.Ui.Pb.IncreaseSleep("5s")
		d.Ui.Pb.DecreaseStep(4)
	}
	return nil
}
Пример #4
0
func RegisterSteps(d *deployer.CommonData, i *InputData, c *Config, metaconf deployer.MetadataConfigurator) error {
	xid, err := xmlinput.ParseXMLInput(i.InputDataConfigFile)
	if err != nil {
		return utils.FormatError(err)
	}

	controller.RegisterSteps(func() func() error {
		return func() error {
			var err error
			if c.Metadata.DomainName, err = gui.UiApplianceName(d.Ui, d.VaName, c.EnvDriver); err != nil {
				return err
			}
			d.VaName = c.Metadata.DomainName
			if err = gui.UiGatherHWInfo(d.Ui, c.Hwdriver, c.RemoteMode); err != nil {
				return utils.FormatError(err)
			}
			return nil
		}
	}())

	// Network configuration
	if xid.Networks.Configure {
		controller.RegisterSteps(func() func() error {
			return func() error {
				c.GuestConfig.Networks = nil
				c.GuestConfig.NICLists = nil

				nics, err := host_hwfilter.GetAllowedNICs(xid, c.Hwdriver)
				if err != nil {
					return utils.FormatError(err)
				}
				if err = gui.UiNetworks(d.Ui, xid, nics, c.GuestConfig); err != nil {
					return err
				}
				c.Metadata.Networks, err = metaconf.SetNetworkData(c.GuestConfig, i.TemplatesDir, nil)
				if err != nil {
					return utils.FormatError(err)
				}
				return nil
			}
		}())
	}

	// guest configuration
	controller.RegisterSteps(func() func() error {
		return func() error {
			if i.BundleParser != nil {
				m, err := i.BundleParser.Parse(d, c.Hwdriver, xid)
				if err != nil {
					return utils.FormatError(err)
				}
				if m != nil {
					c.Bundle = m
					c.GuestConfig.CPUs = m["cpus"].(int)
					c.GuestConfig.RamMb = m["ram_mb"].(int) * 1024
					c.GuestConfig.Storage, err = config.StorageConfig(filepath.Join(c.ExportDir, d.VaName),
						m["storage_config_index"].(image.ConfigIndex), c.StorageConfig, nil)
					if err != nil {
						return utils.FormatError(err)
					}
				}
			}
			if len(c.Bundle) == 0 {
				if xid.CPU.Max == xmlinput.UnlimitedAlloc {
					xid.CPU.Max = c.EnvDriver.MaxVCPUsPerGuest()
				}
				if err = gui.UiVmConfig(d.Ui, c.Hwdriver, xid, filepath.Join(c.ExportDir, d.VaName), c.StorageConfig, c.GuestConfig); err != nil {
					return err
				}
			}

			c.Metadata.CPUs = c.GuestConfig.CPUs
			c.Metadata.RAM = c.GuestConfig.RamMb * 1024
			if c.GuestConfig.Storage == nil {
				if c.GuestConfig.Storage, err = config.StorageConfig(filepath.Join(c.ExportDir, d.VaName), 0, c.StorageConfig, nil); err != nil {
					return err
				}
			}
			c.Metadata.Storage, err = metaconf.SetStorageData(c.GuestConfig, i.TemplatesDir, nil)
			if err != nil {
				return utils.FormatError(err)
			}
			return nil

		}
	}())

	// NUMA configuration
	controller.RegisterSteps(func() func() error {
		return func() error {
			// file, err := os.Create("/tmp/x.txt")
			// defer file.Close()

			c.GuestConfig.NUMAs = nil
			numas, err := c.Hwdriver.NUMAInfo()
			if err != nil {
				return utils.FormatError(err)
			}
			if xid.NUMA.AutoConfig {
				if xid.WarnOnUnpinnedCPUs {
					pinned, err := c.EnvDriver.AllCPUsPinned()
					if err != nil {
						return utils.FormatError(err)
					}
					if !pinned {
						if !gui.UiWarningOnOptimizationFailure(d.Ui, "Not all the virtual machines on the host are configured with CPU pinning.") {
							os.Exit(0)
						}
					}
				}
				if numas.TotalNUMAs() == 1 {
					// file.WriteString("RegisterSteps() numas.TotalNUMAs() == 1\n")
					if err := c.GuestConfig.SetTopologySingleVirtualNUMA(numas, true); err != nil {
						return utils.FormatError(err)
					}
				} else {
					// file.WriteString("RegisterSteps() numas.TotalNUMAs() else \n")
					if err := c.GuestConfig.SetTopologyMultipleVirtualNUMAs(numas); err != nil {
						// file.WriteString("RegisterSteps() c.GuestConfig.SetTopologyMultipleVirtualNUMAs(numas) err != nil " + err.Error() + "\n")
						return utils.FormatError(err)
					}
					if c.GuestConfig.OptimizationFailureMsg != "" {
						// file.WriteString("RegisterSteps() c.GuestConfig.OptimizationFailureMsg  " + c.GuestConfig.OptimizationFailureMsg + "\n")
						if !gui.UiWarningOnOptimizationFailure(d.Ui, c.GuestConfig.OptimizationFailureMsg) {
							os.Exit(0)
						}
					}
				}
			} else {
				if err := c.GuestConfig.SetTopologySingleVirtualNUMA(numas, false); err != nil {
					return utils.FormatError(err)
				}
			}

			processNext, err := gui.UiNumaRamNotOK(d.Ui, c.Hwdriver, c.GuestConfig, c.GuestConfig.RamMb)

			if processNext != true {

				return errors.New(dialog_ui.DialogMoveBack)
			}
			if err != nil {
				// file.WriteString("RegisterSteps() err != nil 1 \n")
				return utils.FormatError(err)
			}
			// file.WriteString("RegisterSteps() xid.UiEditNUMAConfig  \n")
			if xid.UiEditNUMAConfig {
				cpus, err := c.Hwdriver.CPUs()
				// file.WriteString("RegisterSteps() c.Hwdriver.CPUs() \n")
				if err != nil {
					// file.WriteString("RegisterSteps() err  " + err.Error() + " \n")
					return utils.FormatError(err)
				}
				// inject return code if need reconfigure
				isChanged, err := gui.UiNUMATopology(d.Ui, c.GuestConfig, c.EnvDriver, cpus)
				if err != nil {
					// file.WriteString("RegisterSteps() err !=nil gui.UiNUMATopology " + err.Error() + " \n")
					return err
				}
				if isChanged {
					// err := errors.New("CPU j is assigned to more than one vCPU")
					// return utils.FormatError(err)
					if err := c.GuestConfig.ReconfigureMultipleVirtualNUMAs(numas); err != nil {
						// file.WriteString("RegisterSteps() err !=nil c.GuestConfig.ReconfigureMultipleVirtualNUMAs  \n")
						return utils.FormatError(err)
					}
				}
			}
			// file.WriteString("RegisterSteps() c.Hwdriver.CPUInfo()  \n")
			hcpu, err := c.Hwdriver.CPUInfo()
			if err != nil {
				return utils.FormatError(err)
			}
			if _, ok := hcpu.Cap["pdpe1gb"]; ok {
				c.GuestConfig.LargeHugePagesSupported = true
			}
			// file.WriteString("RegisterSteps() metaconf.SetCpuTuneData(  \n")
			c.Metadata.CPUTune, err = metaconf.SetCpuTuneData(c.GuestConfig, i.TemplatesDir, nil)
			if err != nil {
				return utils.FormatError(err)
			}
			// file.WriteString("RegisterSteps() metaconf.SetCpuConfigData(  \n")
			c.Metadata.CPUConfig, err = metaconf.SetCpuConfigData(c.GuestConfig, i.TemplatesDir, nil)
			if err != nil {
				return utils.FormatError(err)
			}
			// file.WriteString("RegisterSteps() metaconf.SetNUMATuneData(  \n")
			c.Metadata.NUMATune, err = metaconf.SetNUMATuneData(c.GuestConfig, i.TemplatesDir, c.EnvDriver)
			if err != nil {
				return utils.FormatError(err)
			}
			// file.WriteString("RegisterSteps() END \n")
			return nil

		}
	}())

	// create default metadata
	controller.RegisterSteps(func() func() error {
		return func() error {
			c.DestMetadataFile = fmt.Sprintf("/tmp/%s-temp-metadata.%d", d.VaName, os.Getpid())
			// always create default metadata
			if err := ioutil.WriteFile(c.DestMetadataFile, metaconf.DefaultMetadata(), 0); err != nil {
				return utils.FormatError(err)
			}
			return controller.SkipStep
		}
	}())

	return nil
}