summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWesley Wiedenmeier <wesley.wiedenmeier@gmail.com>2016-03-18 02:30:59 -0500
committerWesley Wiedenmeier <wesley.wiedenmeier@gmail.com>2016-03-18 02:30:59 -0500
commitc03915a454cfa947c1d905ba5b55a5207ad85cda (patch)
treea34b3abd34f7bb3087840feb91d79d6b60230b50
parent671493a26966b179ecc09ce222b987fbc5376fe2 (diff)
downloadvyos-cloud-init-c03915a454cfa947c1d905ba5b55a5207ad85cda.tar.gz
vyos-cloud-init-c03915a454cfa947c1d905ba5b55a5207ad85cda.zip
Fully parse files at /run/net-dev.conf, loading parameters for address,
broadcast, netmask, gateway and hostname if present
-rw-r--r--cloudinit/net/__init__.py36
1 files changed, 27 insertions, 9 deletions
diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py
index e455040d..cce0773f 100644
--- a/cloudinit/net/__init__.py
+++ b/cloudinit/net/__init__.py
@@ -280,21 +280,39 @@ def parse_net_config(path):
return ns
-def load_key_value_pair_net_cfg(data_mapping):
+def load_klibc_net_cfg(data_mapping):
"""Process key value pairs from files written because of the ip parameter
on the kernel cmdline"""
- subnets = []
entry_ns = {
'mtu': None, 'name': data_mapping['DEVICE'], 'type': 'physical',
- 'mode': 'manual', 'inet': 'inet', 'gateway': None, 'address': None
+ 'mode': 'manual', 'inet': 'inet', 'gateway': None, 'address': None,
+ 'subnets': []
}
if data_mapping.get('PROTO') == 'dhcp':
- if 'IPV4ADDR' in data_mapping:
- subnets.append({'type': 'dhcp4'})
- if 'IPV6ADDR' in data_mapping:
- subnets.append({'type': 'dhcp6'})
- entry_ns['subnets'] = subnets
+ if data_mapping.get('IPV4ADDR'):
+ entry_ns['subnets'].append({'type': 'dhcp4'})
+ if data_mapping.get('IPV6ADDR'):
+ entry_ns['subnets'].append({'type': 'dhcp6'})
+
+ if data_mapping.get('IPV4ADDR'):
+ entry_ns['address'] = data_mapping['IPV4ADDR']
+ if data_mapping.get('IPV6ADDR'):
+ entry_ns['address'] = data_mapping['IPV6ADDR']
+ if data_mapping.get('IPV4BROADCAST'):
+ entry_ns['broadcast'] = data_mapping['IPV4BROADCAST']
+ if data_mapping.get('IPV6BROADCAST'):
+ entry_ns['broadcast'] = data_mapping['IPV6BROADCAST']
+ if data_mapping.get('IPV4NETMASK'):
+ entry_ns['netmask'] = data_mapping['IPV4NETMASK']
+ if data_mapping.get('IPV6NETMASK'):
+ entry_ns['netmask'] = data_mapping['IPV6NETMASK']
+ if data_mapping.get('IPV4GATEWAY'):
+ entry_ns['gateway'] = data_mapping['IPV4GATEWAY']
+ if data_mapping.get('IPV6GATEWAY'):
+ entry_ns['gateway'] = data_mapping['IPV6GATEWAY']
+ if data_mapping.get('HOSTNAME'):
+ entry_ns['hostname'] = data_mapping['HOSTNAME']
return entry_ns
@@ -322,7 +340,7 @@ def merge_from_cmdline_config(ns):
# Not a net cfg file
continue
- loaded_ns = load_key_value_pair_net_cfg(parsed)
+ loaded_ns = load_klibc_net_cfg(parsed)
if dev_name in ns['interfaces']:
if 'subnets' not in ns['interfaces'][dev_name]: