class NodeattrUtils::Config
Public Class Methods
path(_cluster)
click to toggle source
# File lib/nodeattr_utils/config.rb, line 37 def self.path(_cluster) raise NotImplementedError end
Public Instance Methods
__data__()
click to toggle source
Calls superclass method
# File lib/nodeattr_utils/config.rb, line 41 def __data__ super().tap { |d| d.set_if_empty(:groups, value: ['orphan']) } end
add_group(group_name)
click to toggle source
# File lib/nodeattr_utils/config.rb, line 86 def add_group(group_name) return if raw_groups.include?(group_name) __data__.append(group_name, to: :groups) end
add_nodes(node_string, groups: [])
click to toggle source
# File lib/nodeattr_utils/config.rb, line 99 def add_nodes(node_string, groups: []) groups = groups.is_a?(Array) ? groups : [groups] add_group(groups.first) unless groups.empty? NodeattrUtils::Nodes.expand(node_string).each do |node| __data__.set(:nodes, node, value: groups) end end
cluster()
click to toggle source
# File lib/nodeattr_utils/config.rb, line 45 def cluster __inputs__.first end
group_index(group)
click to toggle source
# File lib/nodeattr_utils/config.rb, line 67 def group_index(group) return nil if group.nil? raw_groups.find_index(group) end
groups_for_node(node)
click to toggle source
# File lib/nodeattr_utils/config.rb, line 72 def groups_for_node(node) __data__.fetch(:nodes, node, default: []).dup.tap do |groups| groups.push 'orphan' if groups.empty? end end
groups_hash()
click to toggle source
# File lib/nodeattr_utils/config.rb, line 61 def groups_hash raw_groups.reject(&:nil?).map do |group| [group, group_index(group)] end.to_h end
nodes_in_group(group)
click to toggle source
# File lib/nodeattr_utils/config.rb, line 78 def nodes_in_group(group) nodes_list.select { |node| groups_for_node(node).include?(group) } end
nodes_in_primary_group(group)
click to toggle source
# File lib/nodeattr_utils/config.rb, line 82 def nodes_in_primary_group(group) nodes_list.select { |n| groups_for_node(n).first == group } end
nodes_list()
click to toggle source
# File lib/nodeattr_utils/config.rb, line 57 def nodes_list raw_nodes.keys end
orphans()
click to toggle source
# File lib/nodeattr_utils/config.rb, line 113 def orphans nodes_in_group('orphan') end
raw_groups()
click to toggle source
# File lib/nodeattr_utils/config.rb, line 49 def raw_groups __data__.fetch(:groups) end
raw_nodes()
click to toggle source
# File lib/nodeattr_utils/config.rb, line 53 def raw_nodes __data__.fetch(:nodes, default: {}) end
remove_group(group_name)
click to toggle source
# File lib/nodeattr_utils/config.rb, line 91 def remove_group(group_name) error_if_removing_orphan_group(group_name) nodes_list.select { |n| groups_for_node(n).first == group_name } .join(',') .tap { |node_str| remove_nodes(node_str) } __data__.fetch(:groups).map! { |g| g == group_name ? nil : g } end
remove_nodes(node_string)
click to toggle source
# File lib/nodeattr_utils/config.rb, line 107 def remove_nodes(node_string) NodeattrUtils::Nodes.expand(node_string).map do |node| __data__.delete(:nodes, node) end end
Private Instance Methods
error_if_removing_orphan_group(group)
click to toggle source
# File lib/nodeattr_utils/config.rb, line 119 def error_if_removing_orphan_group(group) return unless group == 'orphan' raise RemovingOrphanGroupError, <<~ERROR.chomp Can not remove the orphan group ERROR end