Age | Commit message (Collapse) | Author |
|
there are numerous use-cases for this in models, no point to load in
models separately
|
|
still not sure if this is the right way to guard non-string blocks...
|
|
Return empty string instead of what ever model returned.
Closes #63
|
|
|
|
- now default type is 'nil', which is collapsed to flat config via
Outputs#to_cfg
- if type is not 'nil' then name is automatically set if not set by
model
- if name and type is set, separate file is created
- if name is not set, but type is set, outputs from type are collapsed
as with 'nil' types
This model:
cmd 'show ip cef' do |out|
out.type = 'poop'
out.name = false
out
end
cmd 'show process cpu' do |out|
out.type = 'poop'
out.name = 'my_cpu'
out
end
cmd 'show memory statistics' do |out|
out.type = 'poop'
out.name = false
out
end
cmd 'show ip bgp summary' do |out|
out.type = 'poop'
end
Would produce git output:
[ytti@ytti.fi ~/.config/oxidized]% ls poop
bu.ip.fi bu.ip.fi--cpu bu.ip.fi--show_ip_bgp_summary
[ytti@ytti.fi ~/.config/oxidized]%
bu.ip.fi contains the collapsed stuff
bu.ip.fi--cpu is manually named
bu.ip.fi--show_ip_bgp_summary is automatically named
|
|
The model will look like this:
cmd 'show ip cef' do |out|
out.type = 'poop'
out
end
cmd 'show process cpu' do |out|
out.type = 'poop'
out
end
cmd 'show memory statistics' do |out|
out.type = 'poop'
out
end
I think it's cleaner.
|
|
These objects have some keys, such as 'type' and 'name', which allows
our output model to discriminate on them.
If ios.rb contains this:
cmd 'show ip cef' do |out|
{ output: out, type: 'poop' }
end
cmd 'show process cpu' do |out|
{ output: out, type: 'poop' }
end
cmd 'show memory statistics' do |out|
{ output: out, type: 'poop' }
end
Our git output looks like this:
[ytti@ytti.fi ~/.config/oxidized]% git clone oxidized.git
Cloning into 'oxidized'...
done.
[ytti@ytti.fi ~/.config/oxidized]% git clone poop.git
Cloning into 'poop'...
done.
[ytti@ytti.fi ~/.config/oxidized]% ls poop
bu.ip.fi--show_ip_cef bu.ip.fi--show_memory_statistics bu.ip.fi--show_process_cpu
[ytti@ytti.fi ~/.config/oxidized]% ls oxidized
bu.ip.fi
[ytti@ytti.fi ~/.config/oxidized]%
Where oxidized repo contains standard config for all unspecified types (type is
then 'cfg'), for all specified types instead of collapsing it into single
string, we store them in 'type' repo with filename including 'name' of the
command.
|
|
We needed this, because use of 'def inherited' not idempotent, in
Oxidized::Script use case we may need to restart Oxidized, even though
it's already loaded, and we won't get class names populated via 'def
inherited' anymore.
There are quite many optiosn to do this
a) filename == class name
+ no discovery/mapping, very clean
- user 'source' must give us model name in exactly right
capitalization
b) add 'self' at end of files, so eval will return class name
+ deterministic with arbitrary name
- DSL cruft, DSL being light is our main value
(can we do this via parent class? I couldn't find way)
c) load in new module via Module.module_eval X
+ module will contain only consts we just created
- but which one is the one we want?
- if we use eval, load errors won't tell line error
But at least now we got rid of 'inherited' methods and not adding too
much cruft, hope it's better than before.
|
|
|
|
- we need config/vars before model
- some whitespace changes
Bump up gemspec
|
|
Variables can now be fed to model from multiple locations. In order of
preference:
1) node (from source)
2) group
3) global
In a model vars should be accessed via 'vars' helper method though it is
not required. Helper method ignores nil values so care needs to taken
when designing model behaviour.
Support for node level vars is currently available on sql source via
'vars_map' configuration.
Following example populates node vars 'enable' and 'somevariable' from sql
columns 'var_enable' and 'var_somevariable'
sql:
adapter: sqlite
file: /home/aakso/.config/oxidized/sqrouter.db
table: nodes
map:
name: hostname
model: model
group: node_group
username: username
password: password
vars_map:
enable: var_enablepw
somevariable: var_somevariable
|
|
Model can inmplement something like
cmd :secret do |cfg|
cfg.sub! / secret (\d+) (\S+).*/, '\\1 SECRET'
cfg
end
Which is called for all commands if CFG.remove_secret is set
|
|
It is now separately in oxidized-web package
|
|
Will allow convenience methods such as
cmd :all do |cfg|
cfg.pop.shift
end
instead of:
cmd :all do |cfg|
cfg.each_line.to_a[1..-2].join
end
And what ever convenience configs we come up with
|
|
that was run
|
|
Block must return string, it returned nil which broke it.
Also coerce type to string in future, so block won't fail so
catastrophically, just output missing.
|
|
Both post and pre are called after all 'cmd' are already called, but
output from 'pre' is put on top of configuration output and output from
'post' is put on bottom of confguration output.
Rationale is dynamic configuration, where you'll only know after running
some commands what commands you want to run.
Both except blocks, such as
pre do
# commands to execute
end
Both can be called multiple times
|
|
Outputs about what we've seen last in input class. Quite dirty in
telnet, so not sure I'm going to support it. Let's see if there is
use-case for it.
|
|
Now we can deal with pager and additional PW prompts, such as 'enable'
Examples in IOS model how to use.
The Telnet implementation is particularly fugly, I just need one line in
'waitfor' to handle pager while waiting for prompt, but couldn't figure
out clean way to do it, so needed to rewrit whole Telnet#waitfor just to
add that line.
|
|
|
|
|
|
|
|
Gives alternative, maybe less awkward way to do conditional commands.
You can first use cmd methods to gather stuff you want, then in main
method you could conditional to things based on them, maybe futher call
methods per model.
|
|
Easier screen-scraping, if each command produces always same set of
cruft that needs to be removed
|
|
Silly for shit-and-giggles attempt at rancid
|