summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2016-03-22 03:50:28 -0400
committerScott Moser <smoser@ubuntu.com>2016-03-22 03:50:28 -0400
commit9c0a2abc8d2c0e390745ddb163f5eae07b20d61d (patch)
tree910459878f970a42d9895758a5d59275916953ba /cloudinit
parent6ce134c1868478345471ba9166f1523f7d9bf19d (diff)
downloadvyos-cloud-init-9c0a2abc8d2c0e390745ddb163f5eae07b20d61d.tar.gz
vyos-cloud-init-9c0a2abc8d2c0e390745ddb163f5eae07b20d61d.zip
add code to invoke networking config
there is no data source that has a populated network_config() so at this point this doesn't do anything.
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/distros/__init__.py2
-rw-r--r--cloudinit/net/__init__.py17
-rw-r--r--cloudinit/sources/__init__.py4
-rw-r--r--cloudinit/stages.py24
4 files changed, 46 insertions, 1 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index 74b484a7..418421b9 100644
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -135,7 +135,7 @@ class Distro(object):
return self._bring_up_interfaces(dev_names)
return False
- def apply_network_config(self, netconfig, bring_up=True):
+ def apply_network_config(self, netconfig, bring_up=False):
# Write it out
dev_names = self._write_network_config(netconfig)
# Now try to bring them up
diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py
index 3cf99604..799cb97e 100644
--- a/cloudinit/net/__init__.py
+++ b/cloudinit/net/__init__.py
@@ -434,4 +434,21 @@ def render_network_state(target, network_state):
with open(netrules, 'w+') as f:
f.write(render_persistent_net(network_state))
+
+def is_disabled_cfg(cfg):
+ if not cfg or not isinstance(cfg, dict):
+ return False
+ return cfg.get('config') == "disabled"
+
+
+def generate_fallback_config():
+ # FIXME: add implementation here
+ return None
+
+
+def read_kernel_cmdline_config():
+ # FIXME: add implementation here
+ return None
+
+
# vi: ts=4 expandtab syntax=python
diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py
index 28540a7b..c63464b2 100644
--- a/cloudinit/sources/__init__.py
+++ b/cloudinit/sources/__init__.py
@@ -221,6 +221,10 @@ class DataSource(object):
# quickly (local check only) if self.instance_id is still
return False
+ @property
+ def network_config(self):
+ return None
+
def normalize_pubkey_data(pubkey_data):
keys = []
diff --git a/cloudinit/stages.py b/cloudinit/stages.py
index c230ec0d..8e681e29 100644
--- a/cloudinit/stages.py
+++ b/cloudinit/stages.py
@@ -43,6 +43,7 @@ from cloudinit import distros
from cloudinit import helpers
from cloudinit import importer
from cloudinit import log as logging
+from cloudinit import net
from cloudinit import sources
from cloudinit import type_utils
from cloudinit import util
@@ -567,6 +568,29 @@ class Init(object):
# Run the handlers
self._do_handlers(user_data_msg, c_handlers_list, frequency)
+ def _find_networking_config(self):
+ cmdline_cfg = ('cmdline', net.read_kernel_cmdline_config())
+ dscfg = ('ds', None)
+ if self.datasource and hasattr(self.datasource, 'network_config'):
+ dscfg = ('ds', self.datasource.network_config)
+ sys_cfg = ('system_cfg', self.cfg.get('network'))
+
+ for loc, ncfg in (cmdline_cfg, dscfg, sys_cfg):
+ if net.is_disabled_cfg(ncfg):
+ LOG.debug("network config disabled by %s", loc)
+ return None
+ if ncfg:
+ return ncfg
+ return net.generate_fallback_config()
+
+ def apply_network_config(self):
+ netcfg = self._find_networking_config()
+ if netcfg is None:
+ LOG.info("network config is disabled")
+ return
+
+ return self.distro.apply_network_config(netcfg)
+
class Modules(object):
def __init__(self, init, cfg_files=None, reporter=None):