Module: PuppetX::IntechWIFI::Declare_Environment_Resources::CidrMaths

Defined in:
lib/puppet_x/intechwifi/declare_environment_resources.rb

Defined Under Namespace

Classes: CidrSizeTooSmallForSubnet

Class Method Summary collapse

Class Method Details

.CalculateBlockSize(cidr_size, weighting, total_weighting, azs) ⇒ Object

Isolated module containing the maths involved in CIDR calculations.



950
951
952
953
954
955
956
957
958
959
960
# File 'lib/puppet_x/intechwifi/declare_environment_resources.rb', line 950

def self.CalculateBlockSize(cidr_size, weighting, total_weighting, azs)

  ipaddrs = (((2**(32-cidr_size)) * weighting) / (azs.to_f * total_weighting)).to_i

  possible_cidr = 32
  while ipaddrs >= 2**(33-possible_cidr) do
    possible_cidr -= 1
  end

  possible_cidr
end

.CidrToLong(cidr) ⇒ Object



962
963
964
965
# File 'lib/puppet_x/intechwifi/declare_environment_resources.rb', line 962

def self.CidrToLong(cidr)
  # Convert the cidr_base into a number.
  cidr.split("/")[0].split(".").map(&:to_i).reduce(0) { |sum, num| (sum << 8) + num }
end

.IpAddrsInCidrBlock(size) ⇒ Object



971
972
973
974
975
976
977
978
979
# File 'lib/puppet_x/intechwifi/declare_environment_resources.rb', line 971

def self.IpAddrsInCidrBlock(size)
  ip_count = 1

  while size < 32 do
    ip_count <<= 1
    size += 1
  end
  ip_count
end

.LongToCidr(base, size) ⇒ Object



967
968
969
# File 'lib/puppet_x/intechwifi/declare_environment_resources.rb', line 967

def self.LongToCidr(base, size)
  (base >> 24).to_s + "." + (base >> 16 & 0xFF).to_s + "." + (base >> 8 & 0xFF).to_s + "." + (base & 0xFF).to_s + "/" + size.to_s
end