From bee7873ecb70f9f7d94d9798a61d11632e64e77f Mon Sep 17 00:00:00 2001 From: Siteshwar Vashisht Date: Thu, 14 Mar 2024 16:28:01 +0100 Subject: [PATCH] Agent spawner configurations should be accessible ... as attributes. Signed-off-by: Siteshwar Vashisht --- resalloc_agent_spawner/helpers.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/resalloc_agent_spawner/helpers.py b/resalloc_agent_spawner/helpers.py index 1e25cae..452d380 100644 --- a/resalloc_agent_spawner/helpers.py +++ b/resalloc_agent_spawner/helpers.py @@ -37,7 +37,17 @@ def get_config(): group.setdefault("cmd_terminate", "/bin/true") group.setdefault("cmd_try_release", "/bin/false") group.setdefault("tags", ["please-specify-some-tags"]) - return config + + # This dictionary is passed to redis APIs and other parts of code which + # expects configurations to be attributes rather than key/value pairs. + # This class works around this requirement. + # Thanks to https://stackoverflow.com/a/14620633 + class AttrDict(dict): + def __init__(self, *args, **kwargs): + super(AttrDict, self).__init__(*args, **kwargs) + self.__dict__ = self + + return AttrDict(config) class CmdCallerMixin: