diff options
author | ytti <saku@ytti.fi> | 2013-10-26 02:32:51 -0700 |
---|---|---|
committer | ytti <saku@ytti.fi> | 2013-10-26 02:32:51 -0700 |
commit | f2acb9455edae1bc1c80de28af2362da9da206bf (patch) | |
tree | 3c92898daade43cdbbec317c07c2073b2a40e730 | |
parent | 4455a5b91accda5da7c1b8128cb045c7eb7bb5da (diff) | |
parent | 7982a7d3956910406e59952e1b215d5b4dd1d8e5 (diff) |
Merge pull request #8 from nopedial/master
ascii/json output initial differentiation
-rw-r--r-- | lib/oxidized.rb | 1 | ||||
-rw-r--r-- | lib/oxidized/api/rest.rb | 20 | ||||
-rw-r--r-- | lib/oxidized/model/ironware.rb | 1 | ||||
-rw-r--r-- | lib/oxidized/output/file.rb | 2 | ||||
-rw-r--r-- | lib/oxidized/output/git.rb | 9 | ||||
-rw-r--r-- | oxidized.gemspec | 2 |
6 files changed, 26 insertions, 9 deletions
diff --git a/lib/oxidized.rb b/lib/oxidized.rb index ec1a901..99b1ea6 100644 --- a/lib/oxidized.rb +++ b/lib/oxidized.rb @@ -1,4 +1,5 @@ module Oxidized + Encoding.default_external = 'UTF-8' Directory = File.expand_path File.join File.dirname(__FILE__), '../' require 'oxidized/core' end diff --git a/lib/oxidized/api/rest.rb b/lib/oxidized/api/rest.rb index d1bd7dc..cdf5c80 100644 --- a/lib/oxidized/api/rest.rb +++ b/lib/oxidized/api/rest.rb @@ -4,11 +4,14 @@ module Oxidized module API class Rest module Helpers - def send res, msg='OK', status=200 - msg = {:result => msg} - res['Content-Type'] = 'application/json' - res.status = status - res.body = JSON.dump msg + def send res, msg='OK', ascii=false, status=200 + res.body = msg + if not ascii + msg = {:result => msg} + res['Content-Type'] = 'application/json' + res.status = status + res.body = JSON.dump msg + end end end include Oxidized::API::Rest::Helpers @@ -47,9 +50,12 @@ module Oxidized if $1.include? '/' group, node = $1.split("/")[1..2] else - group, node = 0, $1 + group, node = nil, $1 + end + ascii = if node[-4..-1] == '.txt' + node = node[0..-5] end - send res, @nodes.fetch(node, group) + send res, @nodes.fetch(node, group), ascii rescue Oxidized::NotSupported => e send res, e end diff --git a/lib/oxidized/model/ironware.rb b/lib/oxidized/model/ironware.rb index 3dd9ef2..e501f76 100644 --- a/lib/oxidized/model/ironware.rb +++ b/lib/oxidized/model/ironware.rb @@ -16,6 +16,7 @@ class IronWare < Oxidized::Model end cmd 'show chassis' do |cfg| + cfg.gsub! "\xFF", '' # ugly hack - avoids JSON.dump utf-8 breakage on 1.9.. comment cfg end diff --git a/lib/oxidized/output/file.rb b/lib/oxidized/output/file.rb index 2ea2302..da778ff 100644 --- a/lib/oxidized/output/file.rb +++ b/lib/oxidized/output/file.rb @@ -28,7 +28,7 @@ class OxFile < Output def fetch node, group cfg_dir = @cfg[:directory] - if group != 0 # group is explicitly defined by user + if group # group is explicitly defined by user IO.readlines File.join(cfg_dir, group, node) else if File.exists? File.join(cfg_dir, node) # node configuration file is stored on base directory diff --git a/lib/oxidized/output/git.rb b/lib/oxidized/output/git.rb index 202893c..f23b35a 100644 --- a/lib/oxidized/output/git.rb +++ b/lib/oxidized/output/git.rb @@ -37,6 +37,15 @@ class Git < Output end end + def fetch node, group + begin + repo = Repo.new(@cfg[:repo]) + (repo.tree / node).data + rescue + 'node not found' + end + end + private def update_repo repo, file, data, msg, actor diff --git a/oxidized.gemspec b/oxidized.gemspec index 53e12c9..e8db07e 100644 --- a/oxidized.gemspec +++ b/oxidized.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'oxidized' - s.version = '0.0.15' + s.version = '0.0.16' s.platform = Gem::Platform::RUBY s.authors = [ 'Saku Ytti' ] s.email = %w( saku@ytti.fi ) |