diff --git a/sat/cli/bootprep/input/base.py b/sat/cli/bootprep/input/base.py index 3b73516d..1ee242e1 100644 --- a/sat/cli/bootprep/input/base.py +++ b/sat/cli/bootprep/input/base.py @@ -108,14 +108,25 @@ def wrapper(self, *args, **kwargs): # Default to no additional context if not set context = getattr(self, 'jinja_context', {}) - try: - return self.jinja_env.from_string(unrendered_result).render(context) - except SecurityError as err: - raise error_cls(f'Jinja2 template {unrendered_result} for value ' - f'{func.__name__} tried to access unsafe attributes.') from err - except TemplateError as err: - raise error_cls(f'Failed to render Jinja2 template {unrendered_result} ' - f'for value {func.__name__}: {err}') from err + def render_object(obj): + """Render an object with the given context.""" + if isinstance(obj, str): + try: + return self.jinja_env.from_string(obj).render(context) + except SecurityError as err: + raise error_cls(f'Jinja2 template {obj} for value ' + f'{func.__name__} tried to access unsafe attributes.') from err + except TemplateError as err: + raise error_cls(f'Failed to render Jinja2 template {obj} ' + f'for value {func.__name__}: {err}') from err + elif isinstance(obj, dict): + return {key: render_object(value) for key, value in obj.items()} + elif isinstance(obj, list): + return [render_object(item) for item in obj] + else: + return obj + + return render_object(unrendered_result) return wrapper @@ -242,11 +253,6 @@ def name(self): # items that inherit from BaseInputItem. return self.data['name'] - @property - def boot_set(self): - """Return the full boot_sets dictionary.""" - return self.data.get('bos_parameters', {}).get('boot_sets', {}) - def __str__(self): # Since the name can be rendered, and when unrendered, it does not need # to be unique, just refer to this item by its index in the instance. diff --git a/sat/cli/bootprep/input/session_template.py b/sat/cli/bootprep/input/session_template.py index 7febcb02..4fc48353 100644 --- a/sat/cli/bootprep/input/session_template.py +++ b/sat/cli/bootprep/input/session_template.py @@ -98,6 +98,7 @@ def configuration(self): return self.data['configuration'] @property + @jinja_rendered def boot_sets(self): """dict: the boot sets specified for the session template""" # the 'bos_parameters' property is required, and 'boot_sets' is required within that @@ -186,12 +187,6 @@ def get_create_item_data(self): boot_set_api_data.update(boot_set_data) api_data['boot_sets'][boot_set_name] = boot_set_api_data - # Fetch full boot sets - boot_sets = self.boot_set - # Render the rootfs_provider_passthrough using Jinja2 - rendered_rootfs = self.jinja_env.from_string( - boot_sets[boot_set_name]['rootfs_provider_passthrough']).render(self.data) - api_data['boot_sets'][boot_set_name]['rootfs_provider_passthrough'] = rendered_rootfs return api_data def get_image_record_by_id(self, ims_image_id):