Skip to content

Commit

Permalink
Add support for external modules
Browse files Browse the repository at this point in the history
This commmit adds support to define and use external modules for custom migration steps.

Signed-off-by: Tobias Wolf <[email protected]>
  • Loading branch information
NotTheEvilOne authored Sep 10, 2024
1 parent eca2435 commit 24ff45e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ LABEL org.opencontainers.image.source="https://github.com/SovereignCloudStack/ro

ARG ROOKIFY_VERSION=0.0.0.dev1
ENV ROOKIFY_VERSION=$ROOKIFY_VERSION
ENV PYTHONPATH="${PYTHONPATH}:/app/rookify/src"

WORKDIR /app/rookify

Expand Down
16 changes: 15 additions & 1 deletion src/rookify/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ def _load_module(machine: Machine, config: Dict[str, Any], module_name: str) ->
:return: returns tuple of preflight_modules, modules
"""

module = importlib.import_module("rookify.modules.{0}".format(module_name))
if "." in module_name:
absolute_module_name = module_name
else:
absolute_module_name = "rookify.modules.{0}".format(module_name)

try:
module = importlib.import_module(absolute_module_name)
except ModuleNotFoundError as e:
raise ModuleLoadException(module_name, str(e))

additional_modules = []

if not hasattr(module, "ModuleHandler") or not callable(
Expand Down Expand Up @@ -63,6 +72,11 @@ def load_modules(machine: Machine, config: Dict[str, Any]) -> None:
migration_modules.remove(entry.name)
_load_module(machine, config, entry.name)

for migration_module in migration_modules.copy():
if "." in migration_module:
migration_modules.remove(migration_module)
_load_module(machine, config, migration_module)

if len(migration_modules) > 0 or len(config["migration_modules"]) < 1:
logger = get_logger()

Expand Down

0 comments on commit 24ff45e

Please sign in to comment.