From: Alfredo Deza Date: Mon, 26 Feb 2018 21:17:12 +0000 (-0500) Subject: ceph-volume util.system add a helper to find system executables X-Git-Tag: v13.0.2~125^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c36afed9a2fd956dd0694f247f931ae92ae6629a;p=ceph.git ceph-volume util.system add a helper to find system executables Signed-off-by: Alfredo Deza --- diff --git a/src/ceph-volume/ceph_volume/util/system.py b/src/ceph-volume/ceph_volume/util/system.py index 2b4473efe62f..0ba46d362766 100644 --- a/src/ceph-volume/ceph_volume/util/system.py +++ b/src/ceph-volume/ceph_volume/util/system.py @@ -5,10 +5,11 @@ import pwd import platform import tempfile import uuid -from ceph_volume import process +from ceph_volume import process, terminal from . import as_string logger = logging.getLogger(__name__) +mlogger = terminal.MultiLogger(__name__) # TODO: get these out of here and into a common area for others to consume if platform.system() == 'FreeBSD': @@ -30,6 +31,28 @@ def generate_uuid(): return str(uuid.uuid4()) +def which(executable): + """find the location of an executable""" + locations = ( + '/usr/local/bin', + '/bin', + '/usr/bin', + '/usr/local/sbin', + '/usr/sbin', + '/sbin', + ) + + for location in locations: + executable_path = os.path.join(location, executable) + if os.path.exists(executable_path) and os.path.isfile(executable_path): + return executable_path + mlogger.warning('Absolute path not found for executable: %s', executable) + mlogger.warning('Ensure $PATH environment variable contains common executable locations') + # fallback to just returning the argument as-is, to prevent a hard fail, + # and hoping that the system might have the executable somewhere custom + return executable + + def get_ceph_user_ids(): """ Return the id and gid of the ceph user