Class: Bcome::Node::Resources::SubselectInventory

Inherits:
Inventory
  • Object
show all
Defined in:
lib/objects/node/resources/sub_inventory.rb

Instance Attribute Summary

Attributes inherited from Base

#nodes

Instance Method Summary collapse

Methods inherited from Inventory

#<<, #duplicate_nodes, #dynamic_nodes, #rename_initial_duplicate, #reset_duplicate_nodes!, #should_rename_initial_duplicate?, #unset!

Methods inherited from Base

#<<, #active, #clear!, #disable, #disable!, #do_disable, #do_enable, #each, #empty?, #enable, #enable!, #first, #for_identifier, #has_active_nodes?, #is_active_resource?, #should_rename_initial_duplicate?, #size

Constructor Details

#initialize(config) ⇒ SubselectInventory

Returns a new instance of SubselectInventory.



3
4
5
6
7
# File 'lib/objects/node/resources/sub_inventory.rb', line 3

def initialize(config)
  @config = config
  super
  run_subselect
end

Instance Method Details

#filter_by_tags(nodes) ⇒ Object



37
38
39
40
41
42
# File 'lib/objects/node/resources/sub_inventory.rb', line 37

def filter_by_tags(nodes)
  tag_filters.each do |key, values|
    nodes = nodes.select { |node| node.has_tagged_value?(key, values) }
  end
  nodes
end

#filtersObject



48
49
50
# File 'lib/objects/node/resources/sub_inventory.rb', line 48

def filters
  @config[:filters]
end

#parent_crumbObject



44
45
46
# File 'lib/objects/node/resources/sub_inventory.rb', line 44

def parent_crumb
  @config[:parent_crumb]
end

#parent_inventoryObject



56
57
58
# File 'lib/objects/node/resources/sub_inventory.rb', line 56

def parent_inventory
  @config[:parent_inventory]
end

#run_subselectObject



9
10
11
12
13
14
15
16
17
# File 'lib/objects/node/resources/sub_inventory.rb', line 9

def run_subselect
  parent_inventory.load_nodes unless parent_inventory.nodes_loaded?
  new_set = parent_inventory.resources.nodes

  # Filter by ec2_filters
  new_set = filter_by_tags(new_set)

  @nodes = new_set
end

#tag_filtersObject



52
53
54
# File 'lib/objects/node/resources/sub_inventory.rb', line 52

def tag_filters
  filters[:by_tag] ? filters[:by_tag] : {}
end

#update_nodes(inventory) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/objects/node/resources/sub_inventory.rb', line 19

def update_nodes(inventory)
  new_set = []

  @nodes.collect do |node|
    new_node = node.dup_with_new_parent(inventory)
    if inventory.override_server_identifier?
      new_node.identifier =~ /#{inventory.override_identifier}/
      new_node.update_identifier(Regexp.last_match(1)) if Regexp.last_match(1)
    end

    # Register the new node with the registry
    ::Bcome::Registry::Loader.instance.set_command_group_for_node(new_node)

    new_set << new_node
  end
  @nodes = new_set
end