summaryrefslogtreecommitdiff
path: root/cloudinit/net
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2018-03-28 12:29:04 -0600
committerChad Smith <chad.smith@canonical.com>2018-03-28 12:29:04 -0600
commitcf3eaed2e01062f9b5d47042d7a76b092970e0cf (patch)
tree53f7c52c5a76bb586da0483699fd6d188e72f457 /cloudinit/net
parent9f159f3a55a7bba7868e03d9cccd898678381f03 (diff)
parent8caa3bcf8f2c5b3a448b9d892d4cf53ed8db9be9 (diff)
downloadvyos-cloud-init-cf3eaed2e01062f9b5d47042d7a76b092970e0cf.tar.gz
vyos-cloud-init-cf3eaed2e01062f9b5d47042d7a76b092970e0cf.zip
merge from master at 18.2
Diffstat (limited to 'cloudinit/net')
-rwxr-xr-xcloudinit/net/cmdline.py24
-rw-r--r--cloudinit/net/netplan.py35
-rw-r--r--cloudinit/net/network_state.py12
3 files changed, 47 insertions, 24 deletions
diff --git a/cloudinit/net/cmdline.py b/cloudinit/net/cmdline.py
index 7b2cc9db..9e9fe0fe 100755
--- a/cloudinit/net/cmdline.py
+++ b/cloudinit/net/cmdline.py
@@ -9,12 +9,15 @@ import base64
import glob
import gzip
import io
+import os
from . import get_devicelist
from . import read_sys_net_safe
from cloudinit import util
+_OPEN_ISCSI_INTERFACE_FILE = "/run/initramfs/open-iscsi.interface"
+
def _klibc_to_config_entry(content, mac_addrs=None):
"""Convert a klibc written shell content file to a 'config' entry
@@ -103,9 +106,13 @@ def _klibc_to_config_entry(content, mac_addrs=None):
return name, iface
+def _get_klibc_net_cfg_files():
+ return glob.glob('/run/net-*.conf') + glob.glob('/run/net6-*.conf')
+
+
def config_from_klibc_net_cfg(files=None, mac_addrs=None):
if files is None:
- files = glob.glob('/run/net-*.conf') + glob.glob('/run/net6-*.conf')
+ files = _get_klibc_net_cfg_files()
entries = []
names = {}
@@ -160,10 +167,23 @@ def _b64dgz(b64str, gzipped="try"):
return _decomp_gzip(blob, strict=gzipped != "try")
+def _is_initramfs_netconfig(files, cmdline):
+ if files:
+ if 'ip=' in cmdline or 'ip6=' in cmdline:
+ return True
+ if os.path.exists(_OPEN_ISCSI_INTERFACE_FILE):
+ # iBft can configure networking without ip=
+ return True
+ return False
+
+
def read_kernel_cmdline_config(files=None, mac_addrs=None, cmdline=None):
if cmdline is None:
cmdline = util.get_cmdline()
+ if files is None:
+ files = _get_klibc_net_cfg_files()
+
if 'network-config=' in cmdline:
data64 = None
for tok in cmdline.split():
@@ -172,7 +192,7 @@ def read_kernel_cmdline_config(files=None, mac_addrs=None, cmdline=None):
if data64:
return util.load_yaml(_b64dgz(data64))
- if 'ip=' not in cmdline and 'ip6=' not in cmdline:
+ if not _is_initramfs_netconfig(files, cmdline):
return None
if mac_addrs is None:
diff --git a/cloudinit/net/netplan.py b/cloudinit/net/netplan.py
index d3788af8..63443484 100644
--- a/cloudinit/net/netplan.py
+++ b/cloudinit/net/netplan.py
@@ -311,12 +311,12 @@ class Renderer(renderer.Renderer):
if newname is None:
continue
br_config.update({newname: value})
- if newname == 'path-cost':
- # <interface> <cost> -> <interface>: int(<cost>)
+ if newname in ['path-cost', 'port-priority']:
+ # <interface> <value> -> <interface>: int(<value>)
newvalue = {}
- for costval in value:
- (port, cost) = costval.split()
- newvalue[port] = int(cost)
+ for val in value:
+ (port, portval) = val.split()
+ newvalue[port] = int(portval)
br_config.update({newname: newvalue})
if len(br_config) > 0:
@@ -336,22 +336,15 @@ class Renderer(renderer.Renderer):
_extract_addresses(ifcfg, vlan)
vlans.update({ifname: vlan})
- # inject global nameserver values under each physical interface
- if nameservers:
- for _eth, cfg in ethernets.items():
- nscfg = cfg.get('nameservers', {})
- addresses = nscfg.get('addresses', [])
- addresses += nameservers
- nscfg.update({'addresses': addresses})
- cfg.update({'nameservers': nscfg})
-
- if searchdomains:
- for _eth, cfg in ethernets.items():
- nscfg = cfg.get('nameservers', {})
- search = nscfg.get('search', [])
- search += searchdomains
- nscfg.update({'search': search})
- cfg.update({'nameservers': nscfg})
+ # inject global nameserver values under each all interface which
+ # has addresses and do not already have a DNS configuration
+ if nameservers or searchdomains:
+ nscfg = {'addresses': nameservers, 'search': searchdomains}
+ for section in [ethernets, wifis, bonds, bridges, vlans]:
+ for _name, cfg in section.items():
+ if 'nameservers' in cfg or 'addresses' not in cfg:
+ continue
+ cfg.update({'nameservers': nscfg})
# workaround yaml dictionary key sorting when dumping
def _render_section(name, section):
diff --git a/cloudinit/net/network_state.py b/cloudinit/net/network_state.py
index fe667d88..6d63e5c5 100644
--- a/cloudinit/net/network_state.py
+++ b/cloudinit/net/network_state.py
@@ -47,7 +47,7 @@ NET_CONFIG_TO_V2 = {
'bridge_maxage': 'max-age',
'bridge_maxwait': None,
'bridge_pathcost': 'path-cost',
- 'bridge_portprio': None,
+ 'bridge_portprio': 'port-priority',
'bridge_stp': 'stp',
'bridge_waitport': None}}
@@ -708,6 +708,7 @@ class NetworkStateInterpreter(object):
gateway4 = None
gateway6 = None
+ nameservers = {}
for address in cfg.get('addresses', []):
subnet = {
'type': 'static',
@@ -723,6 +724,15 @@ class NetworkStateInterpreter(object):
gateway4 = cfg.get('gateway4')
subnet.update({'gateway': gateway4})
+ if 'nameservers' in cfg and not nameservers:
+ addresses = cfg.get('nameservers').get('addresses')
+ if addresses:
+ nameservers['dns_nameservers'] = addresses
+ search = cfg.get('nameservers').get('search')
+ if search:
+ nameservers['dns_search'] = search
+ subnet.update(nameservers)
+
subnets.append(subnet)
routes = []