summaryrefslogtreecommitdiff
path: root/cloudinit/sources/DataSourceOpenNebula.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2015-01-26 14:48:23 -0500
committerBarry Warsaw <barry@python.org>2015-01-26 14:48:23 -0500
commit18b35de06432869a9d859e2978e7e9567eba66a2 (patch)
tree8627efd630cecb28e0a55a7953953e8c2673cadc /cloudinit/sources/DataSourceOpenNebula.py
parentde5974fe93dd717e0c7ba6de17db3192cc258cff (diff)
downloadvyos-cloud-init-18b35de06432869a9d859e2978e7e9567eba66a2.tar.gz
vyos-cloud-init-18b35de06432869a9d859e2978e7e9567eba66a2.zip
Another handling of b64decode.
Also, restore Python 2 compatibility.
Diffstat (limited to 'cloudinit/sources/DataSourceOpenNebula.py')
-rw-r--r--cloudinit/sources/DataSourceOpenNebula.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/cloudinit/sources/DataSourceOpenNebula.py b/cloudinit/sources/DataSourceOpenNebula.py
index 691b39f8..6da569ec 100644
--- a/cloudinit/sources/DataSourceOpenNebula.py
+++ b/cloudinit/sources/DataSourceOpenNebula.py
@@ -25,6 +25,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import base64
+import codecs
import os
import pwd
import re
@@ -34,6 +35,8 @@ from cloudinit import log as logging
from cloudinit import sources
from cloudinit import util
+import six
+
LOG = logging.getLogger(__name__)
DEFAULT_IID = "iid-dsopennebula"
@@ -43,6 +46,12 @@ CONTEXT_DISK_FILES = ["context.sh"]
VALID_DSMODES = ("local", "net", "disabled")
+def utf8_open(path):
+ if six.PY3:
+ return open(path, 'r', encoding='utf-8')
+ return codecs.open(path, 'r', encoding='utf-8')
+
+
class DataSourceOpenNebula(sources.DataSource):
def __init__(self, sys_cfg, distro, paths):
sources.DataSource.__init__(self, sys_cfg, distro, paths)
@@ -380,7 +389,7 @@ def read_context_disk_dir(source_dir, asuser=None):
"does not exist", asuser)
try:
path = os.path.join(source_dir, 'context.sh')
- with open(path, 'r', encoding='utf-8') as f:
+ with utf8_open(path) as f:
content = f.read().strip()
context = parse_shell_config(content, asuser=asuser)