Class: OsCtld::DistConfig::Network::SystemdNetworkd

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

Overview

Configure network using systemd-networkd

www.freedesktop.org/software/systemd/man/systemd.network.html

Instance Attribute Summary

Attributes inherited from Base

#configurator

Instance Method Summary collapse

Methods inherited from Base

#add_netif, #initialize

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



23
24
25
26
27
# File 'lib/osctld/dist_config/network/systemd_networkd.rb', line 23

def configure(netifs)
  netifs.each do |netif|
    do_create_netif(netif)
  end
end

#do_create_netif(netif) ⇒ Object (protected)



39
40
41
42
43
44
45
46
47
48
# File 'lib/osctld/dist_config/network/systemd_networkd.rb', line 39

def do_create_netif(netif)
  f = network_file(netif.name)
  return unless writable?(f)

  OsCtld::ErbTemplate.render_to_if_changed(
    File.join('dist_config/network/systemd_networkd', netif.type.to_s),
    {netif: netif},
    f,
  )
end

#do_remove_netif(name) ⇒ Object (protected)



50
51
52
53
54
55
# File 'lib/osctld/dist_config/network/systemd_networkd.rb', line 50

def do_remove_netif(name)
  f = network_file(name)
  return unless writable?(f)

  unlink_if_exists(f)
end

#network_file(name) ⇒ Object (protected)



57
58
59
# File 'lib/osctld/dist_config/network/systemd_networkd.rb', line 57

def network_file(name)
  File.join(rootfs, 'etc/systemd/network', "#{name}.network")
end

#remove_netif(netifs, netif) ⇒ Object



29
30
31
# File 'lib/osctld/dist_config/network/systemd_networkd.rb', line 29

def remove_netif(netifs, netif)
  do_remove_netif(netif.name)
end

#rename_netif(netifs, netif, old_name) ⇒ Object



33
34
35
36
# File 'lib/osctld/dist_config/network/systemd_networkd.rb', line 33

def rename_netif(netifs, netif, old_name)
  do_remove_netif(old_name)
  do_create_netif(netif)
end

#usable?Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/osctld/dist_config/network/systemd_networkd.rb', line 8

def usable?
  service = 'systemd-networkd.service'

  # Check the configuration directory exists
  return false unless Dir.exist?(File.join(rootfs, 'etc/systemd/network'))

  # Check the service is not masked
  return false if systemd_service_masked?(service)

  # Check the service is enabled
  return false unless systemd_service_enabled?(service, 'multi-user.target')

  true
end