Sha256: a4625e0b5d76cb5d03c07f2c528744534409b993dacff488808749d1d7368431
Contents?: true
Size: 1.26 KB
Versions: 6
Compression:
Stored size: 1.26 KB
Contents
module Clusterfuck class Cluster attr_reader :name, :network def initialize(name) @name = name @graph = {} end def self.create(name) @@clusters ||= {} @@clusters[name] = self.new(name) end def self.[](name) @@clusters[name] end def self.all @@clusters.values end def find_by_name(name) nodes.find { |node| node.name == name } end alias_method :[], :find_by_name def nodes @graph.keys end def connect(*nodes, subnet: SubnetFactory.next_subnet) # Create a complete graph (a graph where all nodes are connected to each # other) between all the nodes, because that's what a subnet is. nodes.permutation(2).each do |(a, b)| @graph[a] ||= [] @graph[a] << b end nodes.each do |node| node.ips << subnet.next_ip node.cluster = self end subnet.last_ip end def ip_in_same_subnet(a, b) a.ips.find { |a_ip| b.ips.find { |b_ip| a_ip.include?(b_ip) } } end alias_method :neighbor?, :ip_in_same_subnet end class BGPCluster < Cluster def bgp_neighbors(node) @graph[node].select { |neighbor| neighbor.is_a?(BGPPeer) } end end end
Version data entries
6 entries across 6 versions & 1 rubygems