Merge pull request #7 from OpenCHAMI/improvements
Small miscellaneous improvements
This commit is contained in:
commit
c197afddce
9 changed files with 53 additions and 20 deletions
13
README.md
13
README.md
|
|
@ -62,7 +62,7 @@ type Generator interface {
|
|||
}
|
||||
```
|
||||
|
||||
A new plugin can be created by implementing the methods from interface and exporting a symbol with `Generator` as the name and the plugin struct as the type. The `GetName()` function returns the name that is used for looking up the corresponding template set in your config file. The `GetGroups()` function is used to look all of the groups that the plugin is included. The `Generate` function is where the magic happens to build the config file from a template.
|
||||
A new plugin can be created by implementing the methods from interface and exporting a symbol with `Generator` as the name and the plugin struct as the type. The `GetName()` function returns the name that is used for looking up the corresponding template set in your config file. It can also be included in the templated files with the default plugins using the `{{ plugin_name }}` in your template. The `GetVersion()` and `GetDescription()` functions returns the version and description of the plugin which can be included in the templated files using `{{ plugin_version }}` and `{{ plugin_description }}` respectively with the default plugins. The `Generate` function is where the magic happens to build the config file from a template.
|
||||
|
||||
```go
|
||||
package main
|
||||
|
|
@ -83,7 +83,7 @@ func (g *MyGenerator) GetDescription() string {
|
|||
return "This is an example plugin."
|
||||
}
|
||||
|
||||
func (g *MyGenerator) Generate(config *configurator.Config, opts ...util.Option) (map[string][]byte, error) {
|
||||
func (g *MyGenerator) Generate(config *configurator.Config, opts ...util.Option) (generator.Files, error) {
|
||||
// do config generation stuff here...
|
||||
var (
|
||||
params = generator.GetParams(opts...)
|
||||
|
|
@ -92,16 +92,19 @@ func (g *MyGenerator) Generate(config *configurator.Config, opts ...util.Option)
|
|||
)
|
||||
if client {
|
||||
eths, err := client.FetchEthernetInterfaces(opts...)
|
||||
// ... blah, blah, blah, format output, and so on...
|
||||
// ... blah, blah, blah, check error, format output, and so on...
|
||||
}
|
||||
|
||||
// apply the substitutions to Jinja template and return output as byte array
|
||||
return generator.ApplyTemplate(path, generator.Mappings{
|
||||
"hosts": output,
|
||||
"plugin_name": g.GetName(),
|
||||
"plugin_version": g.GetVersion(),
|
||||
"plugin_description": g.GetDescription(),
|
||||
"output": output,
|
||||
})
|
||||
}
|
||||
|
||||
// this MUST be named "Generator" for symbol lookup
|
||||
// this MUST be named "Generator" for symbol lookup in main driver
|
||||
var Generator MyGenerator
|
||||
```
|
||||
|
||||
|
|
|
|||
15
cmd/fetch.go
15
cmd/fetch.go
|
|
@ -13,8 +13,9 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
remoteHost string
|
||||
remotePort int
|
||||
accessToken string
|
||||
remoteHost string
|
||||
remotePort int
|
||||
)
|
||||
|
||||
var fetchCmd = &cobra.Command{
|
||||
|
|
@ -26,11 +27,16 @@ var fetchCmd = &cobra.Command{
|
|||
logrus.Errorf("no '--host' argument set")
|
||||
return
|
||||
}
|
||||
for _, target := range targets {
|
||||
|
||||
headers := map[string]string{}
|
||||
if accessToken != "" {
|
||||
headers["Authorization"] = "Bearer " + accessToken
|
||||
}
|
||||
|
||||
for _, target := range targets {
|
||||
// make a request for each target
|
||||
url := fmt.Sprintf("%s:%d/generate?target=%s", remoteHost, remotePort, target)
|
||||
res, body, err := util.MakeRequest(url, http.MethodGet, nil, nil)
|
||||
res, body, err := util.MakeRequest(url, http.MethodGet, nil, headers)
|
||||
if err != nil {
|
||||
logrus.Errorf("failed to make request: %v", err)
|
||||
return
|
||||
|
|
@ -49,6 +55,7 @@ func init() {
|
|||
fetchCmd.Flags().IntVar(&remotePort, "port", 3334, "set the remote configurator port")
|
||||
fetchCmd.Flags().StringSliceVar(&targets, "target", nil, "set the target configs to make")
|
||||
fetchCmd.Flags().StringVarP(&outputPath, "output", "o", "", "set the output path for config targets")
|
||||
fetchCmd.Flags().StringVar(&accessToken, "access-token", "o", "", "set the output path for config targets")
|
||||
|
||||
rootCmd.AddCommand(fetchCmd)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
#
|
||||
# This file was auto-generated by the OpenCHAMI "configurator" tool using the "{{name}}" plugin.
|
||||
# This file was auto-generated by the OpenCHAMI "configurator" tool using the following plugin:
|
||||
# Name: {{ plugin_name }}
|
||||
# Version: {{ plugin_version }}
|
||||
# Description: {{ plugin_description }}
|
||||
#
|
||||
# Source code: https://github.com/OpenCHAMI/configurator
|
||||
# Creating plugins: https://github.com/OpenCHAMI/configurator/blob/main/README.md#creating-generator-plugins
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
#
|
||||
# This file was auto-generated by the OpenCHAMI "configurator" tool using the "{{name}}" plugin.
|
||||
# This file was auto-generated by the OpenCHAMI "configurator" tool using the following plugin:
|
||||
# Name: {{ plugin_name }}
|
||||
# Version: {{ plugin_version }}
|
||||
# Description: {{ plugin_description }}
|
||||
#
|
||||
# Source code: https://github.com/OpenCHAMI/configurator
|
||||
# Creating plugins: https://github.com/OpenCHAMI/configurator/blob/main/README.md#creating-generator-plugins
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
#
|
||||
# This file was auto-generated by the OpenCHAMI "configurator" tool using the "{{name}}" plugin.
|
||||
# This file was auto-generated by the OpenCHAMI "configurator" tool using the following plugin:
|
||||
# Name: {{ plugin_name }}
|
||||
# Version: {{ plugin_version }}
|
||||
# Description: {{ plugin_description }}
|
||||
#
|
||||
# Source code: https://github.com/OpenCHAMI/configurator
|
||||
# Creating plugins: https://github.com/OpenCHAMI/configurator/blob/main/README.md#creating-generator-plugins
|
||||
#
|
||||
{{ output }}
|
||||
{{ dhcp-hosts }}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,11 @@
|
|||
#
|
||||
# Ansible managed
|
||||
# This file was auto-generated by the OpenCHAMI "configurator" tool using the following plugin:
|
||||
# Name: {{ plugin_name }}
|
||||
# Version: {{ plugin_version }}
|
||||
# Description: {{ plugin_description }}
|
||||
#
|
||||
# Source code: https://github.com/OpenCHAMI/configurator
|
||||
# Creating plugins: https://github.com/OpenCHAMI/configurator/blob/main/README.md#creating-generator-plugins
|
||||
#
|
||||
include "/etc/powerman/ipmipower.dev"
|
||||
include "/etc/powerman/ipmi.dev"
|
||||
|
|
|
|||
|
|
@ -61,8 +61,11 @@ func (g *Conman) Generate(config *configurator.Config, opts ...util.Option) (map
|
|||
|
||||
// apply template substitutions and return output as byte array
|
||||
return generator.ApplyTemplates(generator.Mappings{
|
||||
"server_opts": "",
|
||||
"global_opts": "",
|
||||
"plugin_name": g.GetName(),
|
||||
"plugin_version": g.GetVersion(),
|
||||
"plugin_description": g.GetDescription(),
|
||||
"server_opts": "",
|
||||
"global_opts": "",
|
||||
}, target.Templates...)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,8 +65,11 @@ func (g *Dhcpd) Generate(config *configurator.Config, opts ...util.Option) (gene
|
|||
}
|
||||
}
|
||||
return generator.ApplyTemplates(generator.Mappings{
|
||||
"compute_nodes": compute_nodes,
|
||||
"node_entries": "",
|
||||
"plugin_name": g.GetName(),
|
||||
"plugin_version": g.GetVersion(),
|
||||
"plugin_description": g.GetDescription(),
|
||||
"compute_nodes": compute_nodes,
|
||||
"node_entries": "",
|
||||
}, target.Templates...)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,8 +75,10 @@ func (g *DnsMasq) Generate(config *configurator.Config, opts ...util.Option) (ma
|
|||
|
||||
// apply template substitutions and return output as byte array
|
||||
return generator.ApplyTemplates(generator.Mappings{
|
||||
"name": g.GetName(),
|
||||
"output": output,
|
||||
"plugin_name": g.GetName(),
|
||||
"plugin_version": g.GetVersion(),
|
||||
"plugin_description": g.GetDescription(),
|
||||
"dhcp-hosts": output,
|
||||
}, target.Templates...)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue