diff --git a/controller/controller_interface.py b/controller/controller_interface.py new file mode 100644 index 0000000..b18f14c --- /dev/null +++ b/controller/controller_interface.py @@ -0,0 +1,17 @@ +"""Module providing functions to interact with the drunc controller.""" + +from django.conf import settings +from drunc.controller.controller_driver import ControllerDriver +from drunc.utils.shell_utils import create_dummy_token_from_uname +from druncschema.request_response_pb2 import Description + + +def get_controller_driver() -> ControllerDriver: + """Get a ControllerDriver instance.""" + token = create_dummy_token_from_uname() + return ControllerDriver(settings.ROOT_CONTROLLER_URL, token=token, aio_channel=True) + + +def get_controller_status() -> Description: + """Get the controller status.""" + return get_controller_driver().get_status() diff --git a/drunc_ui/settings/settings.py b/drunc_ui/settings/settings.py index 919f8e4..fce7fb2 100644 --- a/drunc_ui/settings/settings.py +++ b/drunc_ui/settings/settings.py @@ -147,6 +147,7 @@ DJANGO_TABLES2_TEMPLATE = "django_tables2/bootstrap5.html" PROCESS_MANAGER_URL = os.getenv("PROCESS_MANAGER_URL", "localhost:10054") +ROOT_CONTROLLER_URL = os.getenv("ROOT_CONTROLLER_URL", "localhost:3333") INSTALLED_APPS += ["crispy_forms", "crispy_bootstrap5"] CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5" diff --git a/scripts/talk_to_controller.py b/scripts/talk_to_controller.py new file mode 100644 index 0000000..a330de3 --- /dev/null +++ b/scripts/talk_to_controller.py @@ -0,0 +1,20 @@ +"""Example script used to check communication with the controller. + +This is intended to be run within docker from the `app` service, i.e.: + +``` +docker compose exec app python scripts/talk_to_controller.py +``` + +and provides a basic proof of principle of communicating with the controller via +gRPC. +""" + +from drunc.controller.controller_driver import ControllerDriver +from drunc.utils.shell_utils import create_dummy_token_from_uname + +if __name__ == "__main__": + token = create_dummy_token_from_uname() + controller = ControllerDriver("drunc:3333", token=token, aio_channel=True) + val = controller.get_status() + print(val) diff --git a/tests/controller/test_controller_interface.py b/tests/controller/test_controller_interface.py new file mode 100644 index 0000000..8b5d713 --- /dev/null +++ b/tests/controller/test_controller_interface.py @@ -0,0 +1,7 @@ +def test_get_controller_status(mocker): + """Test the _boot_process function.""" + from controller.controller_interface import get_controller_status + + mock = mocker.patch("controller.controller_interface.get_controller_driver") + get_controller_status() + mock.assert_called_once()