Class: Koma::Backend::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/koma/backend/base.rb

Direct Known Subclasses

Exec, Ssh

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, options) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
# File 'lib/koma/backend/base.rb', line 6

def initialize(host, options)
  @host = host
  @options = options
  @inventory_keys = Koma::HostInventory.inventory_keys
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



4
5
6
# File 'lib/koma/backend/base.rb', line 4

def host
  @host
end

#inventory_keysObject (readonly)

Returns the value of attribute inventory_keys.



4
5
6
# File 'lib/koma/backend/base.rb', line 4

def inventory_keys
  @inventory_keys
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/koma/backend/base.rb', line 4

def options
  @options
end

Instance Method Details

#out(key = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/koma/backend/base.rb', line 12

def out(key = nil)
  out = {}
  keys = if key.nil?
           inventory_keys
         else
           key.split(',')
         end
  Koma::HostInventory.disabled_keys.each do |k|
    keys.push(k) if @options["enable-#{k}"]
  end

  keys.each do |k|
    raise Koma::NotImplementedKeyError unless Koma::HostInventory.all_inventory_keys.include?(k)
    begin
      out[k] = Specinfra.backend.host_inventory[k]
      out[k] = Specinfra.backend.host_inventory[k].inspect if k == 'ec2'
    rescue NotImplementedError
      out[k] = nil
    end
  end
  out
end