From 750074b2b6c1245a91b71e5361221434eb50b23b Mon Sep 17 00:00:00 2001 From: Orit Wasserman Date: Wed, 9 Sep 2015 10:40:01 +0200 Subject: [PATCH] radosgw-admin: Add period list command Signed-off-by: Orit Wasserman --- src/rgw/rgw_admin.cc | 21 ++++++++++++++++++++- src/rgw/rgw_rados.cc | 7 +++++++ src/rgw/rgw_rados.h | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index c71bb7c01208f..7e068a348d266 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -78,6 +78,7 @@ void _usage() cerr << " period get-current get current period info\n"; cerr << " period pull pull a period\n"; cerr << " period push push a period\n"; + cerr << " period list list all period\n"; cerr << " quota set set quota params\n"; cerr << " quota enable enable quota\n"; cerr << " quota disable disable quota\n"; @@ -331,6 +332,7 @@ enum { OPT_PERIOD_ACTIVATE, OPT_PERIOD_PULL, OPT_PERIOD_PUSH, + OPT_PERIOD_LIST, }; static int get_cmd(const char *cmd, const char *prev_cmd, const char *prev_prev_cmd, bool *need_more) @@ -492,6 +494,8 @@ static int get_cmd(const char *cmd, const char *prev_cmd, const char *prev_prev_ return OPT_PERIOD_PULL; if (strcmp(cmd, "push") == 0) return OPT_PERIOD_PUSH; + if (strcmp(cmd, "list") == 0) + return OPT_PERIOD_LIST; } else if (strcmp(prev_cmd, "realm") == 0) { if (strcmp(cmd, "create") == 0) return OPT_REALM_CREATE; @@ -1660,7 +1664,7 @@ int main(int argc, char **argv) opt_cmd == OPT_PERIOD_PREPARE || opt_cmd == OPT_PERIOD_ACTIVATE || opt_cmd == OPT_PERIOD_DELETE || opt_cmd == OPT_PERIOD_GET || opt_cmd == OPT_PERIOD_PULL || opt_cmd == OPT_PERIOD_PUSH || - opt_cmd == OPT_PERIOD_GET_CURRENT || + opt_cmd == OPT_PERIOD_GET_CURRENT || opt_cmd == OPT_PERIOD_LIST || opt_cmd == OPT_REALM_DELETE || opt_cmd == OPT_REALM_GET || opt_cmd == OPT_REALM_LIST || opt_cmd == OPT_REALM_GET_DEFAULT || opt_cmd == OPT_REALM_REMOVE || opt_cmd == OPT_REALM_RENAME || opt_cmd == OPT_REALM_SET_DEFAULT); @@ -1823,6 +1827,21 @@ int main(int argc, char **argv) } } break; + case OPT_PERIOD_LIST: + { + list periods; + int ret = store->list_periods(periods); + if (ret < 0) { + cerr << "failed to list periods: " << cpp_strerror(-ret) << std::endl; + return -ret; + } + formatter->open_object_section("periods_list"); + encode_json("periods", periods, formatter); + formatter->close_section(); + formatter->flush(cout); + cout << std::endl; + } + break; case OPT_REALM_CREATE: { if (realm_name.empty()) { diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 41285f1b77d4b..08bed0ed28eac 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -2352,6 +2352,13 @@ int RGWRados::list_realms(list& realms) return list_raw_prefixed_objs(pool_name, realm_names_oid_prefix, realms); } +int RGWRados::list_periods(list& periods) +{ + RGWPeriod period(cct, this); + + return list_raw_prefixed_objs(period.get_pool_name(cct), period.get_info_oid_prefix(), periods); +} + /** * Open the pool used as root for this gateway * Returns: 0 on success, -ERR# otherwise. diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 3e029028b4585..9288d5dbf8d18 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -1677,7 +1677,7 @@ public: int list_regions(list& regions); int list_zones(list& zones); int list_realms(list& realms); - + int list_periods(list& periods); void tick(); CephContext *ctx() { return cct; } -- 2.39.5