~ubuntu-branches/debian/stretch/waagent/stretch

« back to all changes in this revision

Viewing changes to azurelinuxagent/common/version.py

  • Committer: Package Import Robot
  • Author(s): Bastian Blank
  • Date: 2016-08-24 16:48:22 UTC
  • mfrom: (1.2.5)
  • Revision ID: package-import@ubuntu.com-20160824164822-vdf8m5xy5gycm1cz
Tags: 2.1.6-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2014 Microsoft Corporation
 
2
#
 
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
 
6
#
 
7
#     http://www.apache.org/licenses/LICENSE-2.0
 
8
#
 
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.
 
14
#
 
15
# Requires Python 2.4+ and Openssl 1.0+
 
16
#
 
17
 
 
18
import os
 
19
import re
 
20
import platform
 
21
import sys
 
22
 
 
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
 
27
 
 
28
 
 
29
def get_distro():
 
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)
 
38
    else:
 
39
        osinfo = platform.dist()
 
40
 
 
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"):
 
44
        osinfo[2] = "oracle"
 
45
        osinfo[3] = "Oracle Linux"
 
46
 
 
47
    # Remove trailing whitespace and quote in distro name
 
48
    osinfo[0] = osinfo[0].strip('"').strip(' ').lower()
 
49
    return osinfo
 
50
 
 
51
 
 
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.
 
60
"""
 
61
 
 
62
AGENT_DIR_GLOB = "{0}-*".format(AGENT_NAME)
 
63
AGENT_PKG_GLOB = "{0}-*.zip".format(AGENT_NAME)
 
64
 
 
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))
 
68
 
 
69
 
 
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():
 
74
    path = os.getcwd()
 
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
 
81
    else:
 
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()
 
86
 
 
87
def is_current_agent_installed():
 
88
    return CURRENT_AGENT == AGENT_LONG_VERSION
 
89
 
 
90
 
 
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]
 
96
 
 
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]
 
101
 
 
102
"""
 
103
Add this workaround for detecting Snappy Ubuntu Core temporarily, until ubuntu
 
104
fixed this bug: https://bugs.launchpad.net/snappy/+bug/1481086
 
105
"""
 
106
 
 
107
 
 
108
def is_snappy():
 
109
    if os.path.exists("/etc/motd"):
 
110
        motd = fileutil.read_file("/etc/motd")
 
111
        if "snappy" in motd:
 
112
            return True
 
113
    return False
 
114
 
 
115
 
 
116
if is_snappy():
 
117
    DISTRO_FULL_NAME = "Snappy Ubuntu Core"