oxidized: Named variaton for a model results in undefined method `new' for nil:NilClass

As per the documentation here (https://github.com/ytti/oxidized/blob/master/docs/Creating-Models.md) it is mentioned that it is possible to create named variations for existing models. This is a great feature that I would like to use.

When following the documentation:

Create a named variation of an existing model, by creating a file with a new name (such as ~/.config/oxidized/model/junos-extra.rb), Then require the original model and extend its base class as in the above example. The named variation can then be specified as an OS type for specific devices that can benefit from the extra functionality. This allows for preservation of the base functionality for the default model types.

I am getting this exception after running oxidized:

/var/lib/gems/2.3.0/gems/oxidized-0.26.3/lib/oxidized/manager.rb:17:in `load': undefined method `new' for nil:NilClass (NoMethodError)
    from /var/lib/gems/2.3.0/gems/oxidized-0.26.3/lib/oxidized/manager.rb:59:in `loader'
    from /var/lib/gems/2.3.0/gems/oxidized-0.26.3/lib/oxidized/manager.rb:47:in `add_model'
    from /var/lib/gems/2.3.0/gems/oxidized-0.26.3/lib/oxidized/node.rb:170:in `resolve_model'
    from /var/lib/gems/2.3.0/gems/oxidized-0.26.3/lib/oxidized/node.rb:22:in `initialize'
    from /var/lib/gems/2.3.0/gems/oxidized-0.26.3/lib/oxidized/nodes.rb:21:in `new'
    from /var/lib/gems/2.3.0/gems/oxidized-0.26.3/lib/oxidized/nodes.rb:21:in `block (2 levels) in load'
    from /var/lib/gems/2.3.0/gems/oxidized-0.26.3/lib/oxidized/nodes.rb:16:in `each'
    from /var/lib/gems/2.3.0/gems/oxidized-0.26.3/lib/oxidized/nodes.rb:16:in `block in load'
    from /var/lib/gems/2.3.0/gems/oxidized-0.26.3/lib/oxidized/nodes.rb:130:in `synchronize'
    from /var/lib/gems/2.3.0/gems/oxidized-0.26.3/lib/oxidized/nodes.rb:130:in `with_lock'
    from /var/lib/gems/2.3.0/gems/oxidized-0.26.3/lib/oxidized/nodes.rb:10:in `load'
    from /var/lib/gems/2.3.0/gems/oxidized-0.26.3/lib/oxidized/nodes.rb:125:in `initialize'
    from /var/lib/gems/2.3.0/gems/oxidized-0.26.3/lib/oxidized/core.rb:14:in `new'
    from /var/lib/gems/2.3.0/gems/oxidized-0.26.3/lib/oxidized/core.rb:14:in `initialize'
    from /var/lib/gems/2.3.0/gems/oxidized-0.26.3/lib/oxidized/core.rb:4:in `new'
    from /var/lib/gems/2.3.0/gems/oxidized-0.26.3/lib/oxidized/core.rb:4:in `new'
    from /var/lib/gems/2.3.0/gems/oxidized-0.26.3/lib/oxidized/cli.rb:13:in `run'
    from /var/lib/gems/2.3.0/gems/oxidized-0.26.3/bin/oxidized:8:in `<top (required)>'
    from /usr/local/bin/oxidized:23:in `load'
    from /usr/local/bin/oxidized:23:in `<main>'

Our setup includes:

  • Ubuntu 16.04.6 LTS
  • Ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]
  • oxidized 0.26.3

This is the router.db file I use:

$ cat ~/.config/oxidized/router.db
router1:10.0.0.1:arista:oxidized:somepassword
router2:10.0.0.2:arista-extra:oxidized:anotherpassword

This is the config file I use:

$ cat ~/.config/oxidized/config
---
interval: 3600
log: /home/oxidized/.config/oxidized/logs2
debug: true
threads: 30
timeout: 10
retries: 0
resolve_dns: false
rest: 127.0.0.1:28888
prompt: !ruby/regexp /^([\w.@-]+[#>]\s?)$/
vars:
  auth_methods: [ "none", "publickey", "password", "keyboard-interactive" ]
  remove_secret: true
groups: {}
crash:
  directory: /home/oxidized/.config/oxidized/crashes
  hostnames: false
input:
  default: ssh
  debug: true
  ssh:
    secure: false
output:
  default: file
  file:
    directory: /home/oxidized/.config/oxidized/nodes
source:
  default: csv
  csv:
    file: /home/oxidized/.config/oxidized/router.db
    delimiter: !ruby/regexp /:/
    map:
      name: 0
      ip: 1
      model: 2
      username: 3
      password: 4
model_map:
  arista: eos
  arista-extra: eos-extra

The named variaton that defines eos-extra:

$ cat ~/.config/oxidized/model/eos-extra.rb
require 'oxidized/model/eos.rb'

class EOS
  cmd 'show ip route | no-more' do |cfg|
    comment cfg
  end
end

I do see the following debug messages in the oxidized logs just before the crash:

D, [2019-09-14T09:52:06.266090 #18752] DEBUG -- : node.rb: resolving node key 'model', with passed global value of '' and node value 'eos-extra'
D, [2019-09-14T09:52:06.266119 #18752] DEBUG -- : node.rb: setting node key 'model' to value 'junos' from global
D, [2019-09-14T09:52:06.266145 #18752] DEBUG -- : node.rb: returning node key 'model' with value 'eos-extra'
D, [2019-09-14T09:52:06.266167 #18752] DEBUG -- : lib/oxidized/node.rb: Loading model "eos-extra"
D, [2019-09-14T09:52:06.266347 #18752] DEBUG -- : lib/oxidized/model/model.rb Added show ip route | no-more to the commands list
F, [2019-09-14T09:52:06.266701 #18752] FATAL -- : Oxidized crashed, crashfile written in /home/oxidized/.config/oxidized/crash

The new command gets added to the commands list so the named variation file is found and read.

Are you able to help me point out what I am doing wrong here? I am more then willing to contribute to the documentation in this repository once I have a working setup.

Again, thank you so much for your efforts in creating and maintaining this awesome library!

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 25 (15 by maintainers)

Most upvoted comments

I just released 0.27.0.

Email works, saku@ytti.fi

I’d need to think about this more, I don’t understand why subclassing and dup do not work. You shouldn’t be modifying the existing EOS class at all. I don’t currently understand the the outcome.

What about

EOSExtra = EOS.dup

file: pooper.rb

👍 😆