summaryrefslogtreecommitdiff
path: root/azurelinuxagent/utils
diff options
context:
space:
mode:
Diffstat (limited to 'azurelinuxagent/utils')
-rw-r--r--azurelinuxagent/utils/__init__.py2
-rw-r--r--azurelinuxagent/utils/fileutil.py2
-rw-r--r--azurelinuxagent/utils/osutil.py2
-rw-r--r--azurelinuxagent/utils/restutil.py6
-rw-r--r--azurelinuxagent/utils/shellutil.py22
-rw-r--r--azurelinuxagent/utils/textutil.py14
6 files changed, 26 insertions, 22 deletions
diff --git a/azurelinuxagent/utils/__init__.py b/azurelinuxagent/utils/__init__.py
index 4b2b9e1..d9b82f5 100644
--- a/azurelinuxagent/utils/__init__.py
+++ b/azurelinuxagent/utils/__init__.py
@@ -1,4 +1,4 @@
-# Windows Azure Linux Agent
+# Microsoft Azure Linux Agent
#
# Copyright 2014 Microsoft Corporation
#
diff --git a/azurelinuxagent/utils/fileutil.py b/azurelinuxagent/utils/fileutil.py
index 5e7fecf..08592bc 100644
--- a/azurelinuxagent/utils/fileutil.py
+++ b/azurelinuxagent/utils/fileutil.py
@@ -1,4 +1,4 @@
-# Windows Azure Linux Agent
+# Microsoft Azure Linux Agent
#
# Copyright 2014 Microsoft Corporation
#
diff --git a/azurelinuxagent/utils/osutil.py b/azurelinuxagent/utils/osutil.py
index 756400c..9de47e7 100644
--- a/azurelinuxagent/utils/osutil.py
+++ b/azurelinuxagent/utils/osutil.py
@@ -1,4 +1,4 @@
-# Windows Azure Linux Agent
+# Microsoft Azure Linux Agent
#
# Copyright 2014 Microsoft Corporation
#
diff --git a/azurelinuxagent/utils/restutil.py b/azurelinuxagent/utils/restutil.py
index 1015f71..2acfa57 100644
--- a/azurelinuxagent/utils/restutil.py
+++ b/azurelinuxagent/utils/restutil.py
@@ -1,4 +1,4 @@
-# Windows Azure Linux Agent
+# Microsoft Azure Linux Agent
#
# Copyright 2014 Microsoft Corporation
#
@@ -66,7 +66,7 @@ def _http_request(method, host, rel_uri, port=None, data=None, secure=False,
#If proxy is used, full url is needed.
url = "https://{0}:{1}{2}".format(host, port, rel_uri)
else:
- conn = httpclient.HTTPSConnection(host, port)
+ conn = httpclient.HTTPSConnection(host, port, timeout=10)
url = rel_uri
else:
port = 80 if port is None else port
@@ -75,7 +75,7 @@ def _http_request(method, host, rel_uri, port=None, data=None, secure=False,
#If proxy is used, full url is needed.
url = "http://{0}:{1}{2}".format(host, port, rel_uri)
else:
- conn = httpclient.HTTPConnection(host, port)
+ conn = httpclient.HTTPConnection(host, port, timeout=10)
url = rel_uri
if headers == None:
conn.request(method, url, data)
diff --git a/azurelinuxagent/utils/shellutil.py b/azurelinuxagent/utils/shellutil.py
index f4305d9..372c78a 100644
--- a/azurelinuxagent/utils/shellutil.py
+++ b/azurelinuxagent/utils/shellutil.py
@@ -1,4 +1,4 @@
-# Windows Azure Linux Agent
+# Microsoft Azure Linux Agent
#
# Copyright 2014 Microsoft Corporation
#
@@ -65,21 +65,25 @@ def run(cmd, chk_err=True):
retcode,out=run_get_output(cmd,chk_err)
return retcode
-def run_get_output(cmd, chk_err=True):
+def run_get_output(cmd, chk_err=True, log_cmd=True):
"""
Wrapper for subprocess.check_output.
Execute 'cmd'. Returns return code and STDOUT, trapping expected exceptions.
Reports exceptions to Error if chk_err parameter is True
"""
- logger.verb("run cmd '{0}'", cmd)
+ if log_cmd:
+ logger.verb(u"run cmd '{0}'", cmd)
try:
output=subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
+ output = text(output, encoding='utf-8', errors="backslashreplace")
except subprocess.CalledProcessError as e :
- if chk_err :
- logger.error("run cmd '{0}' failed", e.cmd)
- logger.error("Error Code:{0}", e.returncode)
- logger.error("Result:{0}", e.output[:-1].decode('latin-1'))
- return e.returncode, e.output.decode('latin-1')
- return 0, text(output, encoding="utf-8")
+ output = text(e.output, encoding='utf-8', errors="backslashreplace")
+ if chk_err:
+ if log_cmd:
+ logger.error(u"run cmd '{0}' failed", e.cmd)
+ logger.error(u"Error Code:{0}", e.returncode)
+ logger.error(u"Result:{0}", output)
+ return e.returncode, output
+ return 0, output
#End shell command util functions
diff --git a/azurelinuxagent/utils/textutil.py b/azurelinuxagent/utils/textutil.py
index 2e66b0e..e0f1395 100644
--- a/azurelinuxagent/utils/textutil.py
+++ b/azurelinuxagent/utils/textutil.py
@@ -1,4 +1,4 @@
-# Windows Azure Linux Agent
+# Microsoft Azure Linux Agent
#
# Copyright 2014 Microsoft Corporation
#
@@ -22,6 +22,7 @@ import string
import struct
import xml.dom.minidom as minidom
import sys
+from distutils.version import LooseVersion
def parse_doc(xml_text):
"""
@@ -217,12 +218,11 @@ def remove_bom(c):
c = c[3:]
return c
-def gen_password_hash(password, use_salt, salt_type, salt_len):
- salt="$6$"
- if use_salt:
- collection = string.ascii_letters + string.digits
- salt = ''.join(random.choice(collection) for _ in range(salt_len))
- salt = "${0}${1}".format(salt_type, salt)
+def gen_password_hash(password, crypt_id, salt_len):
+ collection = string.ascii_letters + string.digits
+ salt = ''.join(random.choice(collection) for _ in range(salt_len))
+ salt = "${0}${1}".format(crypt_id, salt)
return crypt.crypt(password, salt)
+Version = LooseVersion