actions: retrieve dashboard URL

Allow sunbeam to retrieve the public ingress URL for the
dashboard to avoid the user having to use juju commands
to interrogate the model directly.

Change-Id: Ia35f66ecfd282c70f329d955413fa26f464a08a2
This commit is contained in:
James Page 2023-05-22 14:30:52 +01:00
parent ae4c56bacf
commit be89e68454
4 changed files with 22 additions and 2 deletions

View File

@ -1,2 +1,2 @@
# NOTE: no actions yet!
{ }
get-dashboard-url:
description: URL for access to the Horizon OpenStack Dashboard.

View File

@ -84,6 +84,17 @@ class OpenstackDashboardOperatorCharm(sunbeam_charm.OSBaseOperatorAPICharm):
"identity-credentials",
}
def __init__(self, framework):
super().__init__(framework)
self.framework.observe(
self.on.get_dashboard_url_action,
self._get_dashboard_url_action,
)
def _get_dashboard_url_action(self, event):
"""Retrieve the URL for the Horizon OpenStack Dashboard."""
event.set_results({"url": self.public_url})
@property
def default_public_ingress_port(self):
"""Default public ingress port."""

View File

@ -0,0 +1 @@
../actions.yaml

View File

@ -110,3 +110,11 @@ class TestDashboardOperatorCharm(test_utils.CharmTestCase):
self.check_file(
"openstack-dashboard", "/etc/openstack-dashboard/local_settings.py"
)
def test_get_dashboard_url_action(self):
"""Test admin account action."""
action_event = mock.MagicMock()
self.harness.charm._get_dashboard_url_action(action_event)
action_event.set_results.assert_called_with(
{"url": "http://dashboard.juju:80"}
)