ytti / oxidized

Oxidized is a network device configuration backup tool. It's a RANCID replacement!
Apache License 2.0
2.8k stars 927 forks source link

How to view junos config as set commands? #2138

Closed basondole closed 1 year ago

basondole commented 4 years ago

Hello

Have created the model file as described below, how can I access the config displayed as set commands?

$ cat /opt/oxidized/.config/oxidized/model/junos.rb
require 'oxidized/model/junos.rb'

class JunOS

    cmd 'show interface diagnostic optics' do |cfg|
        comment cfg
    end

    cmd 'show configuration | display set' do |cfg|
        cfg.type = "junos-set"
        cfg.name = "set"
        cfg
    end

end
systeembeheerder commented 4 years ago

copy https://github.com/ytti/oxidized/blob/master/lib/oxidized/model/junos.rb to /opt/oxidized/.config/oxidized/model/junos.rb change line 40 to cmd 'show configuration | display set'

systeembeheerder commented 4 years ago

I suggest Oxidized chooses a default. Currently vyatta.rb does return the set commands, junos.rb not.

wk commented 4 years ago

@systeembeheerder I believe a PR that reverts vyatta model output to the default, plus documents the required change in the model documentation will be accepted; the goal is to always store the native configuration output by default, unless the model outputs an incomplete configuration using the default output mode (in which case a different modifier can be selected). There is currently discussion to add a configuration knob for alternative outputs (e.g. vyatta 'commands', junos 'set' and iosxr 'formal') to make this more streamlined.

@basondole your implementation is correct, and will result in additional files being created as described in docs/Creating-Models.md, however at present - only the git output type implements the multi-output functionality. If you happen to use the file rather than git output, multi-output is unfortunately not supported. In this scenario, you can instead replace the cmd block in the following manner in your custom ~/.config/oxidized/model/junos.rb file (pseudo-code, untested, but shouldn't be too far!):

require 'oxidized/model/junos.rb'

class JunOS

    cmd :clear, 'show configuration' do |cfg|
        cfg = "" # This isn't elegant, but it does the needful.
    end

    cmd 'show configuration | display set'

end

This will monkey patch the existing model to replace the command.

basondole commented 4 years ago

Hello @wk thanks for the tip. My oxidized config for output

output:
  default: git
  git:
    user: paul
    email: example@me.com
    repo: "/opt/oxidized/.config/oxidized/configs"

I did a git clone /opt/oxidized/.config/oxidized/configs I can see set folder with config inside. Is it possible to have the set style config appear in the web GUI? Will that modification you suggested above achieve that goal?

wk commented 4 years ago

Hi! Thanks for the additional details.

The web UI has no support for secondary outputs at this time. With the git output, you should be able to find the secondary output in the repository as a file, but will still see the primary output in the UI.

If UI integration is key in your use case, replacing the original command with the display set variant so that it is the primary output (the approach proposed by @systeembeheerder and a variant of which is the 2nd alternative in my previous comment) would be the way to go.

basondole commented 4 years ago

Hello @wk I could not get below code to work

require 'oxidized/model/junos.rb'

class JunOS

    cmd :clear, 'show configuration' do |cfg|
        cfg = "" # This isn't elegant, but it does the needful.
    end

    cmd 'show configuration | display set'

end

However by following @systeembeheerder instruction I have been able to get the set-style config to show in web UI. Now I would also want to keep the default config style in the repo. Have tried editing https://github.com/ytti/oxidized/blob/master/lib/oxidized/model/junos.rb and adding below, just above the last "closing" end

  cmd 'show configuration | display omit' do |cfg|
      cfg.type = "junos-default"
      cfg.name = "default"
      cfg
  end

end

But have not been successful. Is there a way to make this possible?