def __init__(self, cleaned_data, version, fqn, forms=None, templates=None, application=None, **kwargs): self.cleaned_data = cleaned_data self.templates = templates or {} self.spec_version = str(version) if application is None: raise ValueError('Application section is required') else: self.application = application self.context = legacy.create_context() yaql_functions.register(self.context) self.forms = [] for key, value in six.iteritems(kwargs): setattr(self, key, value) if forms: for counter, data in enumerate(forms): name, field_specs, validators = self.extract_form_data(data) self._add_form(name, field_specs, validators) # Add ManageWorkflowForm workflow_form = catalog_forms.WorkflowManagementForm() if semantic_version.Version.coerce(self.spec_version) >= \ semantic_version.Version.coerce('2.2'): app_name_field = workflow_form.name_field(fqn) workflow_form.field_specs.insert(0, app_name_field) self._add_form(workflow_form.name, workflow_form.field_specs, workflow_form.validators)
def __init__(self, *args, **kwargs): LOG.info("Creating form {0}".format(self.__class__.__name__)) super(ServiceConfigurationForm, self).__init__(*args, **kwargs) self.auto_id = '{0}_%s'.format(self.initial.get('app_id')) self.context = legacy.create_context() yaql_functions.register(self.context) self.finalize_fields() self.update_fields()
def __init__(self, cleaned_data, version, fqn, forms=None, templates=None, application=None, parameters=None, **kwargs): self.cleaned_data = cleaned_data self.templates = templates or {} self.spec_version = str(version) if forms is None: forms = [] if application is None: raise ValueError('Application section is required') else: self.application = application self.context = legacy.create_context() self.context['?service'] = self yaql_functions.register(self.context) params = parameters or {} self.parameters = {} for k, v in six.iteritems(params): if not k or not k[0].isalpha(): continue v = helpers.evaluate(v, self.context) self.parameters[k] = v self.context[k] = v self.forms = [] for key, value in six.iteritems(kwargs): setattr(self, key, value) for form in forms: (name, field_specs, validators, region) = self.extract_form_data(form) # NOTE(kzaitsev) should be str (not unicode) under python2 # however it also works as str under python3 name = helpers.to_str(name) self._add_form(name, field_specs, validators, region) # Add ManageWorkflowForm workflow_form = catalog_forms.WorkflowManagementForm() if semantic_version.Version.coerce(self.spec_version) >= \ semantic_version.Version.coerce('2.2'): app_name_field = workflow_form.name_field(fqn) workflow_form.field_specs.insert(0, app_name_field) self._add_form(workflow_form.name, workflow_form.field_specs, workflow_form.validators)
def validator_func(value): context = legacy.create_context() context['$'] = value if not expr.evaluate(context=context): raise forms.ValidationError(message)
_add_operators(engine_factory=engine_factory) options = (ENGINE_10_OPTIONS if runtime_version <= constants.RUNTIME_VERSION_1_1 else ENGINE_12_OPTIONS) return engine_factory.create(options=options) @specs.name('#finalize') def _finalize(obj, context): return helpers.evaluate(obj, context) CONVENTION = conventions.CamelCaseConvention() ENGINE_10 = _create_engine(constants.RUNTIME_VERSION_1_0) ENGINE_12 = _create_engine(constants.RUNTIME_VERSION_1_2) ROOT_CONTEXT_10 = legacy.create_context(convention=CONVENTION, finalizer=_finalize) ROOT_CONTEXT_12 = yaql.create_context(convention=CONVENTION, finalizer=_finalize) class ContractedValue(yaqltypes.GenericType): def __init__(self, value_spec, with_check=False): def converter(value, receiver, context, *args, **kwargs): if isinstance(receiver, dsl_types.MuranoObject): this = receiver.real_this else: this = receiver return value_spec.transform(value, this, context[constants.CTX_ARGUMENT_OWNER], context)
engine_factory = factory.YaqlFactory() _add_operators(engine_factory=engine_factory) options = (ENGINE_10_OPTIONS if runtime_version <= constants.RUNTIME_VERSION_1_1 else ENGINE_12_OPTIONS) return engine_factory.create(options=options) @specs.name('#finalize') def _finalize(obj, context): return helpers.evaluate(obj, context) CONVENTION = conventions.CamelCaseConvention() ENGINE_10 = _create_engine(constants.RUNTIME_VERSION_1_0) ENGINE_12 = _create_engine(constants.RUNTIME_VERSION_1_2) ROOT_CONTEXT_10 = legacy.create_context( convention=CONVENTION, finalizer=_finalize) ROOT_CONTEXT_12 = yaql.create_context( convention=CONVENTION, finalizer=_finalize) class ContractedValue(yaqltypes.GenericType): def __init__(self, value_spec): self._value_spec = value_spec self._last_result = False super(ContractedValue, self).__init__( True, None, lambda value, sender, context, *args, **kwargs: self._value_spec.validate( value, sender.real_this, context[constants.CTX_ARGUMENT_OWNER], context))
def legacy_context(self): if self._legacy_context is None: self._legacy_context = legacy.create_context() return self._legacy_context