Documentation
¶
Index ¶
- Variables
- func BuildAllOverlays(nodes []node.Node, allNodes []node.Node, workerCount int) error
- func BuildHostOverlay() error
- func BuildOverlay(nodeConf node.Node, allNodes []node.Node, context string, ...) error
- func BuildOverlayIndir(nodeData node.Node, allNodes []node.Node, overlayNames []string, ...) error
- func BuildSpecificOverlays(nodes []node.Node, allNodes []node.Node, overlayNames []string, ...) error
- func CarefulWriteBuffer(destFile string, buffer bytes.Buffer, backupFile bool, perm fs.FileMode) (err error)
- func FindOverlays() (overlayList []string)
- func Image(nodeName string, context string, overlayNames []string) string
- func RemoveImage(nodeName string, context string, overlayNames []string) error
- func RenderTemplateFile(fileName string, data TemplateStruct) (buffer bytes.Buffer, backupFile, writeFile *bool, err error)
- func ScanLines(data []byte, atEOF bool) (advance int, token []byte, err error)
- func UniqueField(sep string, index int, input string) string
- func ValidateName(name string) error
- type FieldInfo
- type Overlay
- func (overlay Overlay) AddFile(filePath string, content []byte, parents bool, force bool) error
- func (overlay Overlay) Chmod(path string, mode uint64) (err error)
- func (overlay Overlay) Chown(path string, uid, gid int) (err error)
- func (overlay Overlay) CloneToSite() (siteOverlay Overlay, err error)
- func (overlay Overlay) Delete(force bool) (err error)
- func (overlay Overlay) DeleteFile(filePath string, force, cleanup bool) (err error)
- func (overlay Overlay) Exists() bool
- func (overlay Overlay) File(filePath string) string
- func (overlay Overlay) GetFiles() (files []string, err error)
- func (overlay Overlay) IsDistributionOverlay() bool
- func (overlay Overlay) IsSiteOverlay() bool
- func (overlay Overlay) Mkdir(path string, mode int32) (err error)
- func (overlay Overlay) Name() string
- func (overlay Overlay) ParseCommentVars(file string) (retMap map[string]string)
- func (overlay Overlay) ParseVarFields(file string) map[string]FieldInfo
- func (overlay Overlay) Path() string
- func (overlay Overlay) Rootfs() string
- type TemplateStruct
Constants ¶
This section is empty.
Variables ¶
var ErrDoesNotExist = fmt.Errorf("overlay does not exist")
Functions ¶
func BuildAllOverlays ¶
func BuildHostOverlay ¶
func BuildHostOverlay() error
Build overlay for the host, so no argument needs to be given
func BuildOverlay ¶
func BuildOverlay(nodeConf node.Node, allNodes []node.Node, context string, overlayNames []string) error
Build the given overlays for a node and create an image for them
func BuildOverlayIndir ¶
func BuildOverlayIndir(nodeData node.Node, allNodes []node.Node, overlayNames []string, outputDir string) error
Build the given overlays for a node in the given directory.
func BuildSpecificOverlays ¶
func CarefulWriteBuffer ¶
func CarefulWriteBuffer(destFile string, buffer bytes.Buffer, backupFile bool, perm fs.FileMode) (err error)
Writes buffer to the destination file. If wwbackup is set a wwbackup will be created.
func Image ¶
Image returns the full path to an overlay image based on the context and the overlays contained in it.
If a context is provided, the image file name is based on that context name, in the form __{CONTEXT}__.
If the context is empty ("") the image file name is a concatenated list of the contained overlays joined by "-".
If the context is empty and no overlays are specified, the empty string is returned.
func RenderTemplateFile ¶
func RenderTemplateFile(fileName string, data TemplateStruct) ( buffer bytes.Buffer, backupFile, writeFile *bool, err error, )
Parses the template with the given filename, variables must be in data. Returns the parsed template as bytes.Buffer, and the bool variables for backupFile and writeFile. If something goes wrong an error is returned.
func UniqueField ¶
UniqueField returns a filtered version of a multi-line input string. input is expected to be a field-separated format with one record per line (terminated by `\n`). Order of lines is preserved, with the first matching line taking precedence.
For example, parsing /etc/passwd filter /etc/passwd for unique user names:
Lines without the index field (e.g., blank lines) are always included in the output.
UniqueField(":", 0, passwdContent)
func ValidateName ¶
ValidateName validates that an overlay name consists only of safe characters. It does not check whether the overlay actually exists.
Types ¶
type FieldInfo ¶
type FieldInfo struct {
Field reflect.StructField // Complete field metadata including tags
ParentType reflect.Type // The containing struct type
FullPath string // Full path like ".NetDevs.Ipaddr6"
VarName string // Original variable name from template
}
FieldInfo contains detailed type information about a template variable
type Overlay ¶
type Overlay string
Overlay represents an overlay directory path.
func Create ¶
Create creates a new overlay directory for the given overlay
Returns an error if the overlay already exists or if directory creation fails.
func (Overlay) CloneToSite ¶
CloneToSite creates a site overlay from an existing distribution overlay.
If the distribution overlay doesn't exist, return an error.
func (Overlay) DeleteFile ¶
DeleteFile deletes a file or the entire overlay directory. before deletion.
func (Overlay) Exists ¶
Exists checks whether the overlay path exists and is a directory.
Returns:
- true if the overlay path exists and is a directory; false otherwise.
func (Overlay) File ¶
File constructs a full path to a file within the overlay's root filesystem.
Parameters:
- filePath: The relative path of the file within the overlay.
Returns:
- The full path to the specified file in the overlay's rootfs. If the specified path is not contained within the overlay, the empty string is returned.
func (Overlay) IsDistributionOverlay ¶
IsDistributionOverlay determines whether the overlay is a distribution overlay.
A distribution overlay is identified by its parent directory matching the configured distribution overlay directory path.
Returns:
- true if the overlay is a distribution overlay; false otherwise.
func (Overlay) IsSiteOverlay ¶
IsSiteOverlay determines whether the overlay is a site overlay.
A site overlay is identified by its parent directory matching the configured site overlay directory path.
Returns:
- true if the overlay is a site overlay; false otherwise.
func (Overlay) Name ¶
Name returns the base name of the overlay directory.
This is derived from the full path of the overlay.
func (Overlay) ParseCommentVars ¶
ParseCommentVars parses a template file for comments that contain variable documentations. The comments must be in the format `{{/* key: value */}}`. The content is parsed as YAML.
func (Overlay) ParseVarFields ¶
ParseVarFields returns detailed type information for each variable in the template by using reflection to resolve the actual struct fields being referenced.
func (Overlay) Path ¶
Path returns the string representation of the overlay path.
This method allows the Overlay type to be easily converted back to its underlying string representation.
func (Overlay) Rootfs ¶
Rootfs returns the path to the root filesystem (rootfs) within the overlay.
If the "rootfs" directory exists inside the overlay path, it returns the path to the "rootfs" directory. Otherwise, it checks if the overlay path itself is a directory and returns that. If neither exists, it defaults to returning the "rootfs" path.
type TemplateStruct ¶
type TemplateStruct struct {
Id string
Hostname string
BuildHost string
BuildTime string
BuildTimeUnix string
BuildSource string
Ipaddr string
IpCIDR string
Netmask string
Network string
NetworkCIDR string
Overlay string
Ipaddr6 string
PrefixLen6 string
IpCIDR6 string
Network6 string
NetworkCIDR6 string
Ipv6 bool
Dhcp warewulfconf.DHCPConf
Nfs warewulfconf.NFSConf
Ssh warewulfconf.SSHConf
Warewulf warewulfconf.WarewulfConf
Tftp warewulfconf.TFTPConf
Paths warewulfconf.BuildConfig
AllNodes []node.Node
node.Node
// backward compatiblity
Container string
ContainerName string
ThisNode *node.Node
}
struct which contains the variables to which are available in the templates.
func InitStruct ¶
func InitStruct(overlayName string, nodeData node.Node, allNodes []node.Node) (TemplateStruct, error)
Initialize an TemplateStruct with the given node.NodeInfo