Skip to content

Commit

Permalink
pybind: use find_library for libcephfs and librbd
Browse files Browse the repository at this point in the history
Use find_library to avoid assumptions about platform shared library
naming conventions.

Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
  • Loading branch information
dotnwat committed Oct 28, 2013
1 parent e5efc29 commit b28b64a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/pybind/cephfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
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):
Expand Down Expand Up @@ -124,7 +125,10 @@ def require_state(self, *args):
"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):
Expand Down
14 changes: 12 additions & 2 deletions src/pybind/rbd.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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

Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -330,7 +340,7 @@ def __init__(self, ioctx, name, snapshot=None, read_only=False):
: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):
Expand Down

0 comments on commit b28b64a

Please sign in to comment.