def get_cluster_version(dcos_url):
"""Given a cluster url, return its version string, such as 1.7, 1.8,
1.8.8, 1.9, 1.9-dev, etc"""
version_url = "%s/%s" % (dcos_url, "dcos-metadata/dcos-version.json")
# Since our test clusters have weird certs that won't validate, turn off
# validation
try:
# this will handle a variety of versions, including some 2.7.x
# (haven't investigated which) and all recent 3.x
noverify_context = ssl.SSLContext()
except:
if hasattr(ssl, 'PROTOCOL_TLS'):
# 2.7.13
noverify_context = ssl.SSLContext(ssl.PROTOCOL_TLS)
elif hasattr(ssl, 'OP_NO_SSLv2'):
# 2.7.9-2.7.12
logger.warn("Old python; Asking for something better than sslv2 or 3")
noverify_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
# explicitly switch these off. This is recommended for ancient
# versions as per https://docs.python.org/2/library/ssl.html#protocol-versions
noverify_context.options |= ssl.OP_NO_SSLv2
noverify_context.options |= ssl.OP_NO_SSLv3
else:
# before 2.7.9
logger.error("*VERY* old python. Very weak/unsafe encryption ahoy.")
noverify_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
response = urllib.request.urlopen(version_url, context=noverify_context)
encoding = 'utf-8' # default
try:
#python3
provided_encoding = response.headers.get_content_charset()
if provided_encoding:
encoding = provided_encoding
except:
pass
json_s = response.read().decode(encoding)
ver_s = json.loads(json_s)['version']
return ver_s
评论列表
文章目录