Class: Specinfra::HostInventory

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Singleton
Defined in:
lib/specinfra/host_inventory.rb,
lib/specinfra/host_inventory/cpu.rb,
lib/specinfra/host_inventory/ec2.rb,
lib/specinfra/host_inventory/fqdn.rb,
lib/specinfra/host_inventory/domain.rb,
lib/specinfra/host_inventory/memory.rb,
lib/specinfra/host_inventory/hostname.rb,
lib/specinfra/host_inventory/platform.rb,
lib/specinfra/host_inventory/filesystem.rb,
lib/specinfra/host_inventory/platform_version.rb

Defined Under Namespace

Classes: Cpu, Domain, Ec2, Filesystem, Fqdn, Hostname, Memory, Platform, PlatformVersion

Instance Method Summary collapse

Constructor Details

#initializeHostInventory

Returns a new instance of HostInventory.



6
7
8
9
# File 'lib/specinfra/host_inventory.rb', line 6

def initialize
  property[:host_inventory] ||= {}
  @inventory = property[:host_inventory]
end

Instance Method Details

#[](key) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/specinfra/host_inventory.rb', line 11

def [](key)
  @inventory[key.to_sym] ||= {}
  if @inventory[key.to_sym].empty?
    begin
      inventory_class = Specinfra::HostInventory.const_get(key.to_s.to_camel_case)
      @inventory[key.to_sym] = inventory_class.get
    rescue
      @inventory[key.to_sym] = nil
    end
  end
  @inventory[key.to_sym]
end

#eachObject



24
25
26
27
28
# File 'lib/specinfra/host_inventory.rb', line 24

def each
  keys.each do |k|
    yield k, self[k]
  end
end

#each_keyObject



30
31
32
33
34
# File 'lib/specinfra/host_inventory.rb', line 30

def each_key
  keys.each do |k|
    yield k
  end
end

#each_valueObject



36
37
38
39
40
# File 'lib/specinfra/host_inventory.rb', line 36

def each_value
  keys.each do |k|
    yield self[k]
  end
end

#keysObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/specinfra/host_inventory.rb', line 42

def keys
  %w{
    memory
    ec2
    hostname
    domain
    fqdn
    platform
    platform_version
    filesystem
    cpu
  }
end