Class: Construqt::Addresses

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

Defined Under Namespace

Classes: Address, CqIpAddress

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



292
293
294
# File 'lib/construqt/addresses.rb', line 292

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

#add_route(dest, via = nil) ⇒ Object



296
297
298
# File 'lib/construqt/addresses.rb', line 296

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

#allObject



304
305
306
# File 'lib/construqt/addresses.rb', line 304

def all
  @Addresses
end

#createObject



282
283
284
285
286
# File 'lib/construqt/addresses.rb', line 282

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



300
301
302
# File 'lib/construqt/addresses.rb', line 300

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

#tag(tag) ⇒ Object



288
289
290
# File 'lib/construqt/addresses.rb', line 288

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

#v4_default_route(tag = "") ⇒ Object



308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/construqt/addresses.rb', line 308

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