summaryrefslogtreecommitdiff
path: root/cloudinit/distros
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/distros
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/distros')
-rw-r--r--cloudinit/distros/photon.py217
1 files changed, 0 insertions, 217 deletions
diff --git a/cloudinit/distros/photon.py b/cloudinit/distros/photon.py
index 8b78f98f..45125be7 100644
--- a/cloudinit/distros/photon.py
+++ b/cloudinit/distros/photon.py
@@ -10,10 +10,8 @@ from cloudinit import subp
from cloudinit import distros
from cloudinit import helpers
from cloudinit import log as logging
-from cloudinit.distros import net_util
from cloudinit.settings import PER_INSTANCE
from cloudinit.distros import rhel_util as rhutil
-from cloudinit.net.network_state import mask_to_net_prefix
from cloudinit.distros.parsers.hostname import HostnameConf
LOG = logging.getLogger(__name__)
@@ -79,9 +77,6 @@ class Distro(distros.Distro):
self.package_command('install', pkgs=pkglist)
def _write_network_config(self, netconfig):
- if isinstance(netconfig, str):
- self._write_network_(netconfig)
- return
return self._supported_write_network_config(netconfig)
def _bring_up_interfaces(self, device_names):
@@ -141,215 +136,3 @@ class Distro(distros.Distro):
def update_package_sources(self):
self._runner.run('update-sources', self.package_command,
['makecache'], freq=PER_INSTANCE)
-
- def _generate_resolv_conf(self):
- resolv_conf_fn = self.resolve_conf_fn
- resolv_templ_fn = 'systemd.resolved.conf'
-
- return resolv_conf_fn, resolv_templ_fn
-
- def _write_network_(self, settings):
- entries = net_util.translate_network(settings)
- LOG.debug('Translated ubuntu style network settings %s into %s',
- settings, entries)
- route_entries = []
- route_entries = translate_routes(settings)
- dev_names = entries.keys()
- nameservers = []
- searchdomains = []
- # Format for systemd
- for (dev, info) in entries.items():
- if 'dns-nameservers' in info:
- nameservers.extend(info['dns-nameservers'])
- if 'dns-search' in info:
- searchdomains.extend(info['dns-search'])
- if dev == 'lo':
- continue
-
- net_fn = self.network_conf_dir + '10-cloud-init-' + dev
- net_fn += '.network'
- dhcp_enabled = 'no'
- if info.get('bootproto') == 'dhcp':
- if (settings.find('inet dhcp') >= 0 and
- settings.find('inet6 dhcp') >= 0):
- dhcp_enabled = 'yes'
- else:
- if info.get('inet6') is True:
- dhcp_enabled = 'ipv6'
- else:
- dhcp_enabled = 'ipv4'
-
- net_cfg = {
- 'Name': dev,
- 'DHCP': dhcp_enabled,
- }
-
- if info.get('hwaddress'):
- net_cfg['MACAddress'] = info.get('hwaddress')
- if info.get('address'):
- net_cfg['Address'] = '%s' % (info.get('address'))
- if info.get('netmask'):
- net_cfg['Address'] += '/%s' % (
- mask_to_net_prefix(info.get('netmask')))
- if info.get('gateway'):
- net_cfg['Gateway'] = info.get('gateway')
- if info.get('dns-nameservers'):
- net_cfg['DNS'] = str(
- tuple(info.get('dns-nameservers'))).replace(',', '')
- if info.get('dns-search'):
- net_cfg['Domains'] = str(
- tuple(info.get('dns-search'))).replace(',', '')
- route_entry = []
- if dev in route_entries:
- route_entry = route_entries[dev]
- route_index = 0
- found = True
- while found:
- route_name = 'routes.' + str(route_index)
- if route_name in route_entries[dev]:
- val = str(tuple(route_entries[dev][route_name]))
- val = val.replace(',', '')
- if val:
- net_cfg[route_name] = val
- else:
- found = False
- route_index += 1
-
- if info.get('auto'):
- self._write_interface_file(net_fn, net_cfg, route_entry)
-
- resolve_data = []
- new_resolve_data = []
- with open(self.resolve_conf_fn, 'r') as rf:
- resolve_data = rf.readlines()
- LOG.debug('Old Resolve Data\n')
- LOG.debug('%s', resolve_data)
- for item in resolve_data:
- if ((nameservers and ('DNS=' in item)) or
- (searchdomains and ('Domains=' in item))):
- continue
- else:
- new_resolve_data.append(item)
-
- new_resolve_data = new_resolve_data + \
- convert_resolv_conf(nameservers, searchdomains)
- LOG.debug('New resolve data\n')
- LOG.debug('%s', new_resolve_data)
- if nameservers or searchdomains:
- util.write_file(self.resolve_conf_fn, ''.join(new_resolve_data))
-
- return dev_names
-
- def _write_interface_file(self, net_fn, net_cfg, route_entry):
- if not net_cfg['Name']:
- return
- content = '[Match]\n'
- content += 'Name=%s\n' % (net_cfg['Name'])
- if 'MACAddress' in net_cfg:
- content += 'MACAddress=%s\n' % (net_cfg['MACAddress'])
- content += '[Network]\n'
-
- if 'DHCP' in net_cfg and net_cfg['DHCP'] in {'yes', 'ipv4', 'ipv6'}:
- content += 'DHCP=%s\n' % (net_cfg['DHCP'])
- else:
- if 'Address' in net_cfg:
- content += 'Address=%s\n' % (net_cfg['Address'])
- if 'Gateway' in net_cfg:
- content += 'Gateway=%s\n' % (net_cfg['Gateway'])
- if 'DHCP' in net_cfg and net_cfg['DHCP'] == 'no':
- content += 'DHCP=%s\n' % (net_cfg['DHCP'])
-
- route_index = 0
- found = True
- if route_entry:
- while found:
- route_name = 'routes.' + str(route_index)
- if route_name in route_entry:
- content += '[Route]\n'
- if len(route_entry[route_name]) != 2:
- continue
- content += 'Gateway=%s\n' % (
- route_entry[route_name][0])
- content += 'Destination=%s\n' % (
- route_entry[route_name][1])
- else:
- found = False
- route_index += 1
-
- util.write_file(net_fn, content)
-
-
-def convert_resolv_conf(nameservers, searchdomains):
- ''' Returns a string formatted for resolv.conf '''
- result = []
- if nameservers:
- nslist = 'DNS='
- for ns in nameservers:
- nslist = nslist + '%s ' % ns
- nslist = nslist + '\n'
- result.append(str(nslist))
- if searchdomains:
- sdlist = 'Domains='
- for sd in searchdomains:
- sdlist = sdlist + '%s ' % sd
- sdlist = sdlist + '\n'
- result.append(str(sdlist))
- return result
-
-
-def translate_routes(settings):
- entries = []
- for line in settings.splitlines():
- line = line.strip()
- if not line or line.startswith('#'):
- continue
- split_up = line.split(None, 1)
- if len(split_up) <= 1:
- continue
- entries.append(split_up)
- consume = {}
- ifaces = []
- for (cmd, args) in entries:
- if cmd == 'iface':
- if consume:
- ifaces.append(consume)
- consume = {}
- consume[cmd] = args
- else:
- consume[cmd] = args
-
- absorb = False
- for (cmd, args) in consume.items():
- if cmd == 'iface':
- absorb = True
- if absorb:
- ifaces.append(consume)
- out_ifaces = {}
- for info in ifaces:
- if 'iface' not in info:
- continue
- iface_details = info['iface'].split(None)
- dev_name = None
- if len(iface_details) >= 1:
- dev = iface_details[0].strip().lower()
- if dev:
- dev_name = dev
- if not dev_name:
- continue
- route_info = {}
- route_index = 0
- found = True
- while found:
- route_name = 'routes.' + str(route_index)
- if route_name in info:
- val = info[route_name].split()
- if val:
- route_info[route_name] = val
- else:
- found = False
- route_index += 1
- if dev_name in out_ifaces:
- out_ifaces[dev_name].update(route_info)
- else:
- out_ifaces[dev_name] = route_info
- return out_ifaces