Skip to content

Commit 9aacbd1

Browse files
authored
Merge pull request ceph#62596 from rhcs-dashboard/rgw-url
mgr/dashboard: introduce dashboard setting to resolve rgw hostname Reviewed-by: Afreen Misbah <[email protected]> Reviewed-by: Aashish Sharma <[email protected]>
2 parents 44ad32a + 0c50c07 commit 9aacbd1

File tree

6 files changed

+112
-6
lines changed

6 files changed

+112
-6
lines changed

doc/mgr/dashboard.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,19 @@ the host name:
429429

430430
ceph dashboard set-rgw-api-ssl-verify False
431431

432+
To set a custom hostname or address for an RGW gateway, set the value of ``RGW_HOSTNAME_PER_DAEMON``
433+
accordingly:
434+
435+
.. promt:: bash $
436+
437+
ceph dashboard set-rgw-hostname <gateway_name> <hostname>
438+
439+
The setting can be unset using:
440+
441+
.. promt:: bash $
442+
443+
ceph dashboard unset-rgw-hostname <gateway_name>
444+
432445
If the Object Gateway takes too long to process requests and the dashboard runs
433446
into timeouts, you can set the timeout value to your needs:
434447

src/pybind/mgr/dashboard/module.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,24 @@ def set_rgw_credentials(self):
429429

430430
return 0, 'RGW credentials configured', ''
431431

432+
@CLIWriteCommand("dashboard set-rgw-hostname")
433+
def set_rgw_hostname(self, daemon_name: str, hostname: str):
434+
try:
435+
rgw_service_manager = RgwServiceManager()
436+
rgw_service_manager.set_rgw_hostname(daemon_name, hostname)
437+
return 0, f'RGW hostname for daemon {daemon_name} configured', ''
438+
except Exception as error:
439+
return -errno.EINVAL, '', str(error)
440+
441+
@CLIWriteCommand("dashboard unset-rgw-hostname")
442+
def unset_rgw_hostname(self, daemon_name: str):
443+
try:
444+
rgw_service_manager = RgwServiceManager()
445+
rgw_service_manager.unset_rgw_hostname(daemon_name)
446+
return 0, f'RGW hostname for daemon {daemon_name} resetted', ''
447+
except Exception as error:
448+
return -errno.EINVAL, '', str(error)
449+
432450
@CLIWriteCommand("dashboard set-login-banner")
433451
def set_login_banner(self, inbuf: str):
434452
'''

src/pybind/mgr/dashboard/services/rgw_client.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
except ModuleNotFoundError:
2323
logging.error("Module 'xmltodict' is not installed.")
2424

25-
from mgr_util import build_url, name_to_config_section
25+
from mgr_util import build_url
2626

2727
from .. import mgr
2828
from ..awsauth import S3Auth
@@ -100,9 +100,12 @@ def _determine_rgw_addr(daemon_info: Dict[str, Any]) -> RgwDaemon:
100100
Parse RGW daemon info to determine the configured host (IP address) and port.
101101
"""
102102
daemon = RgwDaemon()
103-
rgw_dns_name = CephService.send_command('mon', 'config get',
104-
who=name_to_config_section('rgw.' + daemon_info['metadata']['id']), # noqa E501 #pylint: disable=line-too-long
105-
key='rgw_dns_name').rstrip()
103+
rgw_dns_name = ''
104+
if (
105+
Settings.RGW_HOSTNAME_PER_DAEMON
106+
and daemon_info['metadata']['id'] in Settings.RGW_HOSTNAME_PER_DAEMON
107+
):
108+
rgw_dns_name = Settings.RGW_HOSTNAME_PER_DAEMON[daemon_info['metadata']['id']]
106109

107110
daemon.port, daemon.ssl = _parse_frontend_config(daemon_info['metadata']['frontend_config#0'])
108111

@@ -279,7 +282,9 @@ def _rgw_settings():
279282
return (Settings.RGW_API_ACCESS_KEY,
280283
Settings.RGW_API_SECRET_KEY,
281284
Settings.RGW_API_ADMIN_RESOURCE,
282-
Settings.RGW_API_SSL_VERIFY)
285+
Settings.RGW_API_SSL_VERIFY,
286+
Settings.RGW_HOSTNAME_PER_DAEMON
287+
)
283288

284289
@staticmethod
285290
def instance(userid: Optional[str] = None,

src/pybind/mgr/dashboard/services/service.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,20 @@ def configure_rgw_credentials(self):
204204
except (AssertionError, SubprocessError) as error:
205205
logger.exception(error)
206206
raise NoCredentialsException
207+
208+
def set_rgw_hostname(self, daemon_name: str, hostname: str):
209+
if not Settings.RGW_HOSTNAME_PER_DAEMON:
210+
Settings.RGW_HOSTNAME_PER_DAEMON = {daemon_name: hostname}
211+
return
212+
213+
rgw_hostname_setting = Settings.RGW_HOSTNAME_PER_DAEMON
214+
rgw_hostname_setting[daemon_name] = hostname
215+
Settings.RGW_HOSTNAME_PER_DAEMON = rgw_hostname_setting
216+
217+
def unset_rgw_hostname(self, daemon_name: str):
218+
if not Settings.RGW_HOSTNAME_PER_DAEMON:
219+
return
220+
221+
rgw_hostname_setting = Settings.RGW_HOSTNAME_PER_DAEMON
222+
rgw_hostname_setting.pop(daemon_name, None)
223+
Settings.RGW_HOSTNAME_PER_DAEMON = rgw_hostname_setting

src/pybind/mgr/dashboard/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class Options(object):
6767
RGW_API_SECRET_KEY = Setting('', [dict, str])
6868
RGW_API_ADMIN_RESOURCE = Setting('admin', [str])
6969
RGW_API_SSL_VERIFY = Setting(True, [bool])
70+
RGW_HOSTNAME_PER_DAEMON = Setting('', [dict, str])
7071

7172
# Ceph Issue Tracker API Access Key
7273
ISSUE_TRACKER_API_KEY = Setting('', [str])

src/pybind/mgr/dashboard/tests/test_rgw_client.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
from .. import mgr
88
from ..exceptions import DashboardException
9-
from ..services.rgw_client import NoRgwDaemonsException, RgwClient, _parse_frontend_config
9+
from ..services.rgw_client import NoRgwDaemonsException, RgwClient, \
10+
_determine_rgw_addr, _parse_frontend_config
1011
from ..services.service import NoCredentialsException
1112
from ..settings import Settings
1213
from ..tests import CLICommandTestMixin, RgwStub
@@ -273,6 +274,57 @@ def test_set_bucket_locking_success(self):
273274
retention_period_years=years
274275
))
275276

277+
def test_set_rgw_hostname(self):
278+
result = self.exec_cmd(
279+
'set-rgw-hostname',
280+
daemon_name='test_daemon',
281+
hostname='example.hostname.com'
282+
)
283+
self.assertEqual(
284+
result,
285+
'RGW hostname for daemon test_daemon configured'
286+
)
287+
self.assertEqual(
288+
Settings.RGW_HOSTNAME_PER_DAEMON,
289+
{'test_daemon': 'example.hostname.com'}
290+
)
291+
292+
@patch("dashboard.services.rgw_client.RgwDaemon")
293+
def test_hostname_when_rgw_hostname_config_is_set(self, mock_daemons):
294+
mock_instance = Mock()
295+
mock_daemons.return_value = mock_instance
296+
297+
self.test_set_rgw_hostname()
298+
299+
daemon_info = {
300+
'metadata': {
301+
'id': 'test_daemon',
302+
'hostname': 'my-hostname.com',
303+
'frontend_config#0': 'beast port=8000'
304+
},
305+
'addr': '192.0.2.1'
306+
}
307+
308+
result = _determine_rgw_addr(daemon_info)
309+
self.assertEqual(result.host, "example.hostname.com")
310+
311+
@patch("dashboard.services.rgw_client.RgwDaemon")
312+
def test_hostname_when_rgw_hostname_config_is_not_set(self, mock_daemons):
313+
mock_instance = Mock()
314+
mock_daemons.return_value = mock_instance
315+
316+
daemon_info = {
317+
'metadata': {
318+
'id': 'test_daemon',
319+
'hostname': 'my.hostname.com',
320+
'frontend_config#0': 'beast port=8000'
321+
},
322+
'addr': '192.168.178.3:49774/1534999298'
323+
}
324+
325+
result = _determine_rgw_addr(daemon_info)
326+
self.assertEqual(result.host, "192.168.178.3")
327+
276328

277329
class RgwClientHelperTest(TestCase):
278330
def test_parse_frontend_config_1(self):

0 commit comments

Comments
 (0)