Class: Loom::Inventory::InventoryList

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hostlist, hostgroup_map = {}) ⇒ InventoryList

Returns a new instance of InventoryList.



49
50
51
52
53
54
55
# File 'lib/loom/inventory.rb', line 49

def initialize(hostlist, hostgroup_map={})
  @hostgroup_map = hostgroup_map

  all_hosts = hostgroup_map.values.flatten + hostlist
  @hosts = parse_hosts(all_hosts).uniq { |h| h.hostname }
  @disabled_hosts = {}
end

Instance Attribute Details

#hostsObject (readonly)

Returns the value of attribute hosts.



47
48
49
# File 'lib/loom/inventory.rb', line 47

def hosts
  @hosts
end

Class Method Details

.active_inventory(loom_config) ⇒ Object

The list of hosts to apply patterns to



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/loom/inventory.rb', line 26

def active_inventory(loom_config)
  return total_inventory loom_config if loom_config.inventory_all_hosts

  fileset = InventoryFileSet.new inventory_files(loom_config)
  groups = loom_config.inventory_groups.map(&:to_sym).reduce({}) do |map, group|
    Loom.log.debug2(self) { "looking for group => #{group}" }
    key = group.to_sym
    map[key] = fileset.hostgroup_map[key] if fileset.hostgroup_map.key? key
    map
  end
  Loom.log.debug1(self) { "groups map => #{groups}" }

  InventoryList.new loom_config.inventory_hosts, groups
end

.total_inventory(loom_config) ⇒ Object



17
18
19
20
21
22
# File 'lib/loom/inventory.rb', line 17

def total_inventory(loom_config)
  fileset = InventoryFileSet.new inventory_files(loom_config)
  config_hostlist = loom_config.inventory_hosts
  hostlist = fileset.hostlist + config_hostlist
  InventoryList.new hostlist, fileset.hostgroup_map
end

Instance Method Details

#disable(hostname) ⇒ Object



57
58
59
# File 'lib/loom/inventory.rb', line 57

def disable(hostname)
  @disabled_hosts[hostname] = true
end

#disabled?(hostname) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/loom/inventory.rb', line 61

def disabled?(hostname)
  !!@disabled_hosts[hostname]
end

#group_namesObject



69
70
71
# File 'lib/loom/inventory.rb', line 69

def group_names
  @hostgroup_map.keys
end

#hostnamesObject



65
66
67
# File 'lib/loom/inventory.rb', line 65

def hostnames
  @hosts.map { |h| h.hostname }
end