]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
move the lsb_fallback to the lsb module 47/head
authorAlfredo Deza <alfredo.deza@inktank.com>
Thu, 22 Aug 2013 13:45:07 +0000 (09:45 -0400)
committerAlfredo Deza <alfredo.deza@inktank.com>
Thu, 22 Aug 2013 13:45:07 +0000 (09:45 -0400)
Signed-off-by: Alfredo Deza <alfredo.deza@inktank.com>
ceph_deploy/hosts/__init__.py
ceph_deploy/lsb.py

index 33cba50b4f155ff0f43900d2e6441065c65cdae8..5fc973097e0351864d51011693893469d64b55b1 100644 (file)
@@ -5,8 +5,7 @@ that remote host and set all the special cases for running commands depending
 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
@@ -15,6 +14,7 @@ from ceph_deploy.hosts import debian, centos, fedora, suse
 import pushy
 from ceph_deploy import sudo_pushy
 sudo_pushy.patch()
+
 logger = logging.getLogger()
 
 
@@ -36,11 +36,7 @@ def get(hostname, fallback=None):
     :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
@@ -51,27 +47,6 @@ def get(hostname, fallback=None):
     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 = {
index 2ed6cab030b72206f6f7b14a3fd22a1a4b71e884..b7f3e7322ab663b58e0b4a81562b6454bbcd9d16 100644 (file)
@@ -1,6 +1,10 @@
-from . import hosts
+import logging
 from . import exc
 
+
+logger = logging.getLogger(__name__)
+
+
 def check_lsb_release():
     """
     Verify if lsb_release command is available
@@ -18,6 +22,23 @@ def check_lsb_release():
     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.
@@ -82,7 +103,8 @@ def get_lsb_release(sudo):
         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()