mirror of
https://github.com/ceph/ceph
synced 2025-01-10 13:10:46 +00:00
librados, rados.py: add rados_create2/init2
librados clients, particularly the ceph tool, need to be able to specify a full 'name'; rados_create enforced 'client.<param>' with no workaround. New interface. Python Rados().__init__ selects appropriate create function depending on whether name or id is supplied. Signed-off-by: Dan Mick <dan.mick@inktank.com>
This commit is contained in:
parent
ee0913c2e6
commit
24a270a1ae
2
src/ceph
2
src/ceph
@ -1337,7 +1337,7 @@ def main():
|
||||
|
||||
# handle any 'generic' ceph arguments that we didn't parse here
|
||||
global cluster
|
||||
cluster = rados.Rados(rados_id=name, conffile='')
|
||||
cluster = rados.Rados(name=name, conffile='')
|
||||
|
||||
retargs = cluster.conf_parse_argv(childargs)
|
||||
#tmp = childargs
|
||||
|
@ -197,6 +197,12 @@ void rados_version(int *major, int *minor, int *extra);
|
||||
*/
|
||||
int rados_create(rados_t *cluster, const char * const id);
|
||||
|
||||
/**
|
||||
* As in rados_create, but don't assume 'client.'+id; allow full
|
||||
* specification of name
|
||||
*/
|
||||
int rados_create2(rados_t *cluster, const char * const name);
|
||||
|
||||
/**
|
||||
* Initialize a cluster handle from an existing configuration.
|
||||
*
|
||||
|
@ -649,6 +649,7 @@ namespace librados
|
||||
~Rados();
|
||||
|
||||
int init(const char * const id);
|
||||
int init2(const char * const name);
|
||||
int init_with_context(config_t cct_);
|
||||
config_t cct();
|
||||
int connect();
|
||||
|
@ -1203,6 +1203,11 @@ int librados::Rados::init(const char * const id)
|
||||
return rados_create((rados_t *)&client, id);
|
||||
}
|
||||
|
||||
int librados::Rados::init2(const char * const name)
|
||||
{
|
||||
return rados_create2((rados_t *)&client, name);
|
||||
}
|
||||
|
||||
int librados::Rados::init_with_context(config_t cct_)
|
||||
{
|
||||
return rados_create_with_context((rados_t *)&client, (rados_config_t)cct_);
|
||||
@ -1457,14 +1462,10 @@ librados::ObjectOperation::~ObjectOperation()
|
||||
}
|
||||
|
||||
///////////////////////////// C API //////////////////////////////
|
||||
extern "C" int rados_create(rados_t *pcluster, const char * const id)
|
||||
static
|
||||
int rados_create_common(rados_t *pcluster, CephInitParameters *iparams)
|
||||
{
|
||||
CephInitParameters iparams(CEPH_ENTITY_TYPE_CLIENT);
|
||||
if (id) {
|
||||
iparams.name.set(CEPH_ENTITY_TYPE_CLIENT, id);
|
||||
}
|
||||
|
||||
CephContext *cct = common_preinit(iparams, CODE_ENVIRONMENT_LIBRARY, 0);
|
||||
CephContext *cct = common_preinit(*iparams, CODE_ENVIRONMENT_LIBRARY, 0);
|
||||
cct->_conf->parse_env(); // environment variables override
|
||||
cct->_conf->apply_changes(NULL);
|
||||
|
||||
@ -1475,6 +1476,27 @@ extern "C" int rados_create(rados_t *pcluster, const char * const id)
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" int rados_create(rados_t *pcluster, const char * const id)
|
||||
{
|
||||
CephInitParameters iparams(CEPH_ENTITY_TYPE_CLIENT);
|
||||
if (id) {
|
||||
iparams.name.set(CEPH_ENTITY_TYPE_CLIENT, id);
|
||||
}
|
||||
return rados_create_common(pcluster, &iparams);
|
||||
}
|
||||
|
||||
// as above, but don't assume 'client.'; name is a full type.id namestr
|
||||
extern "C" int rados_create2(rados_t *pcluster, const char * const name)
|
||||
{
|
||||
// client is assumed, but from_str will override
|
||||
CephInitParameters iparams(CEPH_ENTITY_TYPE_CLIENT);
|
||||
if (name) {
|
||||
iparams.name.from_str(name);
|
||||
}
|
||||
return rados_create_common(pcluster, &iparams);
|
||||
}
|
||||
|
||||
|
||||
/* This function is intended for use by Ceph daemons. These daemons have
|
||||
* already called global_init and want to use that particular configuration for
|
||||
* their cluster.
|
||||
|
@ -182,16 +182,21 @@ class Rados(object):
|
||||
raise RadosStateError("You cannot perform that operation on a \
|
||||
Rados object in state %s." % (self.state))
|
||||
|
||||
def __init__(self, rados_id=None, conf=None, conffile=None):
|
||||
def __init__(self, rados_id=None, conf=None, conffile=None, name=None):
|
||||
self.librados = CDLL('librados.so.2')
|
||||
self.cluster = c_void_p()
|
||||
self.rados_id = rados_id
|
||||
if rados_id is not None and not isinstance(rados_id, str):
|
||||
if rados_id and not isinstance(rados_id, str):
|
||||
raise TypeError('rados_id must be a string or None')
|
||||
if conffile is not None and not isinstance(conffile, str):
|
||||
if conffile and not isinstance(conffile, str):
|
||||
raise TypeError('conffile must be a string or None')
|
||||
ret = run_in_thread(self.librados.rados_create,
|
||||
(byref(self.cluster), c_char_p(rados_id)))
|
||||
if rados_id and name:
|
||||
raise Error("Rados(): can't supply both rados_id and name")
|
||||
fn = self.librados.rados_create
|
||||
if name:
|
||||
fn = self.librados.rados_create2
|
||||
ret = run_in_thread(fn, (byref(self.cluster), c_char_p(rados_id)))
|
||||
|
||||
if ret != 0:
|
||||
raise Error("rados_initialize failed with error code: %d" % ret)
|
||||
self.state = "configuring"
|
||||
|
Loading…
Reference in New Issue
Block a user