Module: Bosh::Director::IpUtil

Defined Under Namespace

Classes: CIDRIP

Instance Method Summary collapse

Instance Method Details

#each_ip(ranges, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/bosh/director/ip_util.rb', line 4

def each_ip(ranges, &block)
  if ranges.kind_of?(Array)
    ranges.each do |range|
      process_range(range, &block)
    end
  elsif ranges.kind_of?(String)
    process_range(ranges, &block)
  elsif !ranges.nil?
    raise ArgumentError,
          "Unknown range type, must be list or a string: " +
          "#{ranges.class} #{ranges}"
  end
end

#format_ip(ip) ⇒ String

Returns Human-readable IP representation.

Parameters:

  • ip (Integer)

    Integer IP representation

Returns:

  • (String)

    Human-readable IP representation



37
38
39
# File 'lib/bosh/director/ip_util.rb', line 37

def format_ip(ip)
  ip_to_netaddr(ip).ip
end

#ip_to_i(ip) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/bosh/director/ip_util.rb', line 18

def ip_to_i(ip)
  unless ip.kind_of?(Integer)
    unless ip.kind_of?(NetAddr::CIDR)
      ip = NetAddr::CIDR.create(ip)
    end
    ip = ip.to_i
  end
  ip
end

#ip_to_netaddr(ip) ⇒ Object



28
29
30
31
32
33
# File 'lib/bosh/director/ip_util.rb', line 28

def ip_to_netaddr(ip)
  unless ip.kind_of?(NetAddr::CIDR)
    ip = NetAddr::CIDR.create(ip)
  end
  ip
end