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)



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

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: },
    f
  )
end

#do_remove_netif(name) ⇒ Object (protected)



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

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

  unlink_if_exists(f)
end

#network_file(name) ⇒ Object (protected)



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

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