Merge pull request #342 from hpcng/remove-base-template
Remove-base-template
This commit is contained in:
@@ -44,6 +44,11 @@ func New() (nodeYaml, error) {
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
/*
|
||||
Get all the nodes of a configuration. This function also merges
|
||||
the nodes with the given profiles and set the default values
|
||||
for every node
|
||||
*/
|
||||
func (config *nodeYaml) FindAllNodes() ([]NodeInfo, error) {
|
||||
var ret []NodeInfo
|
||||
wwconfig, err := warewulfconf.New()
|
||||
@@ -125,6 +130,7 @@ func (config *nodeYaml) FindAllNodes() ([]NodeInfo, error) {
|
||||
n.NetDevs[devname].Ipaddr6.SetDefault(ipv6str)
|
||||
}
|
||||
n.NetDevs[devname].Netmask.Set(netdev.Netmask)
|
||||
n.NetDevs[devname].Netmask.SetDefault("255.255.255.0")
|
||||
n.NetDevs[devname].Hwaddr.Set(netdev.Hwaddr)
|
||||
n.NetDevs[devname].Gateway.Set(netdev.Gateway)
|
||||
n.NetDevs[devname].Type.Set(netdev.Type)
|
||||
|
||||
@@ -356,28 +356,37 @@ func BuildOverlayIndir(nodeInfo node.NodeInfo, overlayNames []string, outputDir
|
||||
var fileBuffer bytes.Buffer
|
||||
// search for magic file name comment
|
||||
fileScanner := bufio.NewScanner(bytes.NewReader(buffer.Bytes()))
|
||||
fileScanner.Split(bufio.ScanLines)
|
||||
fileScanner.Split(scanLines)
|
||||
reg := regexp.MustCompile(`.*{{\s*/\*\s*file\s*["'](.*)["']\s*\*/\s*}}.*`)
|
||||
foundFileComment := false
|
||||
for fileScanner.Scan() {
|
||||
line := fileScanner.Text()
|
||||
filenameFromTemplate := reg.FindAllStringSubmatch(line, -1)
|
||||
if len(filenameFromTemplate) != 0 {
|
||||
err = carefulWriteBuffer(path.Join(outputDir, destFileName),
|
||||
fileBuffer, backupFile, info.Mode())
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not write file from template")
|
||||
wwlog.Printf(wwlog.DEBUG, "Found multifile comment, new filename %s\n", filenameFromTemplate[0][1])
|
||||
if foundFileComment {
|
||||
err = carefulWriteBuffer(path.Join(outputDir, destFileName),
|
||||
fileBuffer, backupFile, info.Mode())
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not write file from template")
|
||||
}
|
||||
err = util.CopyUIDGID(location, path.Join(outputDir, destFileName))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed setting permissions on template output file")
|
||||
}
|
||||
fileBuffer.Reset()
|
||||
}
|
||||
destFileName = path.Join(path.Dir(destFile), filenameFromTemplate[0][1])
|
||||
fileBuffer.Reset()
|
||||
foundFileComment = true
|
||||
} else {
|
||||
_, _ = fileBuffer.WriteString(line + "\n")
|
||||
_, _ = fileBuffer.WriteString(line)
|
||||
}
|
||||
}
|
||||
err = carefulWriteBuffer(path.Join(outputDir, destFileName), fileBuffer, backupFile, info.Mode())
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not write file from template")
|
||||
}
|
||||
err = util.CopyUIDGID(location, path.Join(outputDir, destFile))
|
||||
err = util.CopyUIDGID(location, path.Join(outputDir, destFileName))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed setting permissions on template output file")
|
||||
}
|
||||
@@ -440,3 +449,20 @@ func carefulWriteBuffer(destFile string, buffer bytes.Buffer, backupFile bool, p
|
||||
_, err = buffer.WriteTo(w)
|
||||
return err
|
||||
}
|
||||
|
||||
// Simple version of ScanLines, but include the line break
|
||||
func scanLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
|
||||
if atEOF && len(data) == 0 {
|
||||
return 0, nil, nil
|
||||
}
|
||||
if i := bytes.IndexByte(data, '\n'); i >= 0 {
|
||||
// We have a full newline-terminated line.
|
||||
return i + 1, data[0 : i+1], nil
|
||||
}
|
||||
// If we're at EOF, we have a final, non-terminated line. Return it.
|
||||
if atEOF {
|
||||
return len(data), data, nil
|
||||
}
|
||||
// Request more data.
|
||||
return 0, nil, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user