on the type of distribution/version we are dealing with.
"""
import logging
-import ceph_deploy
-from ceph_deploy import exc
+from ceph_deploy import exc, lsb
from ceph_deploy.util import wrappers
from ceph_deploy.sudo_pushy import get_transport
from ceph_deploy.hosts import debian, centos, fedora, suse
import pushy
from ceph_deploy import sudo_pushy
sudo_pushy.patch()
+
logger = logging.getLogger()
:param fallback: Optional fallback to use if no supported distro is found
"""
sudo_conn = pushy.connect(get_transport(hostname))
- if not has_lsb(sudo_conn):
- logger.warning('lsb_release was not found - inferring OS details')
- (distro, release, codename) = lsb_fallback(sudo_conn)
- else:
- (distro, release, codename) = ceph_deploy.lsb.get_lsb_release(sudo_conn)
+ (distro, release, codename) = lsb.get_lsb_release(sudo_conn)
module = _get_distro(distro)
module.name = distro
return module
-def lsb_fallback(conn):
- """
- This fallback will attempt to detect the distro, release and codename for
- a given remote host when lsb fails. It uses the
- ``platform.linux_distribution`` module that should be fairly robust and
- would prevent us from adding repositories and installing a package just to
- detect a platform.
- """
- distro, release, codename = conn.modules.platform.linux_distribution()
- return (
- str(distro).rstrip(),
- str(release).rstrip(),
- str(codename).rstrip()
- )
-
-
-def has_lsb(conn):
- _, _, ret_code = wrappers.Popen(conn, logger, ['which', 'lsb_release'])
- return ret_code == 0
-
-
def _get_distro(distro, fallback=None):
distro = _normalized_distro_name(distro)
distributions = {
-from . import hosts
+import logging
from . import exc
+
+logger = logging.getLogger(__name__)
+
+
def check_lsb_release():
"""
Verify if lsb_release command is available
if ret != 0:
raise RuntimeError('The lsb_release command was not found on remote host. Please install the lsb-release package.')
+
+def lsb_fallback(conn):
+ """
+ This fallback will attempt to detect the distro, release and codename for
+ a given remote host when lsb fails. It uses the
+ ``platform.linux_distribution`` module that should be fairly robust and
+ would prevent us from adding repositories and installing a package just to
+ detect a platform.
+ """
+ distro, release, codename = conn.modules.platform.linux_distribution()
+ return (
+ str(distro).rstrip(),
+ str(release).rstrip(),
+ str(codename).rstrip()
+ )
+
+
def lsb_release():
"""
Get LSB release information from lsb_release.
check_lsb_release_r = sudo.compile(check_lsb_release)
status = check_lsb_release_r()
except RuntimeError as e:
- return hosts.lsb_fallback(sudo)
+ logger.warning('lsb_release was not found - inferring OS details')
+ return lsb_fallback(sudo)
lsb_release_r = sudo.compile(lsb_release)
return lsb_release_r()