From 2a77796a7caf10601ae8edea5bf996f951694985 Mon Sep 17 00:00:00 2001 From: Saku Ytti Date: Thu, 7 Aug 2014 13:27:03 +0300 Subject: Pass model config as Outputs object instead of str 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. --- lib/oxidized/model/outputs.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 lib/oxidized/model/outputs.rb (limited to 'lib/oxidized/model/outputs.rb') diff --git a/lib/oxidized/model/outputs.rb b/lib/oxidized/model/outputs.rb new file mode 100644 index 0000000..5ef9bc4 --- /dev/null +++ b/lib/oxidized/model/outputs.rb @@ -0,0 +1,43 @@ +module Oxidized + class Model + class Outputs + + def to_cfg + type_to_str('cfg') + end + + def type_to_str want_type + type(want_type).map { |h| h[:output] }.join + end + + def each_type &block + types.each do |want_type| + yield [want_type, type(want_type)] + end + end + + def << output + @outputs << output + end + + def all + @outputs + end + + def type type + @outputs.select { |h| h[:type]==type } + end + + def types + @outputs.map { |h| h[:type] }.uniq + end + + private + + def initialize + @outputs = [] + end + + end + end +end -- cgit v1.2.1