Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The future of gornir.New() #24

Open
nleiva opened this issue Jun 8, 2019 · 2 comments
Open

The future of gornir.New() #24

nleiva opened this issue Jun 8, 2019 · 2 comments

Comments

@nleiva
Copy link
Collaborator

nleiva commented Jun 8, 2019

Should gornir.New() provide safe defaults?. Should require you to provide mandatory attributes?. Today looks as simple as:

func New() *Gornir {
	return new(Gornir)
}
@dbarrosop
Copy link
Contributor

dbarrosop commented Jun 9, 2019

I think everything should provide sane defaults, problem is that there are no sane defaults in the Gornir object (at least for now). I also don't think gornir.New() is the place to provide sane defaults, instead, each plugin should handle its own sane defaults and gornir.New construct a valid Gornir object. For instance:

// url is mandatory while optsForNSOT overrides some default values
inv, err := inventory.NewSomeRESTInventory(url, optsForNSOT...)
if err != nil {
   // handle err
}

// address is mandatory while optsForES overrides some default values
logger := logger.NewSomeLogger(address, optsForES...)
if err != nil {
   // handle err
}
// Parallel doesn't have mandatory options so everything is set via optsParallel
rnr := runner.Parallel(optsParallel...)

gr := gornir.New(logger, inv, rnr)

So each plugin handles its own defaults and optional builders (I am thinking the pattern you originally proposed for gornir would be great for the plugins) while gornir is just what glues everything together.

@dbarrosop
Copy link
Contributor

Later on we could also implement complex "initializers" that abstracts the pattern above (as another form of plugin?). For instance, nornir has the same pattern as described above (ish) but then there is an initializer InitNornir that takes a configuration file in YAML format and does all the magic for you. For instance:

---
core:
    num_workers: 20
inventory:
    plugin: nornir.plugins.inventory.simple.SimpleInventory
    options:
        host_file: "advanced_filtering/inventory/hosts.yaml"
        group_file: "advanced_filtering/inventory/groups.yaml"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants