generator

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2025 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultGenerators = createDefaultGenerators()

Functions

func ConvertContentsToString

func ConvertContentsToString(f FileMap) map[string]string

Converts the file outputs from map[string][]byte to map[string]string.

func GetTarget

func GetTarget(config *config.Config, key string) configurator.Target

Helper function to get the target in generator.Generate() plugin implementations.

func LoadPlugins

func LoadPlugins(dirpath string, opts ...Option) (map[string]Generator, error)

Loads all generator plugins in a given directory.

Returns a map of generators. Each generator can be accessed by the name returned by the generator.GetName() implemented.

Types

type Conman added in v0.1.1

type Conman struct{}

func (*Conman) Generate added in v0.1.1

func (g *Conman) Generate(config *config.Config, params Params) (FileMap, error)

func (*Conman) GetDescription added in v0.1.1

func (g *Conman) GetDescription() string

func (*Conman) GetName added in v0.1.1

func (g *Conman) GetName() string

func (*Conman) GetVersion added in v0.1.1

func (g *Conman) GetVersion() string

type CoreDhcp added in v0.2.0

type CoreDhcp struct{}

func (*CoreDhcp) Generate added in v0.2.0

func (g *CoreDhcp) Generate(config *config.Config, params Params) (FileMap, error)

func (*CoreDhcp) GetDescription added in v0.2.0

func (g *CoreDhcp) GetDescription() string

func (*CoreDhcp) GetName added in v0.2.0

func (g *CoreDhcp) GetName() string

func (*CoreDhcp) GetVersion added in v0.2.0

func (g *CoreDhcp) GetVersion() string

type DHCPd added in v0.1.1

type DHCPd struct{}

func (*DHCPd) Generate added in v0.1.1

func (g *DHCPd) Generate(config *config.Config, params Params) (FileMap, error)

func (*DHCPd) GetDescription added in v0.1.1

func (g *DHCPd) GetDescription() string

func (*DHCPd) GetName added in v0.1.1

func (g *DHCPd) GetName() string

func (*DHCPd) GetVersion added in v0.1.1

func (g *DHCPd) GetVersion() string

type DNSMasq added in v0.1.1

type DNSMasq struct{}

func (*DNSMasq) Generate added in v0.1.1

func (g *DNSMasq) Generate(config *config.Config, params Params) (FileMap, error)

func (*DNSMasq) GetDescription added in v0.1.1

func (g *DNSMasq) GetDescription() string

func (*DNSMasq) GetName added in v0.1.1

func (g *DNSMasq) GetName() string

func (*DNSMasq) GetVersion added in v0.1.1

func (g *DNSMasq) GetVersion() string

type Example added in v0.2.0

type Example struct {
	Message string
}

func (*Example) Generate added in v0.2.0

func (g *Example) Generate(config *config.Config, params Params) (FileMap, error)

func (*Example) GetDescription added in v0.2.0

func (g *Example) GetDescription() string

func (*Example) GetName added in v0.2.0

func (g *Example) GetName() string

func (*Example) GetVersion added in v0.2.0

func (g *Example) GetVersion() string

type FileList

type FileList [][]byte

type FileMap

type FileMap map[string][]byte

func ApplyTemplateFromFiles

func ApplyTemplateFromFiles(mappings Mappings, paths ...string) (FileMap, error)

Wrapper function similiar to "ApplyTemplates" but takes file paths as arguments. This function will load templates from a file instead of using file contents.

func ApplyTemplates

func ApplyTemplates(mappings Mappings, templates map[string]Template) (FileMap, error)

Wrapper function to slightly abstract away some of the nuances with using gonja into a single function call. This function is *mostly* for convenience and simplication. If no paths are supplied, then no templates will be applied and there will be no output.

The "FileList" returns a slice of byte arrays in the same order as the argument list supplied, but with the Jinja templating applied.

func Generate

func Generate(config *config.Config, plugin string, params Params) (FileMap, error)

Generate() is the main function to generate a collection of files and returns them as a map. This function only expects a path to a plugin and paths to a collection of templates to be used. This function will only load the plugin on-demand and fetch resources as needed.

This function requires that a target and plugin path be set at minimum.

func GenerateWithTarget

func GenerateWithTarget(config *config.Config, target string) (FileMap, error)

Main function to generate a collection of files as a map with the path as the key and the contents of the file as the value. This function currently expects a list of plugin paths to load all plugins within a directory. Then, each plugin's generator.GenerateWithTarget() function is called for each target specified.

This function is the corresponding implementation for the "generate" CLI subcommand. It is also call when running the configurator as a service with the "/generate" route.

TODO: Separate loading plugins so we can load them once when running as a service.

func LoadFiles

func LoadFiles(paths ...string) (FileMap, error)

Loads files without applying any Jinja 2 templating.

type Generator

type Generator interface {
	GetName() string
	GetVersion() string
	GetDescription() string
	Generate(config *config.Config, params Params) (FileMap, error)
}

Generator interface used to define how files are created. Plugins can be created entirely independent of the main driver program.

func LoadPlugin

func LoadPlugin(path string) (Generator, error)

Loads a single generator plugin given a single file path.

type Hostfile added in v0.1.1

type Hostfile struct{}

func (*Hostfile) Generate added in v0.1.1

func (g *Hostfile) Generate(config *config.Config, opts ...Option) (FileMap, error)

func (*Hostfile) GetDescription added in v0.1.1

func (g *Hostfile) GetDescription() string

func (*Hostfile) GetName added in v0.1.1

func (g *Hostfile) GetName() string

func (*Hostfile) GetVersion added in v0.1.1

func (g *Hostfile) GetVersion() string

type Mappings

type Mappings map[string]any

type Option added in v0.2.0

type Option func(Params)

func WithClientOpts added in v0.2.0

func WithClientOpts(opts ...client.Option) Option

func WithTemplates

func WithTemplates(templates map[string]Template) Option

type Params

type Params struct {
	Templates  map[string]Template
	Files      map[string][]byte
	ClientOpts []client.Option
	Verbose    bool
}

Params used by the generator

func ToParams added in v0.2.0

func ToParams(opts ...Option) Params

type Powerman added in v0.1.1

type Powerman struct{}

func (*Powerman) Generate added in v0.1.1

func (g *Powerman) Generate(config *config.Config, opts ...Option) (FileMap, error)

func (*Powerman) GetDescription added in v0.1.1

func (g *Powerman) GetDescription() string

func (*Powerman) GetName added in v0.1.1

func (g *Powerman) GetName() string

func (*Powerman) GetVersion added in v0.1.1

func (g *Powerman) GetVersion() string

type Syslog added in v0.1.1

type Syslog struct{}

func (*Syslog) Generate added in v0.1.1

func (g *Syslog) Generate(config *config.Config, opts ...Option) (FileMap, error)

func (*Syslog) GetDescription added in v0.1.1

func (g *Syslog) GetDescription() string

func (*Syslog) GetName added in v0.1.1

func (g *Syslog) GetName() string

func (*Syslog) GetVersion added in v0.1.1

func (g *Syslog) GetVersion() string

type Template

type Template struct {
	Contents []byte `json:"contents"`
}

func (*Template) IsEmpty added in v0.2.0

func (t *Template) IsEmpty() bool

func (*Template) LoadFromFile added in v0.2.0

func (t *Template) LoadFromFile(path string) error

type Warewulf added in v0.1.1

type Warewulf struct{}

func (*Warewulf) Generate added in v0.1.1

func (g *Warewulf) Generate(config *config.Config, params Params) (FileMap, error)

func (*Warewulf) GetDescription added in v0.1.1

func (g *Warewulf) GetDescription() string

func (*Warewulf) GetName added in v0.1.1

func (g *Warewulf) GetName() string

func (*Warewulf) GetVersion added in v0.1.1

func (g *Warewulf) GetVersion() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL