-
Notifications
You must be signed in to change notification settings - Fork 914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new network activators to bring up interfaces (SC-85) #919
Changes from all commits
280b9fc
690c012
353efb7
14e6a0e
947b823
f4b15f5
4a211c6
12c6ad0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,13 +16,16 @@ | |
import string | ||
import urllib.parse | ||
from io import StringIO | ||
from typing import Any, Mapping | ||
|
||
from cloudinit import importer | ||
from cloudinit import log as logging | ||
from cloudinit import net | ||
from cloudinit.net import activators | ||
from cloudinit.net import eni | ||
from cloudinit.net import network_state | ||
from cloudinit.net import renderers | ||
from cloudinit.net.network_state import parse_net_config_data | ||
from cloudinit import persistence | ||
from cloudinit import ssh_util | ||
from cloudinit import type_utils | ||
|
@@ -72,7 +75,7 @@ class Distro(persistence.CloudInitPickleMixin, metaclass=abc.ABCMeta): | |
hostname_conf_fn = "/etc/hostname" | ||
tz_zone_dir = "/usr/share/zoneinfo" | ||
init_cmd = ['service'] # systemctl, service etc | ||
renderer_configs = {} | ||
renderer_configs = {} # type: Mapping[str, Mapping[str, Any]] | ||
_preferred_ntp_clients = None | ||
networking_cls = LinuxNetworking | ||
# This is used by self.shutdown_command(), and can be overridden in | ||
|
@@ -106,23 +109,20 @@ def install_packages(self, pkglist): | |
raise NotImplementedError() | ||
|
||
def _write_network(self, settings): | ||
raise RuntimeError( | ||
"""Deprecated. Remove if/when arch and gentoo support renderers.""" | ||
raise NotImplementedError( | ||
"Legacy function '_write_network' was called in distro '%s'.\n" | ||
"_write_network_config needs implementation.\n" % self.name) | ||
|
||
def _write_network_config(self, settings): | ||
raise NotImplementedError() | ||
|
||
def _supported_write_network_config(self, network_config): | ||
def _write_network_state(self, network_state): | ||
priority = util.get_cfg_by_path( | ||
self._cfg, ('network', 'renderers'), None) | ||
|
||
name, render_cls = renderers.select(priority=priority) | ||
LOG.debug("Selected renderer '%s' from priority list: %s", | ||
name, priority) | ||
renderer = render_cls(config=self.renderer_configs.get(name)) | ||
renderer.render_network_config(network_config) | ||
return [] | ||
renderer.render_network_state(network_state) | ||
|
||
def _find_tz_file(self, tz): | ||
tz_file = os.path.join(self.tz_zone_dir, str(tz)) | ||
|
@@ -174,6 +174,7 @@ def get_package_mirror_info(self, arch=None, data_source=None): | |
mirror_info=arch_info) | ||
|
||
def apply_network(self, settings, bring_up=True): | ||
"""Deprecated. Remove if/when arch and gentoo support renderers.""" | ||
# this applies network where 'settings' is interfaces(5) style | ||
# it is obsolete compared to apply_network_config | ||
# Write it out | ||
|
@@ -188,6 +189,7 @@ def apply_network(self, settings, bring_up=True): | |
return False | ||
|
||
def _apply_network_from_network_config(self, netconfig, bring_up=True): | ||
"""Deprecated. Remove if/when arch and gentoo support renderers.""" | ||
distro = self.__class__ | ||
LOG.warning("apply_network_config is not currently implemented " | ||
"for distribution '%s'. Attempting to use apply_network", | ||
|
@@ -208,16 +210,18 @@ def apply_network_config(self, netconfig, bring_up=False): | |
# apply network config netconfig | ||
# This method is preferred to apply_network which only takes | ||
# a much less complete network config format (interfaces(5)). | ||
network_state = parse_net_config_data(netconfig) | ||
try: | ||
dev_names = self._write_network_config(netconfig) | ||
self._write_network_state(network_state) | ||
except NotImplementedError: | ||
# backwards compat until all distros have apply_network_config | ||
return self._apply_network_from_network_config( | ||
netconfig, bring_up=bring_up) | ||
|
||
# Now try to bring them up | ||
if bring_up: | ||
return self._bring_up_interfaces(dev_names) | ||
network_activator = activators.select_activator() | ||
network_activator.bring_up_all_interfaces(network_state) | ||
return False | ||
|
||
def apply_network_config_names(self, netconfig): | ||
|
@@ -393,20 +397,11 @@ def preferred_ntp_clients(self): | |
return self._preferred_ntp_clients | ||
|
||
def _bring_up_interface(self, device_name): | ||
cmd = ['ifup', device_name] | ||
LOG.debug("Attempting to run bring up interface %s using command %s", | ||
device_name, cmd) | ||
try: | ||
(_out, err) = subp.subp(cmd) | ||
if len(err): | ||
LOG.warning("Running %s resulted in stderr output: %s", | ||
cmd, err) | ||
return True | ||
except subp.ProcessExecutionError: | ||
util.logexc(LOG, "Running interface command %s failed", cmd) | ||
return False | ||
"""Deprecated. Remove if/when arch and gentoo support renderers.""" | ||
raise NotImplementedError | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will break both gentoo which directly calls Distros._bring_up_interface. Don't we need to either:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't actually. The call hierarchy would work like this: The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. D'oh right. |
||
|
||
def _bring_up_interfaces(self, device_names): | ||
"""Deprecated. Remove if/when arch and gentoo support renderers.""" | ||
am_failed = 0 | ||
for d in device_names: | ||
if not self._bring_up_interface(d): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,9 +61,9 @@ def install_packages(self, pkglist): | |
self.update_package_sources() | ||
self.package_command('', pkgs=pkglist) | ||
|
||
def _write_network_config(self, netconfig): | ||
def _write_network_state(self, network_state): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should also drop "_bring_up_interfaces" from arch as it as a near equivalent (yet less functional) of the parent class |
||
try: | ||
return self._supported_write_network_config(netconfig) | ||
super()._write_network_state(network_state) | ||
except RendererNotFoundError as e: | ||
# Fall back to old _write_network | ||
raise NotImplementedError from e | ||
|
@@ -101,12 +101,6 @@ def _bring_up_interface(self, device_name): | |
util.logexc(LOG, "Running interface command %s failed", cmd) | ||
return False | ||
|
||
def _bring_up_interfaces(self, device_names): | ||
for d in device_names: | ||
if not self._bring_up_interface(d): | ||
return False | ||
return True | ||
|
||
def _write_hostname(self, your_hostname, out_fn): | ||
conf = None | ||
try: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good naming, makes it more clear