return 0;
}
+static int read_current_period_id(RGWRados* store, const std::string& realm_id,
+ const std::string& realm_name,
+ std::string* period_id)
+{
+ RGWRealm realm(realm_id, realm_name);
+ int ret = realm.init(g_ceph_context, store);
+ if (ret < 0) {
+ std::cerr << "failed to read realm: " << cpp_strerror(-ret) << std::endl;
+ return ret;
+ }
+ *period_id = realm.get_current_period();
+ return 0;
+}
+
int main(int argc, char **argv)
{
vector<const char*> args;
break;
case OPT_PERIOD_GET_CURRENT:
{
- RGWRealm realm(realm_id, realm_name);
- int ret = realm.init(g_ceph_context, store);
- if (ret < 0 ) {
- cerr << "Error initializing realm " << cpp_strerror(-ret) << std::endl;
- return ret;
- }
- string current_id = realm.get_current_period();
+ int ret = read_current_period_id(store, realm_id, realm_name, &period_id);
if (ret < 0) {
- cerr << "Error reading current period:" << cpp_strerror(-ret) << std::endl;
return ret;
}
formatter->open_object_section("period_get_current");
- encode_json("current_period", current_id, formatter);
+ encode_json("current_period", period_id, formatter);
formatter->close_section();
formatter->flush(cout);
}
break;
case OPT_REALM_LIST_PERIODS:
{
- RGWRealm realm(realm_id, realm_name);
- int ret = realm.init(g_ceph_context, store);
+ int ret = read_current_period_id(store, realm_id, realm_name, &period_id);
if (ret < 0) {
- cerr << "realm.init failed: " << cpp_strerror(-ret) << std::endl;
return -ret;
}
- string current_period = realm.get_current_period();
list<string> periods;
- ret = store->list_periods(current_period, periods);
+ ret = store->list_periods(period_id, periods);
if (ret < 0) {
cerr << "list periods failed: " << cpp_strerror(-ret) << std::endl;
return -ret;
}
formatter->open_object_section("realm_periods_list");
- encode_json("current_period", current_period, formatter);
+ encode_json("current_period", period_id, formatter);
encode_json("periods", periods, formatter);
formatter->close_section();
formatter->flush(cout);
int i = (specified_shard_id ? shard_id : 0);
if (period_id.empty()) {
- // read current_period from the realm
- RGWRealm realm(realm_id, realm_name);
- ret = realm.init(g_ceph_context, store);
+ int ret = read_current_period_id(store, realm_id, realm_name, &period_id);
if (ret < 0) {
- std::cerr << "failed to init realm: " << cpp_strerror(-ret) << std::endl;
return -ret;
}
- period_id = realm.get_current_period();
std::cerr << "No --period given, using current period="
<< period_id << std::endl;
}
int i = (specified_shard_id ? shard_id : 0);
if (period_id.empty()) {
- // read current_period from the realm
- RGWRealm realm(realm_id, realm_name);
- int ret = realm.init(g_ceph_context, store);
+ int ret = read_current_period_id(store, realm_id, realm_name, &period_id);
if (ret < 0) {
- std::cerr << "failed to init realm: " << cpp_strerror(-ret) << std::endl;
return ret;
}
- period_id = realm.get_current_period();
std::cerr << "No --period given, using current period="
<< period_id << std::endl;
}