lib/onering/cli/reporter.rb in onering-client-0.2.3 vs lib/onering/cli/reporter.rb in onering-client-0.2.4

- old
+ new

@@ -2,12 +2,12 @@ module CLI class Report < Plugin DEFAULT_CACHE_MAXAGE=600 def self.configure(global={}) - - @api = Onering::CLI.connect(global.merge({ + @global_opts = global + @api = Onering::CLI.connect(@global_opts.merge({ :autoconnect => false })) @opts = ::Trollop::options do banner <<-EOS @@ -84,58 +84,14 @@ _save(report) return nil when :get Onering::Logger.fatal!("Expected at least 1 parameter, got #{args.length}", "Onering::CLI::Report") unless args.length >= 1 - - # this is kinda ugly - # because we don't know which property might have an @-prefix, progressively - # search through all of them. first non-null match wins - parts = args[0].split('.') - - # create an array with every component of the path prefixed with the @-symbol, then with - # the path as is. - # - # e.g.: onering report get metrics.disk.block - # -> value exists in the inventory as properties.metrics.disk.@block, - # but the user shouldn't need to know where that @-prefix is, so... - # - # Search for all of these, first non-nil value wins: - # * properties.metrics.disk.block - # * properties.@metrics.disk.block - # * properties.metrics.@disk.block - # * properties.metrics.disk.@block - # * metrics.disk.block - # - candidates = [(['properties']+parts).join('.')] - - parts.each_index{|ix| - candidates << (['properties']+(ix == 0 ? [] : parts[0..(ix-1)]) + ["@#{parts[ix]}"] + parts[ix+1..-1]).join('.') - }.flatten() - - rv = nil - - # search for the key using science or something - candidates.each do |c| - rv = report.get(c) - break unless rv.nil? - end - - # if we're still nil by this point, use the fallback value - rv = report.get(args[0], args[1]) if rv.nil? - - # attempt to get the value remotely if not found locally - if rv.nil? and not @opts[:local] - hid = Onering::Util.fact(:hardwareid) - - if not hid.nil? - Onering::Logger.debug("Getting remote value #{args[0]} for asset #{hid}") - @api.connect() - return @api.assets.get_field(hid, args[0], args[1]) - end - end - - return rv + return @_reporter.get(args[0], args[1], { + :data => report, + :api => @global_opts, + :local => @opts[:local] + }) end end return report end \ No newline at end of file