f3523f3
From 1a2b2cf55115a15244b9a7786959415f9fe421f9 Mon Sep 17 00:00:00 2001
e7d90aa
From: Eduardo Otubo <otubo@redhat.com>
f3523f3
Date: Thu, 2 Sep 2021 10:36:28 +0200
f3523f3
Subject: [PATCH] Don't override default network configuration
e7d90aa
e7d90aa
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
e7d90aa
---
e7d90aa
 cloudinit/net/sysconfig.py | 12 +++++++++++-
e7d90aa
 1 file changed, 11 insertions(+), 1 deletion(-)
e7d90aa
e7d90aa
diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
f3523f3
index 06f7255e..bbe22d3d 100644
e7d90aa
--- a/cloudinit/net/sysconfig.py
e7d90aa
+++ b/cloudinit/net/sysconfig.py
f3523f3
@@ -940,7 +940,17 @@ class Renderer(renderer.Renderer):
e7d90aa
         # Distros configuring /etc/sysconfig/network as a file e.g. Centos
e7d90aa
         if sysconfig_path.endswith('network'):
e7d90aa
             util.ensure_dir(os.path.dirname(sysconfig_path))
e7d90aa
-            netcfg = [_make_header(), 'NETWORKING=yes']
e7d90aa
+            # Make sure that existing lines, other than overriding ones, remain
e7d90aa
+            netcfg = []
e7d90aa
+            for line in util.load_file(sysconfig_path, quiet=True).split('\n'):
e7d90aa
+                if 'cloud-init' in line:
e7d90aa
+                    break
e7d90aa
+                if not line.startswith(('NETWORKING=',
e7d90aa
+                                        'IPV6_AUTOCONF=',
e7d90aa
+                                        'NETWORKING_IPV6=')):
e7d90aa
+                    netcfg.append(line)
e7d90aa
+            # Now generate the cloud-init portion of sysconfig/network
e7d90aa
+            netcfg.extend([_make_header(), 'NETWORKING=yes'])
e7d90aa
             if network_state.use_ipv6:
e7d90aa
                 netcfg.append('NETWORKING_IPV6=yes')
e7d90aa
                 netcfg.append('IPV6_AUTOCONF=no')
e7d90aa
-- 
4a04423
2.27.0
e7d90aa