diff options
author | Scott Moser <smoser@ubuntu.com> | 2012-02-17 12:14:48 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2012-02-17 12:14:48 -0500 |
commit | 02aea2383e0ea020fd6c2e74ffcaad8983820a9d (patch) | |
tree | b8e950f788136a1028124827c78f48851e5d78a0 /cloudinit | |
parent | 979bee2c9ee477ea495c5df4f420d5ca2123a840 (diff) | |
download | vyos-cloud-init-02aea2383e0ea020fd6c2e74ffcaad8983820a9d.tar.gz vyos-cloud-init-02aea2383e0ea020fd6c2e74ffcaad8983820a9d.zip |
support reading network interface config from DataSourceNoCloud
document usage of DataSourceNoCloud from vfat or iso disk.
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/DataSourceNoCloud.py | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/cloudinit/DataSourceNoCloud.py b/cloudinit/DataSourceNoCloud.py index 6c744b82..1e28edbd 100644 --- a/cloudinit/DataSourceNoCloud.py +++ b/cloudinit/DataSourceNoCloud.py @@ -24,6 +24,7 @@ from cloudinit import seeddir as base_seeddir from cloudinit import log import cloudinit.util as util import errno +import subprocess class DataSourceNoCloud(DataSource.DataSource): @@ -31,6 +32,7 @@ class DataSourceNoCloud(DataSource.DataSource): userdata = None userdata_raw = None supported_seed_starts = ("/", "file://") + dsmode = "local" seed = None cmdline_id = "ds=nocloud" seeddir = base_seeddir + '/nocloud' @@ -42,7 +44,7 @@ class DataSourceNoCloud(DataSource.DataSource): def get_data(self): defaults = { - "instance-id": "nocloud" + "instance-id": "nocloud", "dsmode": "net" } found = [] @@ -84,14 +86,20 @@ class DataSourceNoCloud(DataSource.DataSource): except OSError, e: if e.errno != errno.ENOENT: raise + except util.mountFailedError: + log.warn("Failed to mount %s when looking for seed" % dev) # there was no indication on kernel cmdline or data # in the seeddir suggesting this handler should be used. if len(found) == 0: return False + seeded_interfaces = 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 + # on the command line, ie: ds=nocloud;s=http://bit.ly/abcdefg if "seedfrom" in md: seedfrom = md["seedfrom"] seedfound = False @@ -104,6 +112,9 @@ class DataSourceNoCloud(DataSource.DataSource): (seedfrom, self.__class__)) return False + if 'network-interfaces' in md: + seeded_interfaces = self.dsmode + # this could throw errors, but the user told us to do it # so if errors are raised, let them raise (md_seed, ud) = util.read_seeded(seedfrom, timeout=None) @@ -114,10 +125,35 @@ class DataSourceNoCloud(DataSource.DataSource): found.append(seedfrom) md = util.mergedict(md, 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 md and + (self.dsmode in ("local", seeded_interfaces))): + log.info("updating network interfaces from nocloud") + + util.write_file("/etc/network/interfaces", + md['network-interfaces']) + try: + (out, err) = util.subp(['ifup', '--all']) + if len(out) or len(err): + log.warn("ifup --all had stderr: %s" % err) + + except subprocess.CalledProcessError as exc: + log.warn("ifup --all failed: %s" % (exc.output[1])) + self.seed = ",".join(found) self.metadata = md self.userdata_raw = ud - return True + + if md['dsmode'] == self.dsmode: + return True + + log.debug("%s: not claiming datasource, dsmode=%s" % + (self, md['dsmode'])) + return False # returns true or false indicating if cmdline indicated @@ -166,6 +202,7 @@ class DataSourceNoCloudNet(DataSourceNoCloud): cmdline_id = "ds=nocloud-net" supported_seed_starts = ("http://", "https://", "ftp://") seeddir = base_seeddir + '/nocloud-net' + dsmode = "net" datasources = ( |