CEPH_RADOS_API int rados_break_lock(rados_ioctx_t io, const char *o,
const char *name, const char *client,
const char *cookie);
+
+/**
+ * Blacklists the specified client from the OSDs
+ *
+ * @param cluster cluster handle
+ * @param client_address client address
+ * @param expire_seconds number of seconds to blacklist (0 for default)
+ * @returns 0 on success, negative error code on failure
+ */
+CEPH_RADOS_API int rados_blacklist_add(rados_t cluster,
+ char *client_address,
+ uint32_t expire_seconds);
+
/**
* @defgroup librados_h_commands Mon/OSD/PG Commands
*
/// get/wait for the most recent osdmap
int wait_for_latest_osdmap();
+ int blacklist_add(const std::string& client_address,
+ uint32_t expire_seconds);
+
/*
* pool aio
*
#include <iostream>
#include <string>
+#include <sstream>
#include <pthread.h>
#include <errno.h>
objecter->blacklist_self(set);
}
+int librados::RadosClient::blacklist_add(const string& client_address,
+ uint32_t expire_seconds)
+{
+ entity_addr_t addr;
+ if (!addr.parse(client_address.c_str(), 0)) {
+ lderr(cct) << "unable to parse address " << client_address << dendl;
+ return -EINVAL;
+ }
+
+ std::stringstream cmd;
+ cmd << "{"
+ << "\"prefix\": \"osd blacklist\", "
+ << "\"blacklistop\": \"add\", "
+ << "\"addr\": \"" << client_address << "\"";
+ if (expire_seconds != 0) {
+ cmd << ", \"expire\": " << expire_seconds << ".0";
+ }
+ cmd << "}";
+
+ std::vector<std::string> cmds;
+ cmds.push_back(cmd.str());
+ bufferlist inbl;
+ int r = mon_command(cmds, inbl, NULL, NULL);
+ return r;
+}
+
int librados::RadosClient::mon_command(const vector<string>& cmd,
const bufferlist &inbl,
bufferlist *outbl, string *outs)
int pool_delete_async(const char *name, PoolAsyncCompletionImpl *c);
+ int blacklist_add(const string& client_address, uint32_t expire_seconds);
+
int mon_command(const vector<string>& cmd, const bufferlist &inbl,
bufferlist *outbl, string *outs);
int mon_command(int rank,
return client->wait_for_latest_osdmap();
}
+int librados::Rados::blacklist_add(const std::string& client_address,
+ uint32_t expire_seconds)
+{
+ return client->blacklist_add(client_address, expire_seconds);
+}
+
librados::PoolAsyncCompletion *librados::Rados::pool_async_create_completion()
{
PoolAsyncCompletionImpl *c = new PoolAsyncCompletionImpl;
return retval;
}
+extern "C" int rados_blacklist_add(rados_t cluster, char *client_address,
+ uint32_t expire_seconds)
+{
+ librados::RadosClient *radosp = (librados::RadosClient *)cluster;
+ return radosp->blacklist_add(client_address, expire_seconds);
+}
+
extern "C" int rados_pool_list(rados_t cluster, char *buf, size_t len)
{
tracepoint(librados, rados_pool_list_enter, cluster, len);
"""
from ctypes import CDLL, c_char_p, c_size_t, c_void_p, c_char, c_int, c_long, \
c_ulong, create_string_buffer, byref, Structure, c_uint64, c_ubyte, \
- pointer, CFUNCTYPE, c_int64, c_uint8
+ pointer, CFUNCTYPE, c_int64, c_uint32, c_uint8
from ctypes.util import find_library
import ctypes
import errno
self.require_state("connected")
return run_in_thread(self.librados.rados_wait_for_latest_osdmap, (self.cluster,))
+ def blacklist_add(self, client_address, expire_seconds = 0):
+ """
+ Blacklist a client from the OSDs
+
+ :param client_address: client address
+ :type client_address: str
+ :param expire_seconds: number of seconds to blacklist
+ :type expire_seconds: int
+
+ :raises: :class:`Error`
+ """
+ self.require_state("connected")
+ ret = run_in_thread(self.librados.rados_blacklist_add,
+ (self.cluster, c_char_p(client_address),
+ c_uint32(expire_seconds)))
+ if ret < 0:
+ raise make_ex(ret, "error blacklisting client '%s'" % client_address)
+
class ObjectIterator(object):
"""rados.Ioctx Object iterator"""
def __init__(self, ioctx):
assert_raises(RadosStateError, rados.osd_command, 0, '', '')
assert_raises(RadosStateError, rados.pg_command, '', '', '')
assert_raises(RadosStateError, rados.wait_for_latest_osdmap)
+ assert_raises(RadosStateError, rados.blacklist_add, '127.0.0.1/123', 0)
def test_configuring(self):
rados = Rados(conffile='')
fsid = self.rados.get_fsid()
eq(len(fsid), 36)
+ def test_blacklist_add(self):
+ self.rados.blacklist_add("1.2.3.4/123", 1)
+
class TestIoctx(object):
def setUp(self):