Add some Python bindings for librgw.
Also add some more verbose error logging to librgw.
Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
dist-hook:
$(srcdir)/check_version $(srcdir)/.git_version
-python_PYTHON = pybind/rados.py
+python_PYTHON = pybind/rados.py \
+ pybind/rgw.py
if WITH_DEBUG
-dist_bin_SCRIPTS += test/ceph-pybind-test.py
+dist_bin_SCRIPTS += test/ceph-pybind-test.py \
+ test/ceph-pybind-rgw-test.py
endif
# headers... and everything else we want to include in a 'make dist'
--- /dev/null
+"""librgw Python ctypes wrapper
+Copyright 2011, New Dream Network
+"""
+from ctypes import CDLL, c_char_p, c_size_t, c_void_p,\
+ create_string_buffer, byref, Structure, c_uint64, c_ubyte, c_byte,\
+ pointer, c_int
+import ctypes
+import datetime
+import errno
+import time
+
+class Rgw(object):
+ """librgw python wrapper"""
+ def __init__(self):
+ self.lib = CDLL('librgw.so')
+ def acl_bin2xml(self, blob):
+ blob_buf = ctypes.create_string_buffer(blob[:])
+ xml = c_char_p(0)
+ ret = self.lib.librgw_acl_bin2xml(byref(blob_buf), len(blob), byref(xml))
+ if (ret != 0):
+ raise Exception(ret, "acl_bin2xml failed with error %d" % ret)
+ retstr = str(xml)
+ self.lib.librgw_free_xml(xml)
+ return retstr
+ def acl_xml2bin(self, xml):
+ blen = c_int(0)
+ blob = c_void_p(0)
+ print "WATERMELON 1"
+ ret = self.lib.librgw_acl_xml2bin(c_char_p(xml), byref(blob), byref(blen))
+ if (ret != 0):
+ raise Exception(ret, "acl_bin2xml failed with error %d" % ret)
+ print "WATERMELON 2"
+ retblob = ctypes.cast(blob, ctypes.POINTER(ctypes.c_ubyte * blen.value))
+ rets = str(retblob)
+ self.lib.librgw_free_bin(blob)
+ return rets
#include "include/rados/librgw.h"
#include "rgw/rgw_acl.h"
#include "rgw_acl.h"
+#include "common/config.h"
#include <errno.h>
#include <sstream>
#include <string.h>
+#define RGW_LOG(x) pdout(x, g_conf.rgw_log)
+
int librgw_acl_bin2xml(const char *bin, int bin_len, char **xml)
{
try {
return -ENOBUFS;
return 0;
}
+ catch (const std::exception &e) {
+ RGW_LOG(-1) << "librgw_acl_bin2xml: caught exception " << e.what() << dendl;
+ return -2000;
+ }
catch (...) {
+ RGW_LOG(-1) << "librgw_acl_bin2xml: caught unknown exception " << dendl;
return -2000;
}
}
*bin_len = bin_len_;
return 0;
}
+ catch (const std::exception &e) {
+ RGW_LOG(-1) << "librgw_acl_bin2xml: caught exception " << e.what() << dendl;
+ }
catch (...) {
- if (!bin_)
- free(bin_);
- bin_ = NULL;
- return -2000;
+ RGW_LOG(-1) << "librgw_acl_bin2xml: caught unknown exception " << dendl;
}
+ if (!bin_)
+ free(bin_);
+ bin_ = NULL;
+ return -2000;
}
void librgw_free_bin(char *bin)
--- /dev/null
+#!/usr/bin/python
+
+import rgw
+import sys
+
+r = rgw.Rgw()
+
+xml = """<AccessControlPolicy xmlns="http://s3.amazonaws.com/doc/2006-03-01/">\n
+ <Owner>\n
+ <ID>foo</ID>\n
+ <DisplayName>MrFoo</DisplayName>\n
+ </Owner>\n
+ <AccessControlList>\n
+ <Grant>\n
+ <Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\">\n
+ <ID>bar</ID>\n
+ <DisplayName>display-name</DisplayName>\n
+ </Grantee>\n
+ <Permission>FULL_CONTROL</Permission>\n
+ </Grant>\n
+ </AccessControlList>\n
+</AccessControlPolicy>"""
+
+print "converting %s to binary..." % xml
+blob = r.acl_xml2bin(xml)
+print "got blob of length %d" % len(blob)
+
+xml2 = r.acl_bin2xml(blob)
+
+blob2 = r.acl_xml2bin(xml2)
+
+if (blob != blob2):
+ raise "blob differed from blob2!"
+
+sys.exit(0)