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, #override_server_identifier, #rename_initial_duplicate, #reset_duplicate_nodes!, #set_overrides, #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.



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

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

Instance Method Details

#filter_by_tags_or_label(nodes) ⇒ Object



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

def filter_by_tags_or_label(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

#origin_inventoryObject



60
61
62
# File 'lib/objects/node/resources/sub_inventory.rb', line 60

def origin_inventory
  @config[:origin_inventory]
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



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

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

  # ...by_tags: ec2
  # ...by_label: gcp
  new_set = filter_by_tags_or_label(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_label] || filters
end

#update_nodes(inventory) ⇒ Object



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

def update_nodes(inventory)
  new_set = []

  @nodes.collect do |node|
    new_node = node.dup_with_new_parent(inventory)
    set_overrides(inventory, new_node)

    # 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