Class: OsCtld::DistConfig::Network::Netctl

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

Overview

Configure network using netctl

wiki.archlinux.org/title/netctl

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



12
13
14
15
16
# File 'lib/osctld/dist_config/network/netctl.rb', line 12

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

#deprecated_service_path(name) ⇒ Object (protected)



80
81
82
# File 'lib/osctld/dist_config/network/netctl.rb', line 80

def deprecated_service_path(name)
  File.join(rootfs, 'etc/systemd/system', service_name(name))
end

#do_create_netif(netif) ⇒ Object (protected)



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/osctld/dist_config/network/netctl.rb', line 33

def do_create_netif(netif)
  profile = netctl_profile(netif.name)
  return unless writable?(profile)

  # Create netctl profile
  OsCtld::ErbTemplate.render_to_if_changed(
    File.join('dist_config/network/netctl', netif.type.to_s),
    {netif: netif},
    profile
  )

  s_name = service_name(netif.name)

  # Remove deprecated systemd override
  unlink_if_exists(deprecated_service_path(netif.name))

  # Start the service on boot
  s_link = service_symlink(netif.name)

  if !File.symlink?(s_link) && !File.exist?(s_link)
    File.symlink(File.join('/etc/systemd/system', s_name), s_link)
  end
end

#do_remove_netif(name) ⇒ Object (protected)



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/osctld/dist_config/network/netctl.rb', line 57

def do_remove_netif(name)
  profile = netctl_profile(name)
  return unless writable?(profile)

  # Disable the service
  s_link = service_symlink(name)
  File.unlink(s_link) if File.symlink?(s_link)

  # Remove deprecated service override file
  unlink_if_exists(deprecated_service_path(name))

  # Remove netctl profile
  File.unlink(profile) if File.exist?(profile)
end

#netctl_profile(name) ⇒ Object (protected)



72
73
74
# File 'lib/osctld/dist_config/network/netctl.rb', line 72

def netctl_profile(name)
  File.join(rootfs, 'etc/netctl', name)
end

#remove_netif(netifs, netif) ⇒ Object

Remove netctl profile and systemd service



19
20
21
# File 'lib/osctld/dist_config/network/netctl.rb', line 19

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

#rename_netif(netifs, netif, old_name) ⇒ Object

Rename netctl profile and systemd service



24
25
26
27
28
29
30
# File 'lib/osctld/dist_config/network/netctl.rb', line 24

def rename_netif(netifs, netif, old_name)
  # Remove old network interface
  do_remove_netif(old_name)

  # Create the new interface
  do_create_netif(netif)
end

#service_name(name) ⇒ Object (protected)



76
77
78
# File 'lib/osctld/dist_config/network/netctl.rb', line 76

def service_name(name)
  "netctl@#{name}.service"
end


84
85
86
87
88
89
90
# File 'lib/osctld/dist_config/network/netctl.rb', line 84

def service_symlink(name)
  File.join(
    rootfs,
    'etc/systemd/system/multi-user.target.wants',
    service_name(name)
  )
end

#usable?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/osctld/dist_config/network/netctl.rb', line 8

def usable?
  Dir.exist?(File.join(rootfs, 'etc/netctl'))
end