summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-09-28 14:21:02 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-09-28 14:21:02 -0700
commit72fc1f762e5c5df563380e9ed90bfaba131e811b (patch)
tree2420fd4938324bedc739ec4e1573a4211a12a02f /cloudinit
parent5233b6edb70702476463b47c06cb02b3c7f74c51 (diff)
parentd285a0463b6d16487eb5859373ccfd27eaec8b90 (diff)
downloadvyos-cloud-init-72fc1f762e5c5df563380e9ed90bfaba131e811b.tar.gz
vyos-cloud-init-72fc1f762e5c5df563380e9ed90bfaba131e811b.zip
Sync with head and fix conflicts.
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/distros/__init__.py5
-rw-r--r--cloudinit/safeyaml.py32
-rw-r--r--cloudinit/sources/DataSourceMAAS.py2
-rw-r--r--cloudinit/util.py3
4 files changed, 38 insertions, 4 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index 6b458d06..21efe8d9 100644
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -83,7 +83,7 @@ class Distro(object):
return arch
def _get_arch_package_mirror_info(self, arch=None):
- mirror_info = self.get_option("package_mirrors", None)
+ mirror_info = self.get_option("package_mirrors", [])
if arch == None:
arch = self.get_primary_arch()
return _get_arch_package_mirror_info(mirror_info, arch)
@@ -93,7 +93,6 @@ class Distro(object):
# this resolves the package_mirrors config option
# down to a single dict of {mirror_name: mirror_url}
arch_info = self._get_arch_package_mirror_info(arch)
-
return _get_package_mirror_info(availability_zone=availability_zone,
mirror_info=arch_info)
@@ -356,6 +355,8 @@ def _get_package_mirror_info(mirror_info, availability_zone=None,
# given a arch specific 'mirror_info' entry (from package_mirrors)
# search through the 'search' entries, and fallback appropriately
# return a dict with only {name: mirror} entries.
+ if not mirror_info:
+ mirror_info = {}
ec2_az_re = ("^[a-z][a-z]-(%s)-[1-9][0-9]*[a-z]$" %
"north|northeast|east|southeast|south|southwest|west|northwest")
diff --git a/cloudinit/safeyaml.py b/cloudinit/safeyaml.py
new file mode 100644
index 00000000..eba5d056
--- /dev/null
+++ b/cloudinit/safeyaml.py
@@ -0,0 +1,32 @@
+# vi: ts=4 expandtab
+#
+# Copyright (C) 2012 Canonical Ltd.
+#
+# 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
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import yaml
+
+
+class _CustomSafeLoader(yaml.SafeLoader):
+ def construct_python_unicode(self, node):
+ return self.construct_scalar(node)
+
+_CustomSafeLoader.add_constructor(
+ u'tag:yaml.org,2002:python/unicode',
+ _CustomSafeLoader.construct_python_unicode)
+
+
+def load(blob):
+ return(yaml.load(blob, Loader=_CustomSafeLoader))
diff --git a/cloudinit/sources/DataSourceMAAS.py b/cloudinit/sources/DataSourceMAAS.py
index 581e9a4b..c172150b 100644
--- a/cloudinit/sources/DataSourceMAAS.py
+++ b/cloudinit/sources/DataSourceMAAS.py
@@ -338,7 +338,7 @@ if __name__ == "__main__":
if args.config:
import yaml
with open(args.config) as fp:
- cfg = yaml.safe_load(fp)
+ cfg = util.load_yaml(fp.read())
if 'datasource' in cfg:
cfg = cfg['datasource']['MAAS']
for key in creds.keys():
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 184b37a4..f5a7ac12 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -50,6 +50,7 @@ import yaml
from cloudinit import importer
from cloudinit import log as logging
+from cloudinit import safeyaml
from cloudinit import url_helper as uhelp
from cloudinit.settings import (CFG_BUILTIN)
@@ -642,7 +643,7 @@ def load_yaml(blob, default=None, allowed=(dict,)):
LOG.debug(("Attempting to load yaml from string "
"of length %s with allowed root types %s"),
len(blob), allowed)
- converted = yaml.safe_load(blob)
+ converted = safeyaml.load(blob)
if not isinstance(converted, allowed):
# Yes this will just be caught, but thats ok for now...
raise TypeError(("Yaml load allows %s root types,"