Class: Confer::Inventory

Inherits:
Object
  • Object
show all
Defined in:
lib/confer/inventory.rb

Overview

Public: Encapsulates an inventory, which is simply a list of hosts and the credentials and transport mechanisms required to interact with them.

Defined Under Namespace

Classes: Host

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hosts = {}) ⇒ Inventory

Public: Creates a new Inventory instance.

hosts - A Hash of hosts their options in the inventory, indexed by name.



52
53
54
# File 'lib/confer/inventory.rb', line 52

def initialize(hosts = {})
  @hosts = hosts
end

Instance Attribute Details

#hostsObject

Public: A Hash of the hosts and their options in this Inventory, indexed by name.



45
46
47
# File 'lib/confer/inventory.rb', line 45

def hosts
  @hosts
end

Class Method Details

.from_file(path) ⇒ Object

Public: Loads an inventory from a YAML file.

path - A String containing the path to the YAML file to load.

Returns an Inventory instance.



22
23
24
25
26
27
28
# File 'lib/confer/inventory.rb', line 22

def self.from_file(path)
  self.from_hash YAML.load File.open(path, 'r').read
rescue Errno::ENOENT => e
  raise InventoryNotFoundError.new(e)
rescue Psych::SyntaxError => e
  raise InventorySyntaxError.new(e)
end

.from_hash(hash) ⇒ Object

Public: Loads an inventory from a Hash of hosts.

array - A Hash of hosts and their options, indexed by name.

Returns an Inventory instance.



37
38
39
# File 'lib/confer/inventory.rb', line 37

def self.from_hash(hash)
  Inventory.new Hash[hash.map { |k, v| [k, Host.new(k, v)] }]
end