Commit 7aa8ab74 authored by Christopher Huhn's avatar Christopher Huhn 🥚

Guard possible non-existance of sys.networkd.(link|netdev|network) and...

Guard possible non-existance of sys.networkd.(link|netdev|network) and introduce keep_interfaces attribute similar to sys.network
parent a55408ce
......@@ -15,4 +15,4 @@ supports 'debian'
depends 'line', '< 1.0'
version '1.53.7'
version '1.53.8'
......@@ -2,7 +2,11 @@
# Cookbook Name:: sys
# Recipe:: networkd
#
# Copyright 2017, Matthia Pausch
# Copyright 2017-2020 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
#
# Authors:
# Christopher Huhn <c.huhn@gsi.de>
# Matthias Pausch <m.pausch@gsi.de>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -22,80 +26,94 @@ if node['platform_version'].to_i >= 9 && !node['sys']['networkd'].empty?
delete = Dir.glob('/etc/systemd/network/*')
keep = []
node['sys']['networkd']['link'].keys.each do |name|
number_prefix = ''
unless name.match(/^[0-9]{2}-/)
number_prefix = '00-'
if node['sys']['networkd']['link']
node['sys']['networkd']['link'].keys.each do |name|
number_prefix = ''
unless name.match(/^[0-9]{2}-/)
number_prefix = '00-'
end
keep << "#{number_prefix}#{name}.link"
end
keep << "#{number_prefix}#{name}.link"
end
node['sys']['networkd']['netdev'].keys.each do |name|
number_prefix = ''
unless name.match(/^[0-9]{2}-/)
number_prefix = '10-'
if node['sys']['networkd']['netdev']
node['sys']['networkd']['netdev'].keys.each do |name|
number_prefix = ''
unless name.match(/^[0-9]{2}-/)
number_prefix = '10-'
end
keep << "#{number_prefix}#{name}.netdev"
end
keep << "#{number_prefix}#{name}.netdev"
end
node['sys']['networkd']['network'].keys.each do |name|
number_prefix = ''
unless name.match(/^[0-9]{2}-/)
number_prefix = '20-'
if node['sys']['networkd']['network']
node['sys']['networkd']['network'].keys.each do |name|
number_prefix = ''
unless name.match(/^[0-9]{2}-/)
number_prefix = '20-'
end
keep << "#{number_prefix}#{name}.network"
end
keep << "#{number_prefix}#{name}.network"
end
keep.map!{|e| "/etc/systemd/network/#{e}"}
(delete - keep).each do |f|
# TODO: shut down the corresponding systemd unit?
file f do
action :delete
not_if { node['sys']['networkd']['keep_interfaces'] }
end
end
node['sys']['networkd']['link'].each do |name, config|
number_prefix = ''
unless name.match(/^[0-9]{2}-/)
number_prefix = '00-'
end
if node['sys']['networkd']['link']
node['sys']['networkd']['link'].each do |name, config|
number_prefix = ''
unless name.match(/^[0-9]{2}-/)
number_prefix = '00-'
end
template "/etc/systemd/network/#{number_prefix}#{name}.link" do
source "systemd_networkd_generic.erb"
helpers(Sys::Harry)
mode "0644"
variables(:sections => config)
notifies :restart, 'service[systemd-networkd]'
# initramfs needs to be updated, when systemd.link-files change.
notifies :run, 'execute[update-initramfs]'
template "/etc/systemd/network/#{number_prefix}#{name}.link" do
source "systemd_networkd_generic.erb"
helpers(Sys::Harry)
mode "0644"
variables(:sections => config)
notifies :restart, 'service[systemd-networkd]'
# initramfs needs to be updated, when systemd.link-files change.
notifies :run, 'execute[update-initramfs]'
end
end
end
node['sys']['networkd']['netdev'].each do |name, config|
number_prefix = ''
unless name.match(/^[0-9]{2}-/)
number_prefix = '10-'
end
template "/etc/systemd/network/#{number_prefix}#{name}.netdev" do
source "systemd_networkd_generic.erb"
helpers(Sys::Harry)
mode "0644"
variables(:sections => config)
notifies :restart, "service[systemd-networkd]"
if node['sys']['networkd']['netdev']
node['sys']['networkd']['netdev'].each do |name, config|
number_prefix = ''
unless name.match(/^[0-9]{2}-/)
number_prefix = '10-'
end
template "/etc/systemd/network/#{number_prefix}#{name}.netdev" do
source "systemd_networkd_generic.erb"
helpers(Sys::Harry)
mode "0644"
variables(:sections => config)
notifies :restart, "service[systemd-networkd]"
end
end
end
node['sys']['networkd']['network'].each do |name, config|
number_prefix = ''
unless name.match(/^[0-9]{2}-/)
number_prefix = '20-'
end
template "/etc/systemd/network/#{number_prefix}#{name}.network" do
source "systemd_networkd_generic.erb"
helpers(Sys::Harry)
mode "0644"
variables(:sections => config)
notifies :restart, "service[systemd-networkd]"
if node['sys']['networkd']['network']
node['sys']['networkd']['network'].each do |name, config|
number_prefix = ''
unless name.match(/^[0-9]{2}-/)
number_prefix = '20-'
end
template "/etc/systemd/network/#{number_prefix}#{name}.network" do
source "systemd_networkd_generic.erb"
helpers(Sys::Harry)
mode "0644"
variables(:sections => config)
notifies :restart, "service[systemd-networkd]"
end
end
end
......@@ -108,5 +126,6 @@ if node['platform_version'].to_i >= 9 && !node['sys']['networkd'].empty?
execute 'update-initramfs' do
action :nothing
command 'update-initramfs -u'
only_if { node['sys']['networkd']['link'] }
end
end
Markdown is supported
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