diff --git a/charms/horizon-k8s/actions.yaml b/charms/horizon-k8s/actions.yaml index 88e6195d..6d1a31bb 100644 --- a/charms/horizon-k8s/actions.yaml +++ b/charms/horizon-k8s/actions.yaml @@ -1,2 +1,2 @@ -# NOTE: no actions yet! -{ } +get-dashboard-url: + description: URL for access to the Horizon OpenStack Dashboard. diff --git a/charms/horizon-k8s/src/charm.py b/charms/horizon-k8s/src/charm.py index 92fc9215..78fb388a 100755 --- a/charms/horizon-k8s/src/charm.py +++ b/charms/horizon-k8s/src/charm.py @@ -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.""" diff --git a/charms/horizon-k8s/tests/actions.yaml b/charms/horizon-k8s/tests/actions.yaml new file mode 120000 index 00000000..9adaf92e --- /dev/null +++ b/charms/horizon-k8s/tests/actions.yaml @@ -0,0 +1 @@ +../actions.yaml \ No newline at end of file diff --git a/charms/horizon-k8s/tests/unit/test_dashboard_charm.py b/charms/horizon-k8s/tests/unit/test_dashboard_charm.py index c8016789..9600ee63 100644 --- a/charms/horizon-k8s/tests/unit/test_dashboard_charm.py +++ b/charms/horizon-k8s/tests/unit/test_dashboard_charm.py @@ -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"} + )