diff --git a/actions.yaml b/actions.yaml index 88e6195..5756cbf 100644 --- a/actions.yaml +++ b/actions.yaml @@ -1,2 +1,2 @@ -# NOTE: no actions yet! -{ } +get-southbound-db-url: + description: Southbound DB Connection URL for access to OVN via the relay. diff --git a/src/charm.py b/src/charm.py index b362ca7..93a231f 100755 --- a/src/charm.py +++ b/src/charm.py @@ -25,7 +25,9 @@ develop a new k8s charm using the Operator Framework: """ import logging -from typing import List, Mapping + +from ipaddress import IPv4Address, IPv6Address +from typing import List, Mapping, Union from ops.framework import StoredState from ops.main import main @@ -87,8 +89,27 @@ class OVNRelayOperatorCharm(ovn_charm.OSBaseOVNOperatorCharm): self, [ ('southbound', 6642), - ] + ], + service_type="LoadBalancer" ) + self.framework.observe( + self.on.get_southbound_db_url_action, + self._get_southbound_db_url_action + ) + + def _get_southbound_db_url_action(self, event): + event.set_results({"url": self.southbound_db_url}) + + @property + def ingress_address(self) -> Union[IPv4Address, IPv6Address]: + """Network IP address for access to the OVN relay service.""" + return self.model.get_binding( + 'ovsdb-cms-relay').network.ingress_addresses[0] + + @property + def southbound_db_url(self) -> str: + """Full connection URL for Southbound DB relay.""" + return f"ssl:{self.ingress_address}:6442" def get_pebble_handlers(self): pebble_handlers = [ diff --git a/tests/actions.yaml b/tests/actions.yaml new file mode 120000 index 0000000..9adaf92 --- /dev/null +++ b/tests/actions.yaml @@ -0,0 +1 @@ +../actions.yaml \ No newline at end of file diff --git a/tests/unit/test_ovn_relay_charm.py b/tests/unit/test_ovn_relay_charm.py index d310015..c8c7a74 100644 --- a/tests/unit/test_ovn_relay_charm.py +++ b/tests/unit/test_ovn_relay_charm.py @@ -63,3 +63,9 @@ class TestOVNRelayXenaOperatorCharm(test_utils.CharmTestCase): '/root/ovn-relay-wrapper.sh'] for f in ovsdb_config_files: self.check_file('ovsdb-server', f) + + def test_southbound_db_url(self): + self.assertEqual( + 'ssl:10.0.0.10:6442', + self.harness.charm.southbound_db_url + )