Class: Construqt::Addresses

Inherits:
Object
  • Object
show all
Defined in:
lib/construqt/addresses.rb

Defined Under Namespace

Classes: Address

Constant Summary collapse

UNREACHABLE =
:unreachable
LOOOPBACK =
:looopback
DHCPV4 =
:dhcpv4
DHCPV6 =
:dhcpv6
IPV4 =
:ipv4
IPV6 =
:ipv6

Instance Method Summary collapse

Constructor Details

#initialize(network) ⇒ Addresses

Returns a new instance of Addresses.



12
13
14
15
# File 'lib/construqt/addresses.rb', line 12

def initialize(network)
  @network = network
  @Addresses = []
end

Instance Method Details

#add_ip(ip, region = "") ⇒ Object



181
182
183
# File 'lib/construqt/addresses.rb', line 181

def add_ip(ip, region = "")
  create.add_ip(ip, region)
end

#add_route(dest, via = nil) ⇒ Object



185
186
187
# File 'lib/construqt/addresses.rb', line 185

def add_route(dest, via = nil)
  create.add_route(dest, via)
end

#allObject



193
194
195
# File 'lib/construqt/addresses.rb', line 193

def all
  @Addresses
end

#createObject



171
172
173
174
175
# File 'lib/construqt/addresses.rb', line 171

def create
  ret = Address.new()
  @Addresses << ret
  ret
end

#networkObject



17
18
19
# File 'lib/construqt/addresses.rb', line 17

def network
  @network
end

#set_name(name) ⇒ Object



189
190
191
# File 'lib/construqt/addresses.rb', line 189

def set_name(name)
  create.set_name(name)
end

#tag(tag) ⇒ Object



177
178
179
# File 'lib/construqt/addresses.rb', line 177

def tag(tag)
  create.tag(tag)
end

#v4_default_route(tag = "") ⇒ Object



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/construqt/addresses.rb', line 197

def v4_default_route(tag = "")
  nets = [(1..9),(11..126),(128..168),(170..171),(173..191),(193..223)].map do |range|
    range.to_a.map{|i| "#{i}.0.0.0/8"}
  end.flatten
  nets += (0..255).to_a.select{|i| i!=254}.map{|i| "169.#{i}.0.0/16" }
  nets += (0..255).to_a.select{|i| !(16<=i&&i<31)}.map{|i| "172.#{i}.0.0/16" }
  nets += (0..255).to_a.select{|i| i!=168}.map{|i| "192.#{i}.0.0/16" }

  v4_default_route = self.create
  v4_default_route.set_name(tag).tag(tag) if tag && !tag.empty?
  IPAddress::IPv4::summarize(*(nets.map{|i| IPAddress::IPv4.new(i) })).each do |i|
    v4_default_route.add_ip(i.to_string)
  end
  v4_default_route
end