]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind: use find_library for libcephfs and librbd 777/head
authorNoah Watkins <noahwatkins@gmail.com>
Mon, 28 Oct 2013 21:37:07 +0000 (14:37 -0700)
committerNoah Watkins <noahwatkins@gmail.com>
Mon, 28 Oct 2013 21:37:07 +0000 (14:37 -0700)
Use find_library to avoid assumptions about platform shared library
naming conventions.

Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
src/pybind/cephfs.py
src/pybind/rbd.py

index 80b7e4b773ff4dbddf92d80d42d0ceb36dae329f..effc6577b689b0f4352f4ff40911050550b925f4 100644 (file)
@@ -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):
index 6e9ca8a22525da9d16eb3bdba491b878353671fa..ae13252a59b3d7af8a06e2b50e2ce94ed2c3c7aa 100644 (file)
@@ -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):