From 6fe1983777663a1a1136fd73dc50244f2d030be8 Mon Sep 17 00:00:00 2001 From: Gonéri Le Bouder Date: Fri, 14 May 2021 15:58:47 -0400 Subject: BSD: static network, set the mtu (#894) In the case of a static network, we now set the MTU according to the meta-data. --- cloudinit/net/bsd.py | 1 + cloudinit/net/freebsd.py | 11 ++++++----- cloudinit/net/netbsd.py | 8 +++++--- cloudinit/net/openbsd.py | 6 +++++- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/cloudinit/net/bsd.py b/cloudinit/net/bsd.py index e34e0454..aab968a8 100644 --- a/cloudinit/net/bsd.py +++ b/cloudinit/net/bsd.py @@ -76,6 +76,7 @@ class BSDRenderer(renderer.Renderer): self.interface_configurations[device_name] = { 'address': subnet.get('address'), 'netmask': subnet.get('netmask'), + 'mtu': subnet.get('mtu'), } def _route_entries(self, settings, target=None): diff --git a/cloudinit/net/freebsd.py b/cloudinit/net/freebsd.py index 0285dfec..c843d792 100644 --- a/cloudinit/net/freebsd.py +++ b/cloudinit/net/freebsd.py @@ -19,12 +19,13 @@ class Renderer(cloudinit.net.bsd.BSDRenderer): def write_config(self): for device_name, v in self.interface_configurations.items(): + net_config = 'DHCP' if isinstance(v, dict): - self.set_rc_config_value( - 'ifconfig_' + device_name, - v.get('address') + ' netmask ' + v.get('netmask')) - else: - self.set_rc_config_value('ifconfig_' + device_name, 'DHCP') + net_config = v.get('address') + ' netmask ' + v.get('netmask') + mtu = v.get('mtu') + if mtu: + net_config += (' mtu %d' % mtu) + self.set_rc_config_value('ifconfig_' + device_name, net_config) def start_services(self, run=False): if not run: diff --git a/cloudinit/net/netbsd.py b/cloudinit/net/netbsd.py index 71b38ee6..5f8881a5 100644 --- a/cloudinit/net/netbsd.py +++ b/cloudinit/net/netbsd.py @@ -22,9 +22,11 @@ class Renderer(cloudinit.net.bsd.BSDRenderer): ) for device_name, v in self.interface_configurations.items(): if isinstance(v, dict): - self.set_rc_config_value( - 'ifconfig_' + device_name, - v.get('address') + ' netmask ' + v.get('netmask')) + net_config = v.get('address') + ' netmask ' + v.get('netmask') + mtu = v.get('mtu') + if mtu: + net_config += (' mtu %d' % mtu) + self.set_rc_config_value('ifconfig_' + device_name, net_config) def start_services(self, run=False): if not run: diff --git a/cloudinit/net/openbsd.py b/cloudinit/net/openbsd.py index 166d77e6..9ec7ee9e 100644 --- a/cloudinit/net/openbsd.py +++ b/cloudinit/net/openbsd.py @@ -18,7 +18,7 @@ class Renderer(cloudinit.net.bsd.BSDRenderer): content = 'dhcp\n' elif isinstance(v, dict): try: - content = "inet {address} {netmask}\n".format( + content = "inet {address} {netmask}".format( address=v['address'], netmask=v['netmask'] ) @@ -26,6 +26,10 @@ class Renderer(cloudinit.net.bsd.BSDRenderer): LOG.error( "Invalid static configuration for %s", device_name) + mtu = v.get("mtu") + if mtu: + content += (' mtu %d' % mtu) + content += "\n" util.write_file(fn, content) def start_services(self, run=False): -- cgit v1.2.3