7 attr_reader :address, :prefix, :gateway, :network, :netmask
9 def initialize(address)
10 @address = address[:public_address] || address[:address]
11 @prefix = address[:prefix]
12 @gateway = address[:gateway]
14 ip = IPAddr.new(address[:address]).mask(address[:prefix])
21 address <=> other.address
33 "#{@network}/#{@prefix}"
37 def ipaddresses(role: nil, family: nil)
38 interfaces(:role => role).each_with_object([]) do |interface, addresses|
39 addresses << Address.new(interface[:inet]) if interface[:inet] && (family.nil? || family == :inet)
40 addresses << Address.new(interface[:inet6]) if interface[:inet6] && (family.nil? || family == :inet6)
44 def internal_ipaddress(family: nil)
45 ipaddresses(:role => :internal, :family => family).first
48 def external_ipaddress(family: nil)
49 ipaddresses(:role => :external, :family => family).first
55 Chef::Node.include(OpenStreetMap::Mixin::IPAddresses)