pybind: use find_library for libcephfs and librbd

Use find_library to avoid assumptions about platform shared library
naming conventions.

Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
This commit is contained in:
Noah Watkins 2013-10-28 14:37:07 -07:00
parent e5efc2929d
commit b28b64a0b6
2 changed files with 17 additions and 3 deletions

View 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):

View 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):