summaryrefslogtreecommitdiff
path: root/cloudinit/sources/DataSourceOpenNebula.py
diff options
context:
space:
mode:
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)