1
# Copyright 2014 Microsoft Corporation
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
15
# Requires Python 2.4+ and Openssl 1.0+
23
import azurelinuxagent.common.conf as conf
24
import azurelinuxagent.common.utils.fileutil as fileutil
25
from azurelinuxagent.common.utils.flexible_version import FlexibleVersion
26
from azurelinuxagent.common.future import ustr
30
if 'FreeBSD' in platform.system():
31
release = re.sub('\-.*\Z', '', ustr(platform.release()))
32
osinfo = ['freebsd', release, '', 'freebsd']
33
elif 'linux_distribution' in dir(platform):
34
osinfo = list(platform.linux_distribution(full_distribution_name=0,
35
supported_dists=platform._supported_dists+('alpine',)))
36
full_name = platform.linux_distribution()[0].strip()
37
osinfo.append(full_name)
39
osinfo = platform.dist()
41
# The platform.py lib has issue with detecting oracle linux distribution.
42
# Merge the following patch provided by oracle as a temparory fix.
43
if os.path.exists("/etc/oracle-release"):
45
osinfo[3] = "Oracle Linux"
47
# Remove trailing whitespace and quote in distro name
48
osinfo[0] = osinfo[0].strip('"').strip(' ').lower()
52
AGENT_NAME = "WALinuxAgent"
53
AGENT_LONG_NAME = "Azure Linux Agent"
54
AGENT_VERSION = '2.1.6'
55
AGENT_LONG_VERSION = "{0}-{1}".format(AGENT_NAME, AGENT_VERSION)
56
AGENT_DESCRIPTION = """\
57
The Azure Linux Agent supports the provisioning and running of Linux
58
VMs in the Azure cloud. This package should be installed on Linux disk
59
images that are built to run in the Azure environment.
62
AGENT_DIR_GLOB = "{0}-*".format(AGENT_NAME)
63
AGENT_PKG_GLOB = "{0}-*.zip".format(AGENT_NAME)
65
AGENT_PATTERN = "{0}-(.*)".format(AGENT_NAME)
66
AGENT_NAME_PATTERN = re.compile(AGENT_PATTERN)
67
AGENT_DIR_PATTERN = re.compile(".*/{0}".format(AGENT_PATTERN))
70
# Set the CURRENT_AGENT and CURRENT_VERSION to match the agent directory name
71
# - This ensures the agent will "see itself" using the same name and version
72
# as the code that downloads agents.
73
def set_current_agent():
75
lib_dir = conf.get_lib_dir()
76
if lib_dir[-1] != os.path.sep:
77
lib_dir += os.path.sep
78
if path[:len(lib_dir)] != lib_dir:
79
agent = AGENT_LONG_VERSION
80
version = AGENT_VERSION
82
agent = path[len(lib_dir):].split(os.path.sep)[0]
83
version = AGENT_NAME_PATTERN.match(agent).group(1)
84
return agent, FlexibleVersion(version)
85
CURRENT_AGENT, CURRENT_VERSION = set_current_agent()
87
def is_current_agent_installed():
88
return CURRENT_AGENT == AGENT_LONG_VERSION
91
__distro__ = get_distro()
92
DISTRO_NAME = __distro__[0]
93
DISTRO_VERSION = __distro__[1]
94
DISTRO_CODE_NAME = __distro__[2]
95
DISTRO_FULL_NAME = __distro__[3]
97
PY_VERSION = sys.version_info
98
PY_VERSION_MAJOR = sys.version_info[0]
99
PY_VERSION_MINOR = sys.version_info[1]
100
PY_VERSION_MICRO = sys.version_info[2]
103
Add this workaround for detecting Snappy Ubuntu Core temporarily, until ubuntu
104
fixed this bug: https://bugs.launchpad.net/snappy/+bug/1481086
109
if os.path.exists("/etc/motd"):
110
motd = fileutil.read_file("/etc/motd")
117
DISTRO_FULL_NAME = "Snappy Ubuntu Core"