Skip to content

Commit

Permalink
cli:apply: improve networkd restart logic for non-existent networkd c…
Browse files Browse the repository at this point in the history
…onfig
  • Loading branch information
slyon committed Jun 26, 2024
1 parent 9ecdf53 commit a527c51
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions netplan_cli/cli/commands/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ def command_apply(self, run_generate=True, sync=False, exit_on_error=True, state
restart_networkd = False
with tempfile.TemporaryDirectory() as tmp_dir:
# needs to be a subfolder as copytree wants to create it
run_systemd_network = '/run/systemd/network'
old_files_dir = os.path.join(tmp_dir, 'cfg')
shutil.copytree('/run/systemd/network', old_files_dir)
has_old_networkd_config = os.path.isdir(run_systemd_network)
if has_old_networkd_config:
shutil.copytree(run_systemd_network, old_files_dir)

generator_call = []
generate_out = None
Expand All @@ -140,9 +143,13 @@ def command_apply(self, run_generate=True, sync=False, exit_on_error=True, state
raise ConfigurationError("the configuration could not be generated")

# Restart networkd if something in the configuration changed
comp = filecmp.dircmp('/run/systemd/network', old_files_dir)
if comp.left_only or comp.right_only or comp.diff_files:
has_new_networkd_config = os.path.isdir(run_systemd_network)
if has_old_networkd_config != has_new_networkd_config:
restart_networkd = True
elif has_old_networkd_config and has_new_networkd_config:
comp = filecmp.dircmp(run_systemd_network, old_files_dir)
if comp.left_only or comp.right_only or comp.diff_files:
restart_networkd = True

devices = netifaces.interfaces()

Expand Down

0 comments on commit a527c51

Please sign in to comment.