Commit 825304d4 authored by Christopher Huhn's avatar Christopher Huhn
Browse files

Replace huge if clause with a simple return

parent cb74c9c7
......@@ -25,86 +25,85 @@
Chef::Recipe.include(Sys::Helper)
Chef::Resource.include(Sys::Helper)
if systemd_installed? # We do not install systemd for now, just detect if it is available
# We do not install systemd for now, just detect if it is available:
return unless systemd_installed?
execute 'sys-systemd-reload' do
command 'systemctl daemon-reload'
action :nothing
end
execute 'sys-systemd-reload' do
command 'systemctl daemon-reload'
action :nothing
end
if node['sys']['systemd']['networkd']['clean_legacy']
# This works for current usecases, but may be too radical. Probably needs
# to be changed again, when we understand, how to use systemd-networkd.service
# in other scenarios
if node['sys']['systemd']['networkd']['clean_legacy']
# This works for current usecases, but may be too radical. Probably needs
# to be changed again, when we understand, how to use systemd-networkd.service
# in other scenarios
interfacesd = '/etc/network/interfaces.d/*'
execute "rm -rf #{interfacesd}" do
not_if { Dir[interfacesd].empty? }
end
interfacesd = '/etc/network/interfaces.d/*'
execute "rm -rf #{interfacesd}" do
not_if { Dir[interfacesd].empty? }
end
file '/etc/network/interfaces' do
content "# No longer used, see SYSTEMD-NETWORKD.SERVICE(8)\n"
end
file '/etc/network/interfaces' do
content "# No longer used, see SYSTEMD-NETWORKD.SERVICE(8)\n"
end
end
# Create custom units from attributes
unless node['sys']['systemd']['unit'].empty?
node['sys']['systemd']['unit'].each do |name, config|
sys_systemd_unit name do
config.each do |key, value|
begin
send(key, value)
rescue NoMethodError => e
Chef::Log.error("sys_systemd_unit[#{name}]: "\
"No property '#{key}' (#{e})")
end
# Create custom units from attributes
unless node['sys']['systemd']['unit'].empty?
node['sys']['systemd']['unit'].each do |name, config|
sys_systemd_unit name do
config.each do |key, value|
begin
send(key, value)
rescue NoMethodError => e
Chef::Log.error("sys_systemd_unit[#{name}]: "\
"No property '#{key}' (#{e})")
end
end
end
end
end
# Enable/Start systemd-networkd
# This is e.g. needed for the systemd-networkd-wait-online.service to work.
if node['sys']['systemd']['networkd']['enable']
if systemd_active?
service 'systemd-networkd' do
supports restart: true
action [ :enable, :start ]
end
else
# We might be in a chroot
execute 'systemctl enable systemd-networkd.service'
# Enable/Start systemd-networkd
# This is e.g. needed for the systemd-networkd-wait-online.service to work.
if node['sys']['systemd']['networkd']['enable']
if systemd_active?
service 'systemd-networkd' do
supports restart: true
action [ :enable, :start ]
end
else
# We might be in a chroot
execute 'systemctl enable systemd-networkd.service'
end
end
if node['sys']['systemd']['networkd']['make_primary_interface_persistent']
# This uses ohai data, so any manual change to the network interface
# will be made permanent. This flag is intended to be used by a one-time
# mechanism like an OS installer.
if node['sys']['systemd']['networkd']['make_primary_interface_persistent']
# This uses ohai data, so any manual change to the network interface
# will be made permanent. This flag is intended to be used by a one-time
# mechanism like an OS installer.
interface = node['network']['default_interface'].to_s
ipaddress = node['ipaddress'].to_s
gateway = node['network']['default_gateway'].to_s
cidr = node['network']['interfaces'][interface]['addresses'][ipaddress]['prefixlen'].to_s
interface = node['network']['default_interface'].to_s
ipaddress = node['ipaddress'].to_s
gateway = node['network']['default_gateway'].to_s
cidr = node['network']['interfaces'][interface]['addresses'][ipaddress]['prefixlen'].to_s
unless interface.empty? || ipaddress.empty? || gateway.empty? || cidr.empty? # ~FC023
sys_systemd_unit "#{interface}.network" do
directory '/etc/systemd/network'
config({
'Match' => {
'Name' => interface
},
'Network' => {
'Address' => "#{ipaddress}/#{cidr}",
},
'Route' => {
'Gateway' => gateway
}
})
action :create
notifies(:restart, 'service[systemd-networkd]', :delayed) if systemd_active?
end
unless interface.empty? || ipaddress.empty? || gateway.empty? || cidr.empty? # ~FC023
sys_systemd_unit "#{interface}.network" do
directory '/etc/systemd/network'
config({
'Match' => {
'Name' => interface
},
'Network' => {
'Address' => "#{ipaddress}/#{cidr}",
},
'Route' => {
'Gateway' => gateway
}
})
action :create
notifies(:restart, 'service[systemd-networkd]', :delayed) if systemd_active?
end
end
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment