Closed candlerb closed 1 year ago
The example is broken, send
does not expect prompt. If prompt anyhow comes, then next cmd
may end before it sees any new text, because it sees unconsumed prompt in output and decides it got the config.
We have at least 3 cases: a) no enable b) enable, but no password (returns to propmt) c) enable, with password (gets enable password prompt)
This would take care of those three cases:
post_login do
if vars(:enable) == true
cmd "enable"
elsif vars(:enable)
send "enable\n" ## optionally add second argument which is regexp for the enable pw prompt
cmd vars(:enable)
end
end
That's better, but you still have to correctly configure which devices need enable plus password, which devices need enable, and which devices don't need enable.
Could this be handled automatically?
This would allow you to set a global default enable password, which would only be used when required.
Well this clearly isn't universal. Whole concept of 'enable' isn't universal. Prompt isn't universal. So what ever it is, it has to be in the model, not generic.
And if you have enable password, we cannot know what it is, so you have to give it to us, if you give it to us, we know we need to enable.
Only thing that could be improved, is case where enable is needed but not enable password. But which platforms cannot be configured to autoenable? I know IOS can (And should) be, so how many use cases i it actually covering?
Actually, in rancid I also had to explicitly set add autoenable ... 1
to those devices which didn't require an enable command to be sent, so I can't really complain :-)
However, rancid (at least clogin) does automatically detect after sending the "enable" command whether any password needs to be sent or not:
send "$enacmd\r"
expect {
-re "$u_prompt" { send -- "$enauser\r"; exp_continue}
-re "$e_prompt" { send -- "$enapasswd\r"; exp_continue}
"#" { set prompt "#" }
In oxidized I have to set either enable: "string"
or enable: True
, which is not an unreasonable requirement. However if I map the "enable" var to a column in the CSV file, I can't set the True
value. The only way I can think of doing this is to have a fake model:
models:
powerconnect_autoenable:
vars:
enable: true
model_map:
powerconnect_autoenable: powerconnect
That's a little messy. Alternatives might be to have a special sentinel value in the CSV file, or a separate autoenable
var instead of the magic value enable: True
.
Aside: I only reported this because I've just done a migration of a bunch of devices from rancid to oxidized, and oxidized is better than rancid in almost every way.
But with rancid, I do find login problems are easier to debug since you can run clogin
and friends directly from the command line.
The approach I ended up with for oxidized was:
I didn't leave the previous devices uncommented, because each time I restart oxidized, it starts connecting to all devices again from scratch. Perhaps I could have changed router.db and then used the "reload" or "refresh" functionality in oxidized-web; I only realised this afterwards.
If oxidized-web had a button for "connect to this device now and show me the debug output", that would be awesome :-)
(And also no automatic retries in that debug mode)
But I am nit-picking. After I had managed to work out why each device was failing to login, it is working very nicely now. Thank you!
"true" string in CVS file will become true value, so you can do it from CSV, if you can't its a bug.
This is nothing inherently stopping you from detecting enable prompt in model and sending enter if no enable is configured. We can look at the prompt, look if it has > and send enable + new line, per model.
For debugging, you're right. Easiest is just to have mock router.db with single device. I'm happy to accept PR for enhancements to debugging too.
I have some Dell Powerconnect 5524 and an N1548.
5524 are fine. With the N1548, initially I was getting downloaded and stored config like this:
The problem was actually that I had not set an enable password in oxidized, and after configuring it was fine.
However it would be good if the powerconnect module (and perhaps others) could be more robust against problems with not being in enable mode when necessary. Ideas:
Match the enable and non-enable prompts separately; error if we are not in enable mode and no enable password has been set. (This would basically auto-detect whether the enable command needs to be sent)
If there is an error from command output, abort rather than accepting it as valid
I'm not sure the best way to approach this within oxidized framework. I see that ios.rb has some code to do this, but it is commented out and "non-preferred"
As an aside, that code also doesn't check whether an enable password is prompted for. Some AAA configs will take you straight into enable mode when you type "enable".