-
Notifications
You must be signed in to change notification settings - Fork 15
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
handle connections #3
Comments
Not sure how you do it in nornir, but I think you'd have to re-work how you iterate over the hosts. func (r ParallelRunner) Run(ctx gornir.Context, task gornir.Task, results chan *gornir.JobResult) error {
...
for hostname, host := range gr.Inventory.Hosts {
logger.WithField("host", hostname).Debug("calling function")
go task.Run(ctx.ForHost(host), r.wg, results)
}
...
} For a function that is run in the background, that first connects and then executes the task. Something along the lines of https://github.com/nleiva/xrgrpc/blob/master/example/setconfiglist/main.go#L47-L68. I can help you with this, just need to learn how nornir does it and whether is the best fit for Go. |
Nornir is a bit more complex/sophisticated for two reasons:
I will mock open a draft PR for discussion as I think that will be easier but the idea is to:
From an interface perspective things could look like this: // main
gr := &Gornir{...}
defer gr.Close() // this will iterate over all the hosts and close the connections
... // a task
func (t *SomeTaskOverSSH) Run(...) {
// this either gets an opened connection or establishes a new one
c, err := host.GetConnection("ssh")
if err != nil {
// handle error or return it
}
session = c.(*ssh.Session)
...
} Basically the task doesn't need to bother about opening/closing the connection, gornir handles that instead and if you run multiple tasks that require the same type of connection you don't need to keep opening/closing them. |
I was thinking about this. Forgot to open a new issues, but I think it would be better we operate over a Device interface, which defines the behavior of any given host. Something like: type Device interface {
Connect() err
SendCommand(s string) err
...
} Then we'd have implementations of this interface for an |
if no one is working on this, i would like to start from here, i will try to come up with something and submit a |
just submitted #35 for this issue, (yeah i was struggling with fixing the pipeline), gornir should be able to execute multiple commands in a single connection now by using |
Right now connections are handled by tasks, we should have gornir do that in a similar fashion to nornir
The text was updated successfully, but these errors were encountered: