From: Yehuda Sadeh Date: Tue, 29 Jun 2021 22:42:25 +0000 (-0700) Subject: rgw, rgw-admin: add realm/zonegroup/zone id configurables X-Git-Tag: v17.1.0~1137^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F42122%2Fhead;p=ceph.git 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 --- diff --git a/src/common/options/rgw.yaml.in b/src/common/options/rgw.yaml.in index c7498481d198..cde28e0b64fb 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 6350e49315c1..6f3dae8400e7 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 1bb4774fd221..4c4b47b145dc 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 453f09b92c8d..c167dd4d73e5 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