diff options
author | Joshua Harlow <harlowja@gmail.com> | 2016-06-15 16:11:24 -0700 |
---|---|---|
committer | Joshua Harlow <harlowja@gmail.com> | 2016-06-15 16:11:24 -0700 |
commit | 459de83024b41c32823b75cf483da994fb1388b7 (patch) | |
tree | 3f611a640fe41f82b1b27cf7f2ea94a78603cd49 /cloudinit/net/eni.py | |
parent | e0b1e3a8c925446ee9e6d15aae1783b49fb870f8 (diff) | |
download | vyos-cloud-init-459de83024b41c32823b75cf483da994fb1388b7.tar.gz vyos-cloud-init-459de83024b41c32823b75cf483da994fb1388b7.zip |
Fixup code review comments
Diffstat (limited to 'cloudinit/net/eni.py')
-rw-r--r-- | cloudinit/net/eni.py | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/cloudinit/net/eni.py b/cloudinit/net/eni.py index df0df9b2..352f7dd5 100644 --- a/cloudinit/net/eni.py +++ b/cloudinit/net/eni.py @@ -16,10 +16,9 @@ import glob import os import re -from . import LINKS_FNAME_PREFIX from . import ParserError -from .udev import generate_udev_rule +from . import renderer from cloudinit import util @@ -297,9 +296,18 @@ def _ifaces_to_net_config_data(ifaces): 'config': [devs[d] for d in sorted(devs)]} -class Renderer(object): +class Renderer(renderer.Renderer): """Renders network information in a /etc/network/interfaces format.""" + def __init__(self, config=None): + if not config: + config = {} + self.eni_path = config.get('eni_path', 'etc/network/interfaces') + self.links_path_prefix = config.get( + 'links_path_prefix', 'etc/systemd/network/50-cloud-init-') + self.netrules_path = config.get( + 'netrules_path', 'etc/udev/rules.d/70-persistent-net.rules') + def _render_persistent_net(self, network_state): """Given state, emit udev rules to map mac to ifname.""" content = "" @@ -419,29 +427,23 @@ class Renderer(object): content = content.replace('mac_address', 'hwaddress') return content - def render_network_state( - self, target, network_state, eni="etc/network/interfaces", - links_prefix=LINKS_FNAME_PREFIX, - netrules='etc/udev/rules.d/70-persistent-net.rules', - writer=None): - - fpeni = os.path.sep.join((target, eni,)) + def render_network_state(self, target, network_state): + fpeni = os.path.join(target, self.eni_path) util.ensure_dir(os.path.dirname(fpeni)) util.write_file(fpeni, self._render_interfaces(network_state)) - if netrules: - netrules = os.path.sep.join((target, netrules,)) + if self.netrules_path: + netrules = os.path.join(target, self.netrules_path) util.ensure_dir(os.path.dirname(netrules)) util.write_file(netrules, self._render_persistent_net(network_state)) - if links_prefix: + if self.links_path_prefix: self._render_systemd_links(target, network_state, - links_prefix=links_prefix) + links_prefix=self.links_path_prefix) - def _render_systemd_links(self, target, network_state, - links_prefix=LINKS_FNAME_PREFIX): - fp_prefix = os.path.sep.join((target, links_prefix)) + def _render_systemd_links(self, target, network_state, links_prefix): + fp_prefix = os.path.join(target, links_prefix) for f in glob.glob(fp_prefix + "*"): os.unlink(f) for iface in network_state.iter_interfaces(): |