From 15b2da32f215be60ed56015696de14c0df7b7ce7 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Tue, 29 Jun 2021 15:42:25 -0700 Subject: [PATCH] rgw, rgw-admin: add realm/zonegroup/zone id configurables Add the following configurables: - rgw_realm_id - rgw_zonegroup_id - rgw_zone_id radosgw-admin already had --realm-id, --zonegroup-id, --zone-id config options, however, there were no such config options for radosgw. Adding these new config options so that we could start radosgw with specifying the appropriate entity id (vs. the entity names that was required previously). These also apply for radosgw-admin. The old radosgw-admin params are still valid for backward compatibility. Signed-off-by: Yehuda Sadeh --- src/common/options/rgw.yaml.in | 25 +++++++++++++++++++++++++ src/rgw/rgw_admin.cc | 20 ++++++++++++++++++-- src/rgw/rgw_zone.cc | 16 ++++++++++++++++ src/rgw/rgw_zone.h | 4 ++++ 4 files changed, 63 insertions(+), 2 deletions(-) diff --git a/src/common/options/rgw.yaml.in b/src/common/options/rgw.yaml.in index c7498481d19..cde28e0b64f 100644 --- a/src/common/options/rgw.yaml.in +++ b/src/common/options/rgw.yaml.in @@ -1180,6 +1180,16 @@ options: - rgw_zonegroup - rgw_realm with_legacy: true +- name: rgw_zone_id + type: str + level: advanced + desc: Zone ID + services: + - rgw + see_also: + - rgw_zone + - rgw_zonegroup + - rgw_realm - name: rgw_zone_root_pool type: str level: advanced @@ -1248,6 +1258,16 @@ options: - rgw_zone - rgw_realm with_legacy: true +- name: rgw_zonegroup_id + type: str + level: advanced + desc: Zonegroup ID + services: + - rgw + see_also: + - rgw_zone + - rgw_zonegroup + - rgw_realm - name: rgw_zonegroup_root_pool type: str level: advanced @@ -1278,6 +1298,11 @@ options: services: - rgw with_legacy: true +- name: rgw_realm_id + type: str + level: advanced + services: + - rgw - name: rgw_realm_root_pool type: str level: advanced diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 6350e49315c..6f3dae8400e 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -3135,6 +3135,14 @@ static string safe_opt(std::optional& os) return os.value_or(string()); } +void init_realm_param(CephContext *cct, string& var, std::optional& opt_var, const string& conf_name) +{ + var = cct->_conf.get_val(conf_name); + if (!var.empty()) { + opt_var = var; + } +} + int main(int argc, const char **argv) { vector args; @@ -3156,8 +3164,6 @@ int main(int argc, const char **argv) g_conf().set_val_or_die("rgw_zonegroup", g_conf()->rgw_region.c_str()); } - common_init_finish(g_ceph_context); - rgw_user user_id_arg; std::unique_ptr user; string tenant; @@ -3366,6 +3372,10 @@ int main(int argc, const char **argv) std::optional rgw_obj_fs; // radoslist field separator + init_realm_param(cct.get(), realm_id, opt_realm_id, "rgw_realm_id"); + init_realm_param(cct.get(), zonegroup_id, opt_zonegroup_id, "rgw_zonegroup_id"); + init_realm_param(cct.get(), zone_id, opt_zone_id, "rgw_zone_id"); + for (std::vector::iterator i = args.begin(); i != args.end(); ) { if (ceph_argparse_double_dash(args, i)) { break; @@ -3632,11 +3642,13 @@ int main(int argc, const char **argv) } else if (ceph_argparse_witharg(args, i, &val, "--realm-id", (char*)NULL)) { realm_id = val; opt_realm_id = val; + g_conf().set_val("rgw_realm_id", val); } else if (ceph_argparse_witharg(args, i, &val, "--realm-new-name", (char*)NULL)) { realm_new_name = val; } else if (ceph_argparse_witharg(args, i, &val, "--zonegroup-id", (char*)NULL)) { zonegroup_id = val; opt_zonegroup_id = val; + g_conf().set_val("rgw_zonegroup_id", val); } else if (ceph_argparse_witharg(args, i, &val, "--zonegroup-new-name", (char*)NULL)) { zonegroup_new_name = val; } else if (ceph_argparse_witharg(args, i, &val, "--placement-id", (char*)NULL)) { @@ -3654,6 +3666,7 @@ int main(int argc, const char **argv) } else if (ceph_argparse_witharg(args, i, &val, "--zone-id", (char*)NULL)) { zone_id = val; opt_zone_id = val; + g_conf().set_val("rgw_zone_id", val); } else if (ceph_argparse_witharg(args, i, &val, "--zone-new-name", (char*)NULL)) { zone_new_name = val; } else if (ceph_argparse_witharg(args, i, &val, "--endpoints", (char*)NULL)) { @@ -3811,6 +3824,9 @@ int main(int argc, const char **argv) } } + /* common_init_finish needs to be called after g_conf().set_val() */ + common_init_finish(g_ceph_context); + if (args.empty()) { usage(); exit(1); diff --git a/src/rgw/rgw_zone.cc b/src/rgw/rgw_zone.cc index 1bb4774fd22..4c4b47b145d 100644 --- a/src/rgw/rgw_zone.cc +++ b/src/rgw/rgw_zone.cc @@ -166,6 +166,10 @@ const string& RGWZoneGroup::get_names_oid_prefix() const return zonegroup_names_oid_prefix; } +string RGWZoneGroup::get_predefined_id(CephContext *cct) const { + return cct->_conf.get_val("rgw_zonegroup_id"); +} + const string& RGWZoneGroup::get_predefined_name(CephContext *cct) const { return cct->_conf->rgw_zonegroup; } @@ -373,6 +377,10 @@ int RGWSystemMetaObj::init(const DoutPrefixProvider *dpp, CephContext *_cct, RGW id = name; } + if (id.empty()) { + id = get_predefined_id(cct); + } + if (id.empty()) { int r; if (name.empty()) { @@ -709,6 +717,10 @@ RGWRemoteMetaLog::~RGWRemoteMetaLog() delete error_logger; } +string RGWRealm::get_predefined_id(CephContext *cct) const { + return cct->_conf.get_val("rgw_realm_id"); +} + const string& RGWRealm::get_predefined_name(CephContext *cct) const { return cct->_conf->rgw_realm; } @@ -1793,6 +1805,10 @@ const string& RGWZoneParams::get_info_oid_prefix(bool old_format) const return zone_info_oid_prefix; } +string RGWZoneParams::get_predefined_id(CephContext *cct) const { + return cct->_conf.get_val("rgw_zone_id"); +} + const string& RGWZoneParams::get_predefined_name(CephContext *cct) const { return cct->_conf->rgw_zone; } diff --git a/src/rgw/rgw_zone.h b/src/rgw/rgw_zone.h index 453f09b92c8..c167dd4d73e 100644 --- a/src/rgw/rgw_zone.h +++ b/src/rgw/rgw_zone.h @@ -151,6 +151,7 @@ public: virtual const std::string get_default_oid(bool old_format = false) const = 0; virtual const std::string& get_names_oid_prefix() const = 0; virtual const std::string& get_info_oid_prefix(bool old_format = false) const = 0; + virtual std::string get_predefined_id(CephContext *cct) const = 0; virtual const std::string& get_predefined_name(CephContext *cct) const = 0; void dump(Formatter *f) const; @@ -399,6 +400,7 @@ struct RGWZoneParams : RGWSystemMetaObj { const std::string get_default_oid(bool old_format = false) const override; const std::string& get_names_oid_prefix() const override; const std::string& get_info_oid_prefix(bool old_format = false) const override; + std::string get_predefined_id(CephContext *cct) const override; const std::string& get_predefined_name(CephContext *cct) const override; int init(const DoutPrefixProvider *dpp, @@ -831,6 +833,7 @@ struct RGWZoneGroup : public RGWSystemMetaObj { const std::string get_default_oid(bool old_region_format = false) const override; const std::string& get_info_oid_prefix(bool old_region_format = false) const override; const std::string& get_names_oid_prefix() const override; + std::string get_predefined_id(CephContext *cct) const override; const std::string& get_predefined_name(CephContext *cct) const override; void dump(Formatter *f) const; @@ -984,6 +987,7 @@ public: const std::string get_default_oid(bool old_format = false) const override; const std::string& get_names_oid_prefix() const override; const std::string& get_info_oid_prefix(bool old_format = false) const override; + std::string get_predefined_id(CephContext *cct) const override; const std::string& get_predefined_name(CephContext *cct) const override; using RGWSystemMetaObj::read_id; // expose as public for radosgw-admin -- 2.47.3