Class: OsCtld::DistConfig::Network::Ifupdown

Inherits:
Base
  • Object
show all
Defined in:
lib/osctld/dist_config/network/ifupdown.rb

Overview

ifupdown configures network using /etc/network/interfaces

Instance Attribute Summary

Attributes inherited from Base

#configurator

Instance Method Summary collapse

Methods inherited from Base

#add_netif, #initialize, #remove_netif, #rename_netif

Methods included from Helpers::Common

#systemd_service_enabled?, #systemd_service_masked?, #writable?

Constructor Details

This class inherits a constructor from OsCtld::DistConfig::Network::Base

Instance Method Details

#configure(netifs) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/osctld/dist_config/network/ifupdown.rb', line 10

def configure(netifs)
  base = File.join(rootfs, 'etc', 'network')
  config = File.join(base, 'interfaces')
  return unless writable?(config)

  vars = {
    netifs:,
    head: nil,
    interfacesd: Dir.exist?(File.join(base, 'interfaces.d')),
    tail: nil
  }

  %i[head tail].each do |v|
    f = File.join(base, "interfaces.#{v}")

    begin
      # Ignore large files
      if File.size(f) > 10 * 1024 * 1024
        log(:warn, "/etc/network/interfaces.#{v} found, but is too large")
        next
      end

      vars[v] = File.read(f)
    rescue Errno::ENOENT
      next
    end
  end

  OsCtld::ErbTemplate.render_to_if_changed(
    'dist_config/network/ifupdown/interfaces',
    vars,
    config
  )
end

#usable?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/osctld/dist_config/network/ifupdown.rb', line 6

def usable?
  File.exist?(File.join(rootfs, 'etc/network/interfaces'))
end