class Bcome::Node::Resources::SubselectInventory

Public Class Methods

new(config) click to toggle source
Calls superclass method Bcome::Node::Resources::Inventory::new
# File lib/objects/node/resources/sub_inventory.rb, line 5
def initialize(config)
  @config = config
  super
  run_subselect
end

Public Instance Methods

filter_by_tags_or_label(nodes) click to toggle source
# 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
filters() click to toggle source
# File lib/objects/node/resources/sub_inventory.rb, line 48
def filters
  @config[:filters]
end
origin_inventory() click to toggle source
# File lib/objects/node/resources/sub_inventory.rb, line 60
def origin_inventory
  @config[:origin_inventory]
end
parent_crumb() click to toggle source
# File lib/objects/node/resources/sub_inventory.rb, line 44
def parent_crumb
  @config[:parent_crumb]
end
parent_inventory() click to toggle source
# File lib/objects/node/resources/sub_inventory.rb, line 56
def parent_inventory
  @config[:parent_inventory]
end
run_subselect() click to toggle source
# 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_filters() click to toggle source
# File lib/objects/node/resources/sub_inventory.rb, line 52
def tag_filters
  filters[:by_tag] || filters[:by_label] || filters
end
update_nodes(inventory) click to toggle source
# 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