-
Notifications
You must be signed in to change notification settings - Fork 276
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
Scrapligo as transport #737
Conversation
Hey @iprouteget Let's move what you named a 'driver' config under the 'config.transport.scrapli' struct. |
Thanks @hellt! It's funny, I actually tried doing something similar the first time. Just to be clear of your plan, the file would look something like (as an example):
Which could be populated by at the node level or a higher up (e.g. Kinds) level? |
Yes, exactly like you showed in the snippet.
The config structure follows the usual descendency chain: defaults -> kind
-> node
Meaning that for example you could have defined a transport for the whole
crpd kind and it would have been inherited by all the crpd nodes.
The most specific config wins
…On Wed, 29 Dec 2021 at 00:35, Alex Kirby ***@***.***> wrote:
Thanks @hellt <https://github.com/hellt>! It's funny, I actually tried
doing something similar the first time. Just to be clear of your plan, the
file would look something like (as an example):
nodes:
sp1:
kind: crpd
image: crpd:21.3R1.9
config:
vars:
var1: <value>
var2: <value>
transport:
scrapli:
ssh-config-file: <file path>
username: <username>
gnmi:
Which could be populated by at the node level or a higher up (e.g. Kinds)
level?
—
Reply to this email directly, view it on GitHub
<#737 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABLKV5ITTAL2DO7K5A6G2FTUTJCSVANCNFSM5K43O5CA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Sounds good. This latest push does the following:
I mentioned in a comment about setting default values when parsing the yaml file. I don't think the way I did it for scrapli's default port is best; I thought setting a struct tag would work, but I am probably missing something easy here. Examples of output: Yaml file (only part to show the updates):
Topology:
cRPD nodes with startup config (prior to config push):
And after pushing the config:
cRPD node
|
Hi @iprouteget 1 transport interfaceThe idea behind containerab' support of multiple transports lies within Go interfaces. There is a Transport interface defined here that we need to use. This requirement also stands true for the the scrapligo transport. Hence, we need to write define those methods for Scrapli transport and use them inside the You may check how this was done for the embedded transport - https://github.com/iprouteget/containerlab/blob/scrapligo-as-transport/clab/config/transport/ssh.go#L234 2 Transport configurationCurrently you implemented the fallthrough logic of transport configuration. Namely, if the scrapli transport is defined on a node level it is returned. Otherwise the kind transport is used, and last resort is the default transport. For example, a user may want to define some kind specific params of the scrapli transport on the |
Hi @hellt! This makes sense, thank you for the feedback. I should be able to get some updates in over the weekend. I appreciate your patience! |
I'm not convinced the Transport Interface is the correct solution here, or put differently, it might not be complete in its current form: While we can adapt the transport mechanism to connect to the router, we lack any form of transactions (send, commit, compare), and these transactions can be implemented completely differently based on the transport provider. Taking the existing embedded ssh implementation as an example. It follows Connect, Session_start, Write, Session_end and then Close. Maybe session_start/end can use Transport's Write method (but a generic write is not flexible enough), and in some implementations there is already some transactional functionality built in (at least when I looked at Scrapligo in the past). The transaction and write according to me is too closely coupled to try separate them. I also had a use case to use custom ports, which required influencing the connect. For all these cases I simply started using a method to send the config const (
ActionSend = "send"
ActionCompare = "compare"
ActionCommit = "commit"
)
func ConfigSend(c *config.NodeConfig, action string) ([]*transport.SSHReply, error) { |
@kellerza Let's take the scrapligo example and the use cases our users might need 1 Configuring the device by sending commandsThe most common use case, the goal is to get a device to a certain configuration state by sending and applying config commands as if they were entered over the CLI. Scrapligo offers the following method - SendConfigs - which takes a slice of strings representing commands. This method will (in the background) acquire the configuration level privilege that is relevant to the specified NOS (like This method does not imply any particular 2 Sending commands which do not require configuration context. Aka
|
This sound more like we need multiple Transport implementations, one for SendConfigs and one for SendCommands.
Indeed in the very first iteration, but we have CLI to select the action since a while already (see below)
btw, in my view even |
Hi all, just catching up here. I'm still working on merging the transport structs for default/kind/node, but I wanted to submit the first item regarding the move to the Transport interface. This cleaned up send.go quite a bit. Based on these more recent notes, perhaps I need to look at adding some transport options to incorporate a broader range of functions instead of only committing the configuration. Currently, I'm just using scrapligo's cfg driver, which seems to work for pushing the configurations. |
Phew, it's been a hot minute since I've been able to look at this again. From the notes provided earlier, I tried moving the scrapli code to use the existing transport interface, which seems to be working so far. @hellt, regarding the merging of structs, I just copied the example you provided in discord since it was lightweight and straightforward. I figured once there are more complex types, we'd start testing more mergo? I still see some things in my code that probably need refactoring, but I want to make sure I'm on the correct path regarding the two main items mentioned. |
Hey @iprouteget |
Awesome! Much appreciated. I'll add some tests this week as well. |
@iprouteget do you mind checking if you can port some cleanup changes I started to do in #734 with regards to config engine cleanup? Then I could retire that PR |
Will do! |
Okay I believe I have the cleanup items from #734, and I also added a test for the MergeStructConfigs function. |
Hi @iprouteget
|
Hi @hellt, all good! I'll update this accordingly. |
@hellt with the amount of time that has passed and the updates to scrapligo, I feel like it would make more sense to close this out and start fresh :) It might allow for breaking up some parts into smaller PRs. Let me know if this works best. Thanks! |
That makes a alot of sense to me indeed
…On Tue, 2 Aug 2022 at 20:04, Alex Kirby ***@***.***> wrote:
@hellt <https://github.com/hellt> with the amount of time that has passed
and the updates to scrapligo, I feel like it would make more sense to close
this out and start fresh :) It might allow for breaking up some parts into
smaller PRs. Let me know if this works best. Thanks!
—
Reply to this email directly, view it on GitHub
<#737 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABLKV5MAGZYS7KIEZNXXB6TVXFPJNANCNFSM5K43O5CA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
This aims to replace the embedded SSH transport used for the
config
command with scrapligo's various network drivers (#668).This might have been more overkill, but I thought it would be neat to be able to set various driver options directly in the yaml file (e.g. username, password, ssh config, private key file, etc). At the same time, I wanted to make sure only certain options (e.g. most everything here) were available.
I still need to test among the various platforms, but this seems to work on crpd so far:
I was able to then use the following command to push generated configs from templates using:
sudo ~/test/containerlab/bin/containerlab config -t junos-routed-fabric.clab.yml template -p ./templates/ -l net-cfg
This is my first ever PR to an open source project, so I welcome any and all scrutiny!