func (b *MetadataBuilder) Run() (deployer.Artifact, error) { // in case no source template exists apparently we should use the default metadata _, err := os.Stat(b.Source) if err != nil { b.Source = b.Dest } f, err := ioutil.ReadFile(b.Source) if err != nil { return nil, utils.FormatError(err) } data, err := utils.ProcessTemplate(string(f), b.UserData) if err != nil { return nil, utils.FormatError(err) } run := utils.RunFunc(b.SshConfig) if _, err := run(fmt.Sprintf("echo \"%s\" > %s", data, b.Dest)); err != nil { return nil, utils.FormatError(err) } return &deployer.CommonArtifact{ Name: filepath.Base(b.Dest), Path: b.Dest, Type: deployer.MetadataArtifact, }, nil }
func ProcessNetworkTemplate(mode *xmlinput.Mode, defaultTemplate string, tmpltData interface{}, templatesDir string) (string, error) { var customTemplate string if mode.Tmplt == nil { customTemplate = defaultTemplate } else { var templatePath string if templatesDir != "" { templatePath = filepath.Join(templatesDir, mode.Tmplt.FileName) } else { templatePath = filepath.Join(mode.Tmplt.Dir, mode.Tmplt.FileName) } buf, err := ioutil.ReadFile(templatePath) if err != nil { return "", utils.FormatError(err) } customTemplate = string(buf) } tempData, err := utils.ProcessTemplate(customTemplate, tmpltData) if err != nil { return "", utils.FormatError(err) } return string(tempData) + "\n", nil }
func (m meta) SetCpuTuneData(c *guest.Config, templatesDir string, i interface{}) (string, error) { buf, err := ioutil.ReadFile(filepath.Join(templatesDir, TmpltFileCpuTune)) if err == nil { TmpltCpuTune = string(buf) } tempData, err := utils.ProcessTemplate(TmpltCpuTune, &CpuTuneData{setCpuTuneData(c.NUMAs)}) if err != nil { return "", utils.FormatError(err) } return string(tempData) + "\n", nil }
func (m meta) SetCpuConfigData(c *guest.Config, templatesDir string, i interface{}) (string, error) { buf, err := ioutil.ReadFile(filepath.Join(templatesDir, TmpltFileCpuConfig)) if err == nil { TmpltCpuConfig = string(buf) } cfg := new(CpuConfigData) cfg.CPUPolicy, cfg.NUMAConfig = setCpuConfigData(c) tempData, err := utils.ProcessTemplate(TmpltCpuConfig, cfg) if err != nil { return "", utils.FormatError(err) } return string(tempData) + "\n", nil }
func (m meta) SetNUMATuneData(c *guest.Config, templatesDir string, i interface{}) (string, error) { // file, err := os.Create("/tmp/SetNUMATuneData.txt") // if err != nil { // return "", nil // } // defer file.Close() buf, err := ioutil.ReadFile(filepath.Join(templatesDir, TmpltFileNUMATune)) if err == nil { TmpltNUMATune = string(buf) } libvirtVersion, err := i.(deployer.EnvDriver).Version() if err != nil { return "", err } var HostNUMAIds []int var vNUMAIds []int // checking if all Host numa if used for _, n := range c.NUMAs { for _, nic := range n.NICs { if nic.HostNIC.Type == host.NicTypePhys || nic.HostNIC.Type == host.NicTypePhysVF { // hdr += fmt.Sprintf("\nNUMA %d: %s", nic.HostNIC.NUMANode, nic.HostNIC.PCIAddr) HostNUMAIds = append(HostNUMAIds, nic.HostNIC.NUMANode) vNUMAIds = append(vNUMAIds, n.CellID) } } } n := new(NUMATuneData) if c.OptimizationFailureCPU == true { // n.NUMACells, n.MemNodes = setNUMATuneData(HostNUMAIds, libvirtVersion) n.MemMode, n.NUMACells, n.MemNodes = setNUMATuneDataInderect(HostNUMAIds, vNUMAIds, libvirtVersion) } else { n.MemMode, n.NUMACells, n.MemNodes = setNUMATuneData(c.HostNUMAIds, libvirtVersion) } // file.WriteString("n.NUMACells: (" + n.NUMACells + ") \n") // file.WriteString("n.MemNodes: (" + n.MemNodes + ") \n") tempData, err := utils.ProcessTemplate(TmpltNUMATune, n) if err != nil { return "", utils.FormatError(err) } return string(tempData) + "\n", nil }
func processTemplatePassthrough(port *guest.NIC, tmplt string) (string, error) { pciSlice := strings.Split(port.HostNIC.PCIAddr, ":") d := new(PassthroughData) d.HostNicBus = pciSlice[1] temp := strings.Split(pciSlice[2], ".") d.HostNicSlot = temp[0] d.HostNicFunction = temp[1] d.GuestNicDomain = port.PCIAddr.Domain d.GuestNicBus = port.PCIAddr.Bus d.GuestNicSlot = port.PCIAddr.Slot d.GuestNicFunction = port.PCIAddr.Function data, err := utils.ProcessTemplate(tmplt, d) if err != nil { return "", utils.FormatError(err) } return string(data), nil }
// SetStorageData is responsible for adding to the metadata appropriate entries // related to the storage configuration func (m meta) SetStorageData(conf *guest.Config, templatesDir string, i interface{}) (string, error) { var data string buf, err := ioutil.ReadFile(filepath.Join(templatesDir, TmpltFileStorage)) if err == nil { TmpltStorage = string(buf) } for i, disk := range conf.Storage.Disks { d := new(DiskData) d.ImagePath = disk.Path d.StorageType = disk.Type d.BlockDeviceSuffix = blockDevicesSuffix[i] tempData, err := utils.ProcessTemplate(TmpltStorage, d) if err != nil { return "", utils.FormatError(err) } data += string(tempData) + "\n" } return data, nil }