summaryrefslogtreecommitdiff
path: root/lib/oxidized/output/git.rb
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2014-08-07 13:27:03 +0300
committerSaku Ytti <saku@ytti.fi>2014-08-07 13:27:03 +0300
commit2a77796a7caf10601ae8edea5bf996f951694985 (patch)
treee38454fe9e78f16231049ed8c44365b7ea476244 /lib/oxidized/output/git.rb
parentbf299889f54b468412df4822b515cf7c4d60f90d (diff)
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.
Diffstat (limited to 'lib/oxidized/output/git.rb')
-rw-r--r--lib/oxidized/output/git.rb43
1 files changed, 29 insertions, 14 deletions
diff --git a/lib/oxidized/output/git.rb b/lib/oxidized/output/git.rb
index 18c2cc1..59b6bd4 100644
--- a/lib/oxidized/output/git.rb
+++ b/lib/oxidized/output/git.rb
@@ -20,23 +20,27 @@ class Git < Output
end
end
- def store file, data, opt={}
- msg = opt[:msg]
- user = (opt[:user] or @cfg.user)
- email = (opt[:email] or @cfg.email)
- repo = @cfg.repo
- if opt[:group]
- repo = File.join File.dirname(repo), opt[:group] + '.git'
- end
- begin
- repo = Rugged::Repository.new repo
- update_repo repo, file, data, msg, user, email
- rescue Rugged::OSError, Rugged::RepositoryError
- Rugged::Repository.init_at repo, :bare
- retry
+ def store file, outputs, opt={}
+ data = outputs.to_cfg
+ @msg = opt[:msg]
+ @user = (opt[:user] or @cfg.user)
+ @email = (opt[:email] or @cfg.email)
+ @opt = opt
+ repo = @cfg.repo
+
+ outputs.types.each do |type|
+ next if type == 'cfg'
+ type_repo = File.join File.dirname(repo), type + '.git'
+ outputs.type(type).each do |output|
+ type_file = file + '--' + output[:name].strip.gsub(/\s+/, '_')
+ update type_repo, type_file, output[:output]
+ end
end
+
+ update repo, file, outputs.to_cfg
end
+
def fetch node, group
begin
repo = @cfg.repo
@@ -54,6 +58,17 @@ class Git < Output
private
+ def update repo, file, data
+ if @opt[:group]
+ repo = File.join File.dirname(repo), @opt[:group] + '.git'
+ end
+ repo = Rugged::Repository.new repo
+ update_repo repo, file, data, @msg, @user, @email
+ rescue Rugged::OSError, Rugged::RepositoryError
+ Rugged::Repository.init_at repo, :bare
+ retry
+ end
+
def update_repo repo, file, data, msg, user, email
oid = repo.write data, :blob
index = repo.index