summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2016-03-10 21:43:46 -0500
committerScott Moser <smoser@ubuntu.com>2016-03-10 21:43:46 -0500
commit781ded8127deefb49a8806e49bdb7bb6e4d4b245 (patch)
treeff9a951f01a94ba796d8d849a14372aad2d80dff /cloudinit
parent098d05b2f1253ba0808772851a1a8e85cb0108a9 (diff)
downloadvyos-cloud-init-781ded8127deefb49a8806e49bdb7bb6e4d4b245.tar.gz
vyos-cloud-init-781ded8127deefb49a8806e49bdb7bb6e4d4b245.zip
commit planned implementation of datasourcenocloud
this adds the consumption of 'network-config' to the datasourcenocloud. There is an implementation of the network rendering taht is untested in distros/debian.
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/distros/__init__.py11
-rw-r--r--cloudinit/distros/debian.py10
-rw-r--r--cloudinit/sources/DataSourceNoCloud.py49
3 files changed, 53 insertions, 17 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index a73acae5..461253a7 100644
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -75,6 +75,9 @@ class Distro(object):
# to write this blob out in a distro format
raise NotImplementedError()
+ def _write_network_config(self, settings):
+ raise NotImplementedError()
+
def _find_tz_file(self, tz):
tz_file = os.path.join(self.tz_zone_dir, str(tz))
if not os.path.isfile(tz_file):
@@ -132,6 +135,14 @@ class Distro(object):
return self._bring_up_interfaces(dev_names)
return False
+ def apply_network_config(self, netconfig, bring_up=True):
+ # Write it out
+ dev_names = self._write_network_config(netconfig)
+ # Now try to bring them up
+ if bring_up:
+ return self._bring_up_interfaces(dev_names)
+ return False
+
@abc.abstractmethod
def apply_locale(self, locale, out_fn=None):
raise NotImplementedError()
diff --git a/cloudinit/distros/debian.py b/cloudinit/distros/debian.py
index db5890b1..89d8d28e 100644
--- a/cloudinit/distros/debian.py
+++ b/cloudinit/distros/debian.py
@@ -26,6 +26,8 @@ from cloudinit import distros
from cloudinit import helpers
from cloudinit import log as logging
from cloudinit import util
+from cloudinit import net
+from cloudinit.net import network_state
from cloudinit.distros.parsers.hostname import HostnameConf
@@ -76,6 +78,14 @@ class Distro(distros.Distro):
util.write_file(self.network_conf_fn, settings)
return ['all']
+ def _write_network_config(self, netconfig):
+ # TODO: THIS IS NOT TESTED
+ state = network_state.NetworkState()
+ state.load(netconfig)
+ state.parse_config()
+ net.render_network_state("/", state)
+ return ['all']
+
def _bring_up_interfaces(self, device_names):
use_all = False
for d in device_names:
diff --git a/cloudinit/sources/DataSourceNoCloud.py b/cloudinit/sources/DataSourceNoCloud.py
index 4cad6877..e00210e7 100644
--- a/cloudinit/sources/DataSourceNoCloud.py
+++ b/cloudinit/sources/DataSourceNoCloud.py
@@ -50,21 +50,22 @@ class DataSourceNoCloud(sources.DataSource):
}
found = []
- mydata = {'meta-data': {}, 'user-data': "", 'vendor-data': ""}
+ mydata = {'meta-data': {}, 'user-data': "", 'vendor-data': "",
+ 'network-config': {}}
try:
# Parse the kernel command line, getting data passed in
md = {}
if parse_cmdline_data(self.cmdline_id, md):
found.append("cmdline")
- mydata['meta-data'].update(md)
+ mydata = _merge_new_seed({'meta-data': md})
except:
util.logexc(LOG, "Unable to parse command line data")
return False
# Check to see if the seed dir has data.
pp2d_kwargs = {'required': ['user-data', 'meta-data'],
- 'optional': ['vendor-data']}
+ 'optional': ['vendor-data', 'network-config']}
try:
seeded = util.pathprefix2dict(self.seed_dir, **pp2d_kwargs)
@@ -141,8 +142,7 @@ class DataSourceNoCloud(sources.DataSource):
if len(found) == 0:
return False
- seeded_interfaces = None
-
+ seeded_network = None
# The special argument "seedfrom" indicates we should
# attempt to seed the userdata / metadata from its value
# its primarily value is in allowing the user to type less
@@ -158,8 +158,9 @@ class DataSourceNoCloud(sources.DataSource):
LOG.debug("Seed from %s not supported by %s", seedfrom, self)
return False
- if 'network-interfaces' in mydata['meta-data']:
- seeded_interfaces = self.dsmode
+ if (mydata['meta-data'].get('network-interfaces') or
+ mydata.get('network-config')):
+ seeded_network = self.dsmode
# This could throw errors, but the user told us to do it
# so if errors are raised, let them raise
@@ -176,15 +177,25 @@ class DataSourceNoCloud(sources.DataSource):
mydata['meta-data'] = util.mergemanydict([mydata['meta-data'],
defaults])
- # Update the network-interfaces if metadata had 'network-interfaces'
- # entry and this is the local datasource, or 'seedfrom' was used
- # and the source of the seed was self.dsmode
- # ('local' for NoCloud, 'net' for NoCloudNet')
- if ('network-interfaces' in mydata['meta-data'] and
- (self.dsmode in ("local", seeded_interfaces))):
- LOG.debug("Updating network interfaces from %s", self)
- self.distro.apply_network(
- mydata['meta-data']['network-interfaces'])
+ netdata = {'format': None, 'data': None}
+ if mydata['meta-data'].get('network-interfaces'):
+ netdata['format'] = 'interfaces'
+ netdata['data'] = mydata['meta-data']['network-interfaces']
+ elif mydata.get('network-config'):
+ netdata['format'] = 'network-config'
+ netdata['data'] = mydata['network-config']
+
+ # if this is the local datasource or 'seedfrom' was used
+ # and the source of the seed was self.dsmode.
+ # Then see if there is network config to apply.
+ if self.dsmode in ("local", seeded_network):
+ if mydata['meta-data'].get('network-interfaces'):
+ LOG.debug("Updating network interfaces from %s", self)
+ self.distro.apply_network(
+ mydata['meta-data']['network-interfaces'])
+ elif mydata.get('network-config'):
+ LOG.debug("Updating network config from %s", self)
+ self.distro.apply_network_config(mydata['network-config'])
if mydata['meta-data']['dsmode'] == self.dsmode:
self.seed = ",".join(found)
@@ -246,7 +257,11 @@ def _merge_new_seed(cur, seeded):
ret = cur.copy()
ret['meta-data'] = util.mergemanydict([cur['meta-data'],
util.load_yaml(seeded['meta-data'])])
- ret['user-data'] = seeded['user-data']
+ if seeded.get('network-config'):
+ ret['network-config'] = util.load_yaml(seeded['network-config'])
+
+ if 'user-data' in seeded:
+ ret['user-data'] = seeded['user-data']
if 'vendor-data' in seeded:
ret['vendor-data'] = seeded['vendor-data']
return ret