Class: OsCtld::DistConfig::Network::Netctl
- Inherits:
-
Base
- Object
- Base
- OsCtld::DistConfig::Network::Netctl
show all
- Defined in:
- lib/osctld/dist_config/network/netctl.rb
Overview
Instance Attribute Summary
Attributes inherited from Base
#configurator
Instance Method Summary
collapse
Methods inherited from Base
#add_netif, #initialize
#systemd_service_enabled?, #systemd_service_masked?, #writable?
Instance Method Details
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
81
82
83
|
# File 'lib/osctld/dist_config/network/netctl.rb', line 81
def deprecated_service_path(name)
File.join(rootfs, 'etc/systemd/system', service_name(name))
end
|
#do_create_netif(netif) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/osctld/dist_config/network/netctl.rb', line 34
def do_create_netif(netif)
profile = netctl_profile(netif.name)
return unless writable?(profile)
OsCtld::ErbTemplate.render_to_if_changed(
File.join('dist_config/network/netctl', netif.type.to_s),
{ netif: },
profile
)
s_name = service_name(netif.name)
unlink_if_exists(deprecated_service_path(netif.name))
s_link = service_symlink(netif.name)
return unless !File.symlink?(s_link) && !File.exist?(s_link)
File.symlink(File.join('/etc/systemd/system', s_name), s_link)
end
|
#do_remove_netif(name) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/osctld/dist_config/network/netctl.rb', line 58
def do_remove_netif(name)
profile = netctl_profile(name)
return unless writable?(profile)
s_link = service_symlink(name)
File.unlink(s_link) if File.symlink?(s_link)
unlink_if_exists(deprecated_service_path(name))
FileUtils.rm_f(profile)
end
|
#netctl_profile(name) ⇒ Object
73
74
75
|
# File 'lib/osctld/dist_config/network/netctl.rb', line 73
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)
do_remove_netif(old_name)
do_create_netif(netif)
end
|
#service_name(name) ⇒ Object
77
78
79
|
# File 'lib/osctld/dist_config/network/netctl.rb', line 77
def service_name(name)
"netctl@#{name}.service"
end
|
#service_symlink(name) ⇒ Object
85
86
87
88
89
90
91
|
# File 'lib/osctld/dist_config/network/netctl.rb', line 85
def service_symlink(name)
File.join(
rootfs,
'etc/systemd/system/multi-user.target.wants',
service_name(name)
)
end
|
#usable? ⇒ Boolean
8
9
10
|
# File 'lib/osctld/dist_config/network/netctl.rb', line 8
def usable?
Dir.exist?(File.join(rootfs, 'etc/netctl'))
end
|