File cloud-init-write-routes.patch of Package cloud-init.14638

--- cloudinit/distros/opensuse.py.orig
+++ cloudinit/distros/opensuse.py
@@ -11,6 +11,7 @@
 from cloudinit import distros
 
 from cloudinit.distros.parsers.hostname import HostnameConf
+from cloudinit.net.network_state import mask_to_net_prefix
 
 from cloudinit import helpers
 from cloudinit import log as logging
@@ -172,7 +173,69 @@ class Distro(distros.Distro):
             util.write_file(out_fn, str(conf), 0o644)
 
     def _write_network_config(self, netconfig):
-        return self._supported_write_network_config(netconfig)
+        net_apply_res = self._supported_write_network_config(netconfig)
+        # Clobber the route files that were written in RH key-value style
+        self._write_routes(netconfig)
+        return net_apply_res
+
+    def _write_routes(self, netconfig):
+        """Write route files, not part of the standard distro interface"""
+        # Due to the implementation of the sysconfig renderer default routes
+        # are setup in ifcfg-* files. But this does not work on SLES or
+        # openSUSE https://bugs.launchpad.net/cloud-init/+bug/1812117
+        # this is a very hacky way to get around the problem until a real
+        # solution is found in the sysconfig renderer
+        device_configs = netconfig.get('config', [])
+        default_nets = ('::', '0.0.0.0')
+        for config in device_configs:
+            if_name = config.get('name')
+            subnets = config.get('subnets', [])
+            config_routes = ''
+            has_default_route = False
+            for subnet in subnets:
+                # Render the default gateway if it is present
+                gateway = subnet.get('gateway')
+                if gateway:
+                    config_routes += ' '.join(
+                        ['default', gateway, '-', '-\n']
+                    )
+                    has_default_route = True
+                # Render subnet routes
+                routes = subnet.get('routes', [])
+                for route in routes:
+                    dest = route.get('destination') or route.get('network')
+                    if not dest or dest in default_nets:
+                        dest = 'default'
+                    if dest != 'default':
+                        netmask = route.get('netmask')
+                        if netmask:
+                            prefix = mask_to_net_prefix(netmask)
+                            dest += '/' + str(prefix)
+                        if '/' not in dest:
+                            LOG.warning(
+                                'Skipping route; has no prefix "%s"', dest
+                            )
+                            continue
+                    if dest == 'default' and has_default_route:
+                        LOG.warning(
+                            '%s already has default route, skipping "%s"',
+                            if_name, ' '.join([dest, gateway, '-', '-'])
+                        )
+                        continue
+                    if dest == 'default' and not has_default_route:
+                        has_default_route = True
+                    gateway = route.get('gateway')
+                    if not gateway:
+                        LOG.warning(
+                            'Missing gateway for "%s", skipping', dest
+                        )
+                        continue
+                    config_routes += ' '.join(
+                        [dest, gateway, '-', '-\n']
+                    )
+            if config_routes:
+                route_file = '/etc/sysconfig/network/ifroute-%s' % if_name
+                util.write_file(route_file, config_routes)
 
     @property
     def preferred_ntp_clients(self):
openSUSE Build Service is sponsored by