Skip to content

Commit

Permalink
net/sysconfig: do not remove all existing settings of /etc/sysconfig/…
Browse files Browse the repository at this point in the history
…network

In some distros, /etc/sysconfig/network may have important cconfigurations that
are necessary for the instance to come up. For example, centos based distros
write NOZEROCONF=yes in /etc/sysconfig/network for some instances that require
zeroconf to be disabled. Removing these customizations would prevent the
instance to come up. So leave the customizations in /etc/sysconfig/network
intact except those that we are interested in.

Fixes canonicalGH-5990
Signed-off-by: Ani Sinha <[email protected]>
  • Loading branch information
ani-sinha committed Jan 28, 2025
1 parent 4dce22a commit fdd69f7
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cloudinit/net/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,24 @@ def render_network_state(
if network_state.use_ipv6:
netcfg.append("NETWORKING_IPV6=yes")
netcfg.append("IPV6_AUTOCONF=no")

# if sysconfig file exists and is not empty, append rest of the
# file content, do not remove the exsisting customizations.
if os.path.exists(sysconfig_path):
for line in util.load_text_file(sysconfig_path).splitlines():
if (
not any(
setting in line
for setting in [
"NETWORKING",
"NETWORKING_IPV6",
"IPV6_AUTOCONF",
]
)
and line not in _make_header().splitlines()
):
netcfg.append(line)

util.write_file(
sysconfig_path, "\n".join(netcfg) + "\n", file_mode
)
Expand Down

0 comments on commit fdd69f7

Please sign in to comment.