]>
git.proxmox.com Git - ceph.git/blob - ceph/src/ceph-detect-init/ceph_detect_init/__init__.py
1 # Copyright (C) 2015 <contact@redhat.com>
3 # Author: Alfredo Deza <adeza@redhat.com>
4 # Author: Loic Dachary <loic@dachary.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU Library Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Library Public License for more details.
16 from ceph_detect_init
import alpine
17 from ceph_detect_init
import arch
18 from ceph_detect_init
import centos
19 from ceph_detect_init
import debian
20 from ceph_detect_init
import exc
21 from ceph_detect_init
import fedora
22 from ceph_detect_init
import rhel
23 from ceph_detect_init
import suse
24 from ceph_detect_init
import gentoo
25 from ceph_detect_init
import freebsd
26 from ceph_detect_init
import docker
27 from ceph_detect_init
import oraclevms
33 def get(use_rhceph
=False):
34 distro_name
, release
, codename
= platform_information()
35 # Not all distributions have a concept that maps to codenames
36 # (or even releases really)
37 if not codename
and not _get_distro(distro_name
):
38 raise exc
.UnsupportedPlatform(
43 module
= _get_distro(distro_name
, use_rhceph
=use_rhceph
)
44 module
.name
= distro_name
45 module
.normalized_name
= _normalized_distro_name(distro_name
)
46 module
.distro
= module
.normalized_name
47 module
.is_el
= module
.normalized_name
in ['redhat', 'centos',
48 'fedora', 'scientific',
50 module
.release
= release
51 module
.codename
= codename
52 module
.init
= module
.choose_init()
56 def _get_distro(distro
, use_rhceph
=False):
60 distro
= _normalized_distro_name(distro
)
70 'oraclevms': oraclevms
,
82 if distro
== 'redhat' and use_rhceph
:
85 return distributions
.get(distro
)
88 def _normalized_distro_name(distro
):
89 distro
= distro
.lower()
90 if distro
.startswith(('redhat', 'red hat')):
92 elif distro
.startswith(('scientific', 'scientific linux')):
94 elif distro
.startswith(('suse', 'opensuse')):
96 elif distro
.startswith('centos'):
98 elif distro
.startswith('oracle linux'):
100 elif distro
.startswith('oracle vm'):
102 elif distro
.startswith(('gentoo', 'funtoo', 'exherbo')):
104 elif distro
.startswith('virtuozzo'):
109 def platform_information():
110 """detect platform information from remote host."""
112 file_name
= '/proc/self/cgroup'
113 with
open(file_name
, 'r') as f
:
114 lines
= f
.readlines()
116 if "docker" in line
.split(':')[2]:
117 return ('docker', 'docker', 'docker')
118 except Exception as err
:
119 logging
.debug("platform_information: ",
120 "Error while opening %s : %s" % (file_name
, err
))
122 if os
.path
.isfile('/.dockerenv'):
123 return ('docker', 'docker', 'docker')
125 if platform
.system() == 'Linux':
126 linux_distro
= platform
.linux_distribution(
127 supported_dists
=platform
._supported
_dists
+ ('alpine', 'arch'))
128 logging
.debug('platform_information: linux_distribution = ' +
130 distro
, release
, codename
= linux_distro
131 elif platform
.system() == 'FreeBSD':
133 release
= platform
.release()
134 codename
= platform
.version().split(' ')[3].split(':')[0]
136 'platform_information: release = {}, version = {}'.format(
137 platform
.release(), platform
.version()))
139 raise exc
.UnsupportedPlatform(platform
.system(), '', '')
141 distro_lower
= distro
.lower()
142 # this could be an empty string in Debian
143 if not codename
and 'debian' in distro_lower
:
149 major_version
= release
.split('.')[0]
150 codename
= debian_codenames
.get(major_version
, '')
152 # In order to support newer jessie/sid or wheezy/sid strings
153 # we test this if sid is buried in the minor, we should use
155 if not codename
and '/' in release
:
156 major
, minor
= release
.split('/')
161 # this is an empty string in Oracle
162 elif distro_lower
.startswith('oracle linux'):
163 codename
= 'OL' + release
164 elif distro_lower
.startswith('oracle vm'):
165 codename
= 'OVS' + release
166 # this could be an empty string in Virtuozzo linux
167 elif distro_lower
.startswith('virtuozzo linux'):
168 codename
= 'virtuozzo'
171 str(distro
).rstrip(),
172 str(release
).rstrip(),
173 str(codename
).rstrip()