Class: Specinfra::HostInventory

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/specinfra/host_inventory.rb,
lib/specinfra/host_inventory/cpu.rb,
lib/specinfra/host_inventory/ec2.rb,
lib/specinfra/host_inventory/base.rb,
lib/specinfra/host_inventory/fqdn.rb,
lib/specinfra/host_inventory/ohai.rb,
lib/specinfra/host_inventory/user.rb,
lib/specinfra/host_inventory/group.rb,
lib/specinfra/host_inventory/domain.rb,
lib/specinfra/host_inventory/facter.rb,
lib/specinfra/host_inventory/kernel.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/block_device.rb,
lib/specinfra/host_inventory/virtualization.rb,
lib/specinfra/host_inventory/platform_version.rb

Defined Under Namespace

Classes: Base, BlockDevice, Cpu, Domain, Ec2, Facter, Filesystem, Fqdn, Group, Hostname, Kernel, Memory, Ohai, Platform, PlatformVersion, User, Virtualization

Constant Summary collapse

KEYS =
%w{
  memory
  ec2
  hostname
  domain
  fqdn
  platform
  platform_version
  filesystem
  cpu
  virtualization
  kernel
  block_device
  user
  group
  facter
  ohai
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(backend, inventory = {}) ⇒ HostInventory

Returns a new instance of HostInventory.



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

def initialize(backend, inventory = {})
  @backend = backend
  @inventory = inventory
end

Instance Attribute Details

#backendObject (readonly)

Returns the value of attribute backend.



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

def backend
  @backend
end

Class Method Details

.instanceObject



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

def self.instance
  property[:host_inventory] ||= {}
  self.new(Specinfra.backend, property[:host_inventory])
end

Instance Method Details

#[](key) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/specinfra/host_inventory.rb', line 36

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.new(self).get
    rescue
      @inventory[key.to_sym] = nil
    end
  end
  @inventory[key.to_sym]
end

#eachObject



49
50
51
52
53
# File 'lib/specinfra/host_inventory.rb', line 49

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

#each_keyObject



55
56
57
58
59
# File 'lib/specinfra/host_inventory.rb', line 55

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

#each_valueObject



61
62
63
64
65
# File 'lib/specinfra/host_inventory.rb', line 61

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