summaryrefslogtreecommitdiff
path: root/cloudinit/distros/__init__.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2016-07-14 14:25:09 -0400
committerScott Moser <smoser@ubuntu.com>2016-07-14 14:25:09 -0400
commitf92858727965cbb85dfac24a9a79a71779e5edff (patch)
tree5815cfa2ec4f9035753e904f30116fdd5b872553 /cloudinit/distros/__init__.py
parentf886cf61f546f3c5f91340ebb8fd11437c0bfd70 (diff)
parentdeefa139c922fe129c5ed672e4b62b404485d8c0 (diff)
downloadcloud-init-f92858727965cbb85dfac24a9a79a71779e5edff.tar.gz
ConfigDrive: fix writing of 'injected' files and legacy networking
Previous commit inadvertently disabled the consumption of 'injected' files in configdrive (openstack server boot --file=/target/file=local-file) unless the datasource was in 'pass' mode. The default mode is 'net' so that was not likely to happen. Also here are: a.) some comments to apply_network_config b.) add backwards compatibility for distros that do not yet implement apply_network_config by converting the network config into ENI format and calling apply_network. This is required because prior to the previous commit, those distros would have had 'apply_network' called with the openstack provided ENI file. But after this change they will have apply_network_config called by cloudinit's main. c.) add network_state_to_eni for converting net config to eni it supports the not-actually-correct 'hwaddress' field in ENI
Diffstat (limited to 'cloudinit/distros/__init__.py')
-rw-r--r--cloudinit/distros/__init__.py28
1 files changed, 26 insertions, 2 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index 14b500f8..40af8802 100644
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -32,6 +32,8 @@ import stat
from cloudinit import importer
from cloudinit import log as logging
from cloudinit import net
+from cloudinit.net import eni
+from cloudinit.net import network_state
from cloudinit import ssh_util
from cloudinit import type_utils
from cloudinit import util
@@ -138,9 +140,31 @@ class Distro(object):
return self._bring_up_interfaces(dev_names)
return False
+ def _apply_network_from_network_config(self, netconfig, bring_up=True):
+ distro = self.__class__
+ LOG.warn("apply_network_config is not currently implemented "
+ "for distribution '%s'. Attempting to use apply_network",
+ distro)
+ header = '\n'.join([
+ "# Converted from network_config for distro %s" % distro,
+ "# Implmentation of _write_network_config is needed."
+ ])
+ ns = network_state.parse_net_config_data(netconfig)
+ contents = eni.network_state_to_eni(
+ ns, header=header, render_hwaddress=True)
+ return self.apply_network(contents, bring_up=bring_up)
+
def apply_network_config(self, netconfig, bring_up=False):
- # Write it out
- dev_names = self._write_network_config(netconfig)
+ # apply network config netconfig
+ # This method is preferred to apply_network which only takes
+ # a much less complete network config format (interfaces(5)).
+ try:
+ dev_names = self._write_network_config(netconfig)
+ 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)