Module: Pangea::Components::Networking

Included in:
Base
Defined in:
lib/pangea/components/base.rb

Instance Method Summary collapse

Instance Method Details

#calculate_subnet_cidr(vpc_cidr, index, new_bits = 8) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/pangea/components/base.rb', line 26

def calculate_subnet_cidr(vpc_cidr, index, new_bits = 8)
  vpc_network = IPAddr.new(vpc_cidr)
  vpc_prefix = vpc_cidr.split('/').last.to_i
  subnet_prefix = vpc_prefix + new_bits

  subnet_size = 2 ** (32 - subnet_prefix)
  subnet_network = vpc_network.to_i + (index * subnet_size)

  "#{IPAddr.new(subnet_network, Socket::AF_INET)}/#{subnet_prefix}"
end