diff --git a/src/pybind/cephfs.py b/src/pybind/cephfs.py index 80b7e4b773f..effc6577b68 100644 --- a/src/pybind/cephfs.py +++ b/src/pybind/cephfs.py @@ -3,6 +3,7 @@ This module is a thin wrapper around libcephfs. """ from ctypes import CDLL, c_char_p, c_size_t, c_void_p, c_int, c_long, c_uint, c_ulong, \ create_string_buffer, byref, Structure +from ctypes.util import find_library import errno class Error(Exception): @@ -124,7 +125,10 @@ class LibCephFS(object): "CephFS object in state %s." % (self.state)) def __init__(self, conf=None, conffile=None): - self.libcephfs = CDLL('libcephfs.so.1') + libcephfs_path = find_library('cephfs') + if not libcephfs_path: + raise EnvironmentError("Unable to find libcephfs") + self.libcephfs = CDLL(libcephfs_path) self.cluster = c_void_p() if conffile is not None and not isinstance(conffile, str): diff --git a/src/pybind/rbd.py b/src/pybind/rbd.py index 6e9ca8a2252..ae13252a59b 100644 --- a/src/pybind/rbd.py +++ b/src/pybind/rbd.py @@ -18,6 +18,7 @@ methods, a :class:`TypeError` will be raised. from ctypes import CDLL, c_char, c_char_p, c_size_t, c_void_p, c_int, \ create_string_buffer, byref, Structure, c_uint64, c_int64, c_uint8, \ CFUNCTYPE +from ctypes.util import find_library import ctypes import errno @@ -116,12 +117,21 @@ class rbd_snap_info_t(Structure): ("size", c_uint64), ("name", c_char_p)] +def load_librbd(): + """ + Load the librbd shared library. + """ + librbd_path = find_library('rbd') + if not librbd_path: + raise EnvironmentError("Unable to find librbd") + return CDLL(librbd_path) + class RBD(object): """ This class wraps librbd CRUD functions. """ def __init__(self): - self.librbd = CDLL('librbd.so.1') + self.librbd = load_librbd() def version(self): """ @@ -330,7 +340,7 @@ class Image(object): :type read_only: bool """ self.closed = True - self.librbd = CDLL('librbd.so.1') + self.librbd = load_librbd() self.image = c_void_p() self.name = name if not isinstance(name, str):