Module: Onering::CLI

Defined in:
lib/onering/cli.rb,
lib/onering/cli/call.rb,
lib/onering/cli/fact.rb,
lib/onering/cli/devices.rb,
lib/onering/cli/reporter.rb,
lib/onering/cli/automation.rb

Defined Under Namespace

Modules: Automation, Call, Devices, Fact, Report

Class Method Summary collapse

Class Method Details

.connect(cliargs) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/onering/cli.rb', line 8

def self.connect(cliargs)
  @_args = cliargs

  return Onering::API.new({
    'autoconnect' => cliargs[:autoconnect],
    'config' => {
      'url'    => cliargs[:url],
      'path'   => cliargs[:path],
      'params' => Hash[(cliargs[:param] || []).collect{|i| i.split('=',2) }],
      'authentication' => {
        'type'    => (cliargs[:apikey_given] ? :token : nil),
        'keyfile' => (cliargs[:apikey] || cliargs[:sslkey])
      }.compact
    }.compact
  }.compact)
end

.output(data, format) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/onering/cli.rb', line 25

def self.output(data, format)
  return nil if @_args[:quiet]

  case format
  when 'text'
    if data.is_a?(Hash)
      data.coalesce.each do |k,v|
        puts k.to_s+': '+v.to_s
      end
    else
      [*data].each do |d|
        if d.is_a?(Hash)
          d.coalesce.each do |k,v|
            puts k.to_s+': '+v.to_s
          end
        else
          puts d unless d.nil? or d.empty?
        end
      end
    end

  when 'json'
    puts MultiJson.dump(data)

  when 'yaml'
    puts YAML.dump(data)

  else
    raise "Unknown output format #{format.inspect}"
  end

  nil
end