summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/config/cc_seed_random.py47
-rw-r--r--cloudinit/distros/freebsd.py2
-rw-r--r--cloudinit/netinfo.py17
-rw-r--r--cloudinit/sources/DataSourceAltCloud.py6
-rw-r--r--cloudinit/sources/DataSourceConfigDrive.py2
-rw-r--r--cloudinit/sources/DataSourceOpenStack.py12
-rw-r--r--cloudinit/sources/DataSourceSmartOS.py11
-rw-r--r--cloudinit/sources/helpers/__init__.py1
-rw-r--r--cloudinit/sources/helpers/openstack.py21
9 files changed, 84 insertions, 35 deletions
diff --git a/cloudinit/config/cc_seed_random.py b/cloudinit/config/cc_seed_random.py
index 22a31f29..599280f6 100644
--- a/cloudinit/config/cc_seed_random.py
+++ b/cloudinit/config/cc_seed_random.py
@@ -1,8 +1,11 @@
# vi: ts=4 expandtab
#
# Copyright (C) 2013 Yahoo! Inc.
+# Copyright (C) 2014 Canonical, Ltd
#
# Author: Joshua Harlow <harlowja@yahoo-inc.com>
+# Author: Dustin Kirkland <kirkland@ubuntu.com>
+# Author: Scott Moser <scott.moser@canonical.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3, as
@@ -20,9 +23,11 @@ import base64
from StringIO import StringIO
from cloudinit.settings import PER_INSTANCE
+from cloudinit import log as logging
from cloudinit import util
frequency = PER_INSTANCE
+LOG = logging.getLogger(__name__)
def _decode(data, encoding=None):
@@ -38,24 +43,48 @@ def _decode(data, encoding=None):
raise IOError("Unknown random_seed encoding: %s" % (encoding))
-def handle(name, cfg, cloud, log, _args):
- if not cfg or "random_seed" not in cfg:
- log.debug(("Skipping module named %s, "
- "no 'random_seed' configuration found"), name)
+def handle_random_seed_command(command, required):
+ if not command and required:
+ raise ValueError("no command found but required=true")
+ elif not command:
+ LOG.debug("no command provided")
return
- my_cfg = cfg['random_seed']
- seed_path = my_cfg.get('file', '/dev/urandom')
+ cmd = command[0]
+ if not util.which(cmd):
+ if required:
+ raise ValueError("command '%s' not found but required=true", cmd)
+ else:
+ LOG.debug("command '%s' not found for seed_command", cmd)
+ return
+ util.subp(command)
+
+
+def handle(name, cfg, cloud, log, _args):
+ mycfg = cfg.get('random_seed', {})
+ seed_path = mycfg.get('file', '/dev/urandom')
+ seed_data = mycfg.get('data', '')
+
seed_buf = StringIO()
- seed_buf.write(_decode(my_cfg.get('data', ''),
- encoding=my_cfg.get('encoding')))
+ if seed_data:
+ seed_buf.write(_decode(seed_data, encoding=mycfg.get('encoding')))
+ # 'random_seed' is set up by Azure datasource, and comes already in
+ # openstack meta_data.json
metadata = cloud.datasource.metadata
if metadata and 'random_seed' in metadata:
seed_buf.write(metadata['random_seed'])
seed_data = seed_buf.getvalue()
if len(seed_data):
- log.debug("%s: adding %s bytes of random seed entrophy to %s", name,
+ log.debug("%s: adding %s bytes of random seed entropy to %s", name,
len(seed_data), seed_path)
util.append_file(seed_path, seed_data)
+
+ command = mycfg.get('command', ['pollinate', '-q'])
+ req = mycfg.get('command_required', False)
+ try:
+ handle_random_seed_command(command=command, required=req)
+ except ValueError as e:
+ log.warn("handling random command [%s] failed: %s", command, e)
+ raise e
diff --git a/cloudinit/distros/freebsd.py b/cloudinit/distros/freebsd.py
index afb502c9..d98f9578 100644
--- a/cloudinit/distros/freebsd.py
+++ b/cloudinit/distros/freebsd.py
@@ -79,7 +79,7 @@ class Distro(distros.Distro):
return val
def _read_system_hostname(self):
- sys_hostname = self._read_hostname()
+ sys_hostname = self._read_hostname(filename=None)
return ('rc.conf', sys_hostname)
def _read_hostname(self, filename, default=None):
diff --git a/cloudinit/netinfo.py b/cloudinit/netinfo.py
index ac3c011f..30b6f3b3 100644
--- a/cloudinit/netinfo.py
+++ b/cloudinit/netinfo.py
@@ -52,18 +52,23 @@ def netdev_info(empty=""):
fieldpost = "6"
for i in range(len(toks)):
- if toks[i] == "hwaddr" or toks[i] == "ether":
- try:
- devs[curdev]["hwaddr"] = toks[i + 1]
- except IndexError:
- pass
+ # older net-tools (ubuntu) show 'inet addr:xx.yy',
+ # newer (freebsd and fedora) show 'inet xx.yy'
+ # just skip this 'inet' entry. (LP: #1285185)
+ try:
+ if (toks[i] in ("inet", "inet6") and
+ toks[i + 1].startswith("addr:")):
+ continue
+ except IndexError:
+ pass
# Couple the different items we're interested in with the correct
# field since FreeBSD/CentOS/Fedora differ in the output.
ifconfigfields = {
"addr:": "addr", "inet": "addr",
"bcast:": "bcast", "broadcast": "bcast",
- "mask:": "mask", "netmask": "mask"
+ "mask:": "mask", "netmask": "mask",
+ "hwaddr": "hwaddr", "ether": "hwaddr",
}
for origfield, field in ifconfigfields.items():
target = "%s%s" % (field, fieldpost)
diff --git a/cloudinit/sources/DataSourceAltCloud.py b/cloudinit/sources/DataSourceAltCloud.py
index a834f8eb..1e913a6e 100644
--- a/cloudinit/sources/DataSourceAltCloud.py
+++ b/cloudinit/sources/DataSourceAltCloud.py
@@ -115,6 +115,12 @@ class DataSourceAltCloud(sources.DataSource):
'''
+ uname_arch = os.uname()[4]
+ if uname_arch.startswith("arm") or uname_arch == "aarch64":
+ # Disabling because dmidecode in CMD_DMI_SYSTEM crashes kvm process
+ LOG.debug("Disabling AltCloud datasource on arm (LP: #1243287)")
+ return 'UNKNOWN'
+
cmd = CMD_DMI_SYSTEM
try:
(cmd_out, _err) = util.subp(cmd)
diff --git a/cloudinit/sources/DataSourceConfigDrive.py b/cloudinit/sources/DataSourceConfigDrive.py
index 142e0eb8..0c35f83a 100644
--- a/cloudinit/sources/DataSourceConfigDrive.py
+++ b/cloudinit/sources/DataSourceConfigDrive.py
@@ -181,7 +181,7 @@ def get_previous_iid(paths):
# hasn't declared itself found.
fname = os.path.join(paths.get_cpath('data'), 'instance-id')
try:
- return util.load_file(fname)
+ return util.load_file(fname).rstrip("\n")
except IOError:
return None
diff --git a/cloudinit/sources/DataSourceOpenStack.py b/cloudinit/sources/DataSourceOpenStack.py
index 72ec8075..0970d07b 100644
--- a/cloudinit/sources/DataSourceOpenStack.py
+++ b/cloudinit/sources/DataSourceOpenStack.py
@@ -88,11 +88,11 @@ class DataSourceOpenStack(openstack.SourceMixin, sources.DataSource):
md_urls = []
url2base = {}
for url in urls:
- md_url = url_helper.combine_url(url, 'openstack',
- openstack.OS_LATEST,
- 'meta_data.json')
- md_urls.append(md_url)
- url2base[md_url] = url
+ for version in openstack.OS_VERSIONS + (openstack.OS_LATEST,):
+ md_url = url_helper.combine_url(url, 'openstack',
+ version, 'meta_data.json')
+ md_urls.append(md_url)
+ url2base[md_url] = url
(max_wait, timeout) = self._get_url_settings()
start_time = time.time()
@@ -120,7 +120,7 @@ class DataSourceOpenStack(openstack.SourceMixin, sources.DataSource):
read_metadata_service,
args=[self.metadata_address],
kwargs={'ssl_details': self.ssl_details,
- 'version': openstack.OS_LATEST})
+ 'version': openstack.OS_HAVANA})
except openstack.NonReadable:
return False
except (openstack.BrokenMetadata, IOError):
diff --git a/cloudinit/sources/DataSourceSmartOS.py b/cloudinit/sources/DataSourceSmartOS.py
index 8d4a16e6..7c1eb09a 100644
--- a/cloudinit/sources/DataSourceSmartOS.py
+++ b/cloudinit/sources/DataSourceSmartOS.py
@@ -174,6 +174,12 @@ class DataSourceSmartOS(sources.DataSource):
LOG.debug("Host does not appear to be on SmartOS")
return False
+ uname_arch = os.uname()[4]
+ if uname_arch.startswith("arm") or uname_arch == "aarch64":
+ # Disabling because dmidcode in dmi_data() crashes kvm process
+ LOG.debug("Disabling SmartOS datasource on arm (LP: #1243287)")
+ return False
+
dmi_info = dmi_data()
if dmi_info is False:
LOG.debug("No dmidata utility found")
@@ -203,7 +209,7 @@ class DataSourceSmartOS(sources.DataSource):
# executed. It may be of any format that would be considered
# executable in the guest instance.
#
- # We write 'user-script' and 'operator-script' into the
+ # We write 'user-script' and 'operator-script' into the
# instance/data directory. The default vendor-data then handles
# executing them later.
data_d = os.path.join(self.paths.get_cpath(), 'instances',
@@ -238,7 +244,8 @@ class DataSourceSmartOS(sources.DataSource):
md['vendor-data'] = BUILTIN_VENDOR_DATA % {
'user_script': user_script,
'operator_script': operator_script,
- 'per_boot_d': os.path.join(self.paths.get_cpath("scripts"), 'per-boot'),
+ 'per_boot_d': os.path.join(self.paths.get_cpath("scripts"),
+ 'per-boot'),
}
self.metadata = util.mergemanydict([md, self.metadata])
diff --git a/cloudinit/sources/helpers/__init__.py b/cloudinit/sources/helpers/__init__.py
index 2cf99ec8..386225d5 100644
--- a/cloudinit/sources/helpers/__init__.py
+++ b/cloudinit/sources/helpers/__init__.py
@@ -11,4 +11,3 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
diff --git a/cloudinit/sources/helpers/openstack.py b/cloudinit/sources/helpers/openstack.py
index a17148d3..0fac0335 100644
--- a/cloudinit/sources/helpers/openstack.py
+++ b/cloudinit/sources/helpers/openstack.py
@@ -44,12 +44,15 @@ KEY_COPIES = (
('local-hostname', 'hostname', False),
('instance-id', 'uuid', True),
)
+OS_LATEST = 'latest'
+OS_FOLSOM = '2012-08-10'
+OS_GRIZZLY = '2013-04-04'
+OS_HAVANA = '2013-10-17'
OS_VERSIONS = (
- '2012-08-10', # folsom
- '2013-04-04', # grizzly
- '2013-10-17', # havana
+ OS_FOLSOM,
+ OS_GRIZZLY,
+ OS_HAVANA,
)
-OS_LATEST = 'latest'
class NonReadable(IOError):
@@ -176,12 +179,12 @@ class BaseReader(object):
potential_version)
if self._path_exists(path):
if potential_version != version:
- LOG.warn("Version '%s' not available, attempting to use"
- " version '%s' instead", version,
- potential_version)
+ LOG.debug("Version '%s' not available, attempting to use"
+ " version '%s' instead", version,
+ potential_version)
return potential_version
- LOG.warn("Version '%s' not available, attempting to use '%s'"
- " instead", version, OS_LATEST)
+ LOG.debug("Version '%s' not available, attempting to use '%s'"
+ " instead", version, OS_LATEST)
return OS_LATEST
def read_v2(self, version=None):