summaryrefslogtreecommitdiff
path: root/cloudinit/net
diff options
context:
space:
mode:
authorsshedi <53473811+sshedi@users.noreply.github.com>2021-06-29 00:12:34 +0530
committerGitHub <noreply@github.com>2021-06-28 13:42:34 -0500
commitb5aecbe9512fa546255cc93b178b4081342fc247 (patch)
treee7300b313984dfdde9799294d8f2a02f276e19c0 /cloudinit/net
parent35aa9db6f8e2ba05d366776c0e8d97f52217e930 (diff)
downloadvyos-cloud-init-b5aecbe9512fa546255cc93b178b4081342fc247.tar.gz
vyos-cloud-init-b5aecbe9512fa546255cc93b178b4081342fc247.zip
Removed distro specific network code from Photon (#929)
Minor fixes in networkd renderer & fixed corresponding tests Removed datasource_list for Photon from cloud.cfg.tmpl & added a comment in cloud.cfg.tmpl about not to use multiline array for datasource_list. Signed-off-by: Shreenidhi Shedi <sshedi@vmware.com>
Diffstat (limited to 'cloudinit/net')
-rw-r--r--cloudinit/net/networkd.py51
1 files changed, 32 insertions, 19 deletions
diff --git a/cloudinit/net/networkd.py b/cloudinit/net/networkd.py
index 71f87995..2dffce59 100644
--- a/cloudinit/net/networkd.py
+++ b/cloudinit/net/networkd.py
@@ -35,6 +35,8 @@ class CfgParser:
for k in self.conf_dict.keys():
if k == sec:
self.conf_dict[k].append(key+'='+str(val))
+ # remove duplicates from list
+ self.conf_dict[k] = list(dict.fromkeys(self.conf_dict[k]))
self.conf_dict[k].sort()
def get_final_conf(self):
@@ -103,19 +105,27 @@ class Renderer(renderer.Renderer):
def parse_routes(self, conf, cfg):
sec = 'Route'
+ route_cfg_map = {
+ 'gateway': 'Gateway',
+ 'network': 'Destination',
+ 'metric': 'Metric',
+ }
+
+ # prefix is derived using netmask by network_state
+ prefix = ''
+ if 'prefix' in conf:
+ prefix = '/' + str(conf['prefix'])
+
for k, v in conf.items():
- if k == 'gateway':
- cfg.update_section(sec, 'Gateway', v)
- elif k == 'network':
- tmp = v
- if 'prefix' in conf:
- tmp += '/' + str(conf['prefix'])
- cfg.update_section(sec, 'Destination', tmp)
- elif k == 'metric':
- cfg.update_section(sec, 'Metric', v)
+ if k not in route_cfg_map:
+ continue
+ if k == 'network':
+ v += prefix
+ cfg.update_section(sec, route_cfg_map[k], v)
def parse_subnets(self, iface, cfg):
dhcp = 'no'
+ sec = 'Network'
for e in iface.get('subnets', []):
t = e['type']
if t == 'dhcp4' or t == 'dhcp':
@@ -131,21 +141,24 @@ class Renderer(renderer.Renderer):
if 'routes' in e and e['routes']:
for i in e['routes']:
self.parse_routes(i, cfg)
- elif 'address' in e:
+ if 'address' in e:
+ subnet_cfg_map = {
+ 'address': 'Address',
+ 'gateway': 'Gateway',
+ 'dns_nameservers': 'DNS',
+ 'dns_search': 'Domains',
+ }
for k, v in e.items():
if k == 'address':
- tmp = v
if 'prefix' in e:
- tmp += '/' + str(e['prefix'])
- cfg.update_section('Address', 'Address', tmp)
+ v += '/' + str(e['prefix'])
+ cfg.update_section('Address', subnet_cfg_map[k], v)
elif k == 'gateway':
- cfg.update_section('Route', 'Gateway', v)
- elif k == 'dns_nameservers':
- cfg.update_section('Network', 'DNS', ' '.join(v))
- elif k == 'dns_search':
- cfg.update_section('Network', 'Domains', ' '.join(v))
+ cfg.update_section('Route', subnet_cfg_map[k], v)
+ elif k == 'dns_nameservers' or k == 'dns_search':
+ cfg.update_section(sec, subnet_cfg_map[k], ' '.join(v))
- cfg.update_section('Network', 'DHCP', dhcp)
+ cfg.update_section(sec, 'DHCP', dhcp)
# This is to accommodate extra keys present in VMware config
def dhcp_domain(self, d, cfg):