# 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
*/
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.
*
~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();
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_);
}
///////////////////////////// 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);
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.
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"