Module: DevDNSd::ApplicationMethods::Aliases
- Extended by:
- ActiveSupport::Concern
- Included in:
- DevDNSd::Application
- Defined in:
- lib/devdnsd/application.rb
Overview
Methods to handle interfaces aliases.
Instance Method Summary (collapse)
-
- (Array) compute_addresses(type = :all)
Computes the list of address to manage.
-
- (Boolean) is_ipv4?(address)
Checks if an address is a valid IPv4 address.
-
- (Boolean) is_ipv6?(address)
Checks if an address is a valid IPv6 address.
-
- (Boolean) manage_address(type, address, dry_run = false)
Adds or removes an alias from the interface.
-
- (Boolean) manage_aliases(operation, message, options)
Manages aliases.
Instance Method Details
- (Array) compute_addresses(type = :all)
Computes the list of address to manage.
340 341 342 343 |
# File 'lib/devdnsd/application.rb', line 340 def compute_addresses(type = :all) config = self.config config.addresses.present? ? filter_addresses(config, type) : generate_addresses(config, type) end |
- (Boolean) is_ipv4?(address)
Checks if an address is a valid IPv4 address.
349 350 351 352 353 354 |
# File 'lib/devdnsd/application.rb', line 349 def is_ipv4?(address) address = address.ensure_string mo = /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\Z/.match(address) (mo && mo.captures.all? {|i| i.to_i < 256}) ? true : false end |
- (Boolean) is_ipv6?(address)
Checks if an address is a valid IPv6 address.
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/devdnsd/application.rb', line 360 def is_ipv6?(address) address = address.ensure_string catch(:valid) do # IPv6 (normal) throw(:valid, true) if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*\Z/ =~ address throw(:valid, true) if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*)?\Z/ =~ address throw(:valid, true) if /\A::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*)?\Z/ =~ address # IPv6 (IPv4 compat) throw(:valid, true) if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:/ =~ address && is_ipv4?($') throw(:valid, true) if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:)?/ =~ address && is_ipv4?($') throw(:valid, true) if /\A::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:)?/ =~ address && is_ipv4?($') false end end |
- (Boolean) manage_address(type, address, dry_run = false)
Adds or removes an alias from the interface.
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
# File 'lib/devdnsd/application.rb', line 320 def manage_address(type, address, dry_run = false) locale = i18n rv, command, prefix = setup_management(type, address) # Now execute if rv then if !dry_run then execute_manage(command, prefix, type, address, self.config) else log_management(:dry_run, prefix, type, locale.remove, locale.add, address, config) end end rv end |
- (Boolean) manage_aliases(operation, message, options)
Manages aliases.
299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/devdnsd/application.rb', line 299 def manage_aliases(operation, , ) config = self.config .each { |k, v| config.send("#{k}=", v) if config.respond_to?("#{k}=") } addresses = compute_addresses if addresses.present? then # Now, for every address, call the command addresses.all? {|address| manage_address(operation, address, [:dry_run]) } else @logger.error() false end end |