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
+ * Like rados_create, but
+ * 1) don't assume 'client.'+id; allow full specification of name
+ * 2) allow specification of cluster name
+ * 3) flags for future expansion
*/
-int rados_create2(rados_t *cluster, const char * const name);
+int rados_create2(rados_t *pcluster, const char *const clustername,
+ const char * const name, uint64_t flags);
/**
* Initialize a cluster handle from an existing configuration.
~Rados();
int init(const char * const id);
- int init2(const char * const name);
+ int init2(const char * const name, const char * const clustername,
+ uint64_t flags);
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)
+int librados::Rados::init2(const char * const name,
+ const char * const clustername, uint64_t flags)
{
- return rados_create2((rados_t *)&client, name);
+ return rados_create2((rados_t *)&client, clustername, name, flags);
}
int librados::Rados::init_with_context(config_t cct_)
///////////////////////////// C API //////////////////////////////
static
-int rados_create_common(rados_t *pcluster, CephInitParameters *iparams)
+int rados_create_common(rados_t *pcluster,
+ const char * const clustername,
+ CephInitParameters *iparams)
{
+ // missing things compared to global_init:
+ // g_ceph_context, g_conf, g_lockdep, signal handlers
CephContext *cct = common_preinit(*iparams, CODE_ENVIRONMENT_LIBRARY, 0);
+ if (clustername)
+ cct->_conf->cluster = clustername;
cct->_conf->parse_env(); // environment variables override
cct->_conf->apply_changes(NULL);
if (id) {
iparams.name.set(CEPH_ENTITY_TYPE_CLIENT, id);
}
- return rados_create_common(pcluster, &iparams);
+ return rados_create_common(pcluster, "ceph", &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)
+// as above, but
+// 1) don't assume 'client.'; name is a full type.id namestr
+// 2) allow setting clustername
+// 3) flags is for future expansion (maybe some of the global_init()
+// behavior is appropriate for some consumers of librados, for instance)
+
+extern "C" int rados_create2(rados_t *pcluster, const char *const clustername,
+ const char * const name, uint64_t flags)
{
// 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);
+ return rados_create_common(pcluster, clustername, &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, name=None):
+ def __init__(self, rados_id=None, name=None, clustername='ceph',
+ conf_defaults=None, conffile=None, conf=None, flags=0):
self.librados = CDLL('librados.so.2')
self.cluster = c_void_p()
self.rados_id = rados_id
if rados_id and not isinstance(rados_id, str):
raise TypeError('rados_id must be a string or None')
- if conffile and not isinstance(conffile, str):
+ if conffile is not None and not isinstance(conffile, str):
raise TypeError('conffile must be a string or None')
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)))
+ ret = run_in_thread(self.librados.rados_create2,
+ (byref(self.cluster), c_char_p(clustername),
+ c_char_p(rados_id), c_uint64(flags)))
if ret != 0:
raise Error("rados_initialize failed with error code: %d" % ret)
self.state = "configuring"
+ # order is important: conf_defaults, then conffile, then conf
+ if conf_defaults:
+ for key, value in conf_defaults.iteritems():
+ self.conf_set(key, value)
if conffile is not None:
# read the default conf file when '' is given
if conffile == '':
conffile = None
self.conf_read_file(conffile)
- if conf is not None:
+ if conf:
for key, value in conf.iteritems():
self.conf_set(key, value)