summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2018-07-09 19:59:01 +0000
committerServer Team CI Bot <josh.powers+server-team-bot@canonical.com>2018-07-09 19:59:01 +0000
commitc1a75a697d7cb2e6c97ad90d64c9b2b88db2034a (patch)
treed5aea65af8d71de25de46ceb537ea1381005fd74 /cloudinit/util.py
parent802c1d5110db2edd73a83eb57a9ef7f409bd554f (diff)
downloadvyos-cloud-init-c1a75a697d7cb2e6c97ad90d64c9b2b88db2034a.tar.gz
vyos-cloud-init-c1a75a697d7cb2e6c97ad90d64c9b2b88db2034a.zip
ubuntu,centos,debian: get_linux_distro to align with platform.dist
A recent commit added get_linux_distro to replace the deprecated python platform.dist module behavior before it is dropped from python. It added behavior that was compliant on OpenSuSE and SLES, by returning (<distro_name>, <distro_version>, <cpu-arch>). Fix get_linux_distro to behave more like the specific distribution's platform.dist on ubuntu, centos and debian, which will return the distribution release codename as the third element instead of <cpu-arch>. SLES and OpenSUSE will retain their current behavior. Examples follow: ('sles', '15', 'x86_64') ('opensuse', '42.3', 'x86_64') ('debian', '9', 'stretch') ('ubuntu', '16.04', 'xenial') ('centos', '7', 'Core') LP: #1780481
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py28
1 files changed, 18 insertions, 10 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 6da95113..d0b0e90a 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -579,16 +579,24 @@ def get_cfg_option_int(yobj, key, default=0):
def get_linux_distro():
distro_name = ''
distro_version = ''
+ flavor = ''
if os.path.exists('/etc/os-release'):
- os_release = load_file('/etc/os-release')
- for line in os_release.splitlines():
- if line.strip().startswith('ID='):
- distro_name = line.split('=')[-1]
- distro_name = distro_name.replace('"', '')
- if line.strip().startswith('VERSION_ID='):
- # Lets hope for the best that distros stay consistent ;)
- distro_version = line.split('=')[-1]
- distro_version = distro_version.replace('"', '')
+ os_release = load_shell_content(load_file('/etc/os-release'))
+ distro_name = os_release.get('ID', '')
+ distro_version = os_release.get('VERSION_ID', '')
+ if 'sles' in distro_name or 'suse' in distro_name:
+ # RELEASE_BLOCKER: We will drop this sles ivergent behavior in
+ # before 18.4 so that get_linux_distro returns a named tuple
+ # which will include both version codename and architecture
+ # on all distributions.
+ flavor = platform.machine()
+ else:
+ flavor = os_release.get('VERSION_CODENAME', '')
+ if not flavor:
+ match = re.match(r'[^ ]+ \((?P<codename>[^)]+)\)',
+ os_release.get('VERSION'))
+ if match:
+ flavor = match.groupdict()['codename']
else:
dist = ('', '', '')
try:
@@ -606,7 +614,7 @@ def get_linux_distro():
'expansion may have unexpected results')
return dist
- return (distro_name, distro_version, platform.machine())
+ return (distro_name, distro_version, flavor)
def system_info():