Skip to content
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

Extend model, crash oxidized #3118

Closed
marmack95 opened this issue Apr 10, 2024 · 2 comments
Closed

Extend model, crash oxidized #3118

marmack95 opened this issue Apr 10, 2024 · 2 comments

Comments

@marmack95
Copy link

marmack95 commented Apr 10, 2024

Hello, i'm trying to extend a model, but it does not work.

require 'oxidized/model/comware.rb'

class CustomHP
  using Refinements

  cmd 'save force' do |cfg|
    comment cfg
  end

end

That's the result:

2024-04-10 14:53:14 UTC
undefined method `cmd' for CustomHP:Class [NoMethodError]
--------------------------------------------------
/home/oxidized/.config/oxidized/model/edl_hp.rb:12:in `<class:CustomHP>'
/home/oxidized/.config/oxidized/model/edl_hp.rb:3:in `<top (required)>'
<internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:85:in `require'
<internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:85:in `require'
/var/lib/gems/3.0.0/gems/oxidized-0.29.1/lib/oxidized/manager.rb:9:in `load'
/var/lib/gems/3.0.0/gems/oxidized-0.29.1/lib/oxidized/manager.rb:60:in `loader'
/var/lib/gems/3.0.0/gems/oxidized-0.29.1/lib/oxidized/manager.rb:48:in `add_model'
/var/lib/gems/3.0.0/gems/oxidized-0.29.1/lib/oxidized/node.rb:179:in `resolve_model'
/var/lib/gems/3.0.0/gems/oxidized-0.29.1/lib/oxidized/node.rb:23:in `initialize'
/var/lib/gems/3.0.0/gems/oxidized-0.29.1/lib/oxidized/nodes.rb:22:in `new'
/var/lib/gems/3.0.0/gems/oxidized-0.29.1/lib/oxidized/nodes.rb:22:in `block (2 levels) in load'
/var/lib/gems/3.0.0/gems/oxidized-0.29.1/lib/oxidized/nodes.rb:17:in `each'
/var/lib/gems/3.0.0/gems/oxidized-0.29.1/lib/oxidized/nodes.rb:17:in `block in load'
/var/lib/gems/3.0.0/gems/oxidized-0.29.1/lib/oxidized/nodes.rb:133:in `synchronize'
/var/lib/gems/3.0.0/gems/oxidized-0.29.1/lib/oxidized/nodes.rb:133:in `with_lock'
/var/lib/gems/3.0.0/gems/oxidized-0.29.1/lib/oxidized/nodes.rb:11:in `load'
/var/lib/gems/3.0.0/gems/oxidized-0.29.1/lib/oxidized/nodes.rb:128:in `initialize'
/var/lib/gems/3.0.0/gems/oxidized-0.29.1/lib/oxidized/core.rb:14:in `new'
/var/lib/gems/3.0.0/gems/oxidized-0.29.1/lib/oxidized/core.rb:14:in `initialize'
/var/lib/gems/3.0.0/gems/oxidized-0.29.1/lib/oxidized/core.rb:4:in `new'
/var/lib/gems/3.0.0/gems/oxidized-0.29.1/lib/oxidized/core.rb:4:in `new'
/var/lib/gems/3.0.0/gems/oxidized-0.29.1/lib/oxidized/cli.rb:13:in `run'
/var/lib/gems/3.0.0/gems/oxidized-0.29.1/bin/oxidized:5:in `<top (required)>'
/usr/local/bin/oxidized:25:in `load'
/usr/local/bin/oxidized:25:in `<main>'

If i compare with documentation: https://github.com/ytti/oxidized/blob/master/docs/Creating-Models.md
or this issue: #3017
All seems ok, but it does not work.

I use docker version (tested with the last version and version 0.29.1 of april 2023)

@marmack95
Copy link
Author

The documentation is not correct. I found the solution by adding the name of the require class as someone do it here: #2579.

require 'oxidized/model/comware.rb'

class CustomHP < Comware
...

It's works now.

@ytti
Copy link
Owner

ytti commented Apr 11, 2024

Document is extending an existing class, you are creating a new class, subclassing existing class. These are two different things. This is technically not oxidized question at all, but rather ruby question.

Usually all model classes are subclasses of Oxidized::Model, this is why custom methods like cmd work. If we don't subclass existing class, and we define entirely new class, of course there will be no Oxidized specific methods available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants