aria.modeling¶
This package provides an API for modeling ARIA’s state and serializing it to storage.
aria.modeling.constraints¶
Constraints for the requirements-and-capabilities matching mechanism.
aria.modeling.exceptions¶
Modeling exceptions.
-
exception
aria.modeling.exceptions.CannotEvaluateFunctionException(message=None, cause=None, cause_traceback=None)¶ Bases:
aria.modeling.exceptions.ModelingExceptionARIA modeling exception: cannot evaluate the function at this time.
-
exception
aria.modeling.exceptions.MissingRequiredParametersException(message=None, cause=None, cause_traceback=None)¶ Bases:
aria.modeling.exceptions.ParameterExceptionARIA modeling exception: Required parameters have been omitted.
-
exception
aria.modeling.exceptions.ModelingException(message=None, cause=None, cause_traceback=None)¶ Bases:
aria.exceptions.AriaExceptionARIA modeling exception.
-
exception
aria.modeling.exceptions.ParameterException(message=None, cause=None, cause_traceback=None)¶ Bases:
aria.modeling.exceptions.ModelingExceptionARIA parameter exception.
-
exception
aria.modeling.exceptions.ParametersOfWrongTypeException(message=None, cause=None, cause_traceback=None)¶ Bases:
aria.modeling.exceptions.ParameterExceptionARIA modeling exception: Parameters of the wrong types have been provided.
-
exception
aria.modeling.exceptions.UndeclaredParametersException(message=None, cause=None, cause_traceback=None)¶ Bases:
aria.modeling.exceptions.ParameterExceptionARIA modeling exception: Undeclared parameters have been provided.
-
exception
aria.modeling.exceptions.ValueFormatException(message=None, cause=None, cause_traceback=None)¶ Bases:
aria.modeling.exceptions.ModelingExceptionARIA modeling exception: the value is in the wrong format.
aria.modeling.functions¶
Mechanism for evaluating intrinsic functions.
-
class
aria.modeling.functions.Evaluation(value, final=False)¶ Bases:
objectAn evaluated
Functionreturn value.Variables: - value – evaluated value
- final (boolean) – whether the value is final
-
class
aria.modeling.functions.Function¶ Bases:
objectBase class for intrinsic functions. Serves as a placeholder for a value that should eventually be derived by “evaluating” (calling) the function.
Note that this base class is provided as a convenience and you do not have to inherit it: any object with an
__evaluate__method would be treated similarly.-
__evaluate__(container_holder)¶ Evaluates the function if possible.
Return type: Evaluation(or any object withvalueandfinalproperties)Raises: CannotEvaluateFunctionException – if cannot be evaluated at this time (do not just return None)
-
as_raw¶
-
-
aria.modeling.functions.evaluate(value, container_holder, report_issues=False)¶ Recursively attempts to call
__evaluate__. If an evaluation occurred will return anEvaluation, otherwise it will beNone. If any evaluation is non-final, then the entire evaluation will also be non-final.The
container_holderargument should have three properties:containershould return the model that contains the value,serviceshould return the containingServicemodel or None, andservice_templateshould return the containingServiceTemplatemodel orNone.
aria.modeling.mixins¶
ARIA modeling mix-ins module
-
class
aria.modeling.mixins.InstanceModelMixin¶ Bases:
aria.modeling.mixins.ModelMixinMix-in for service instance models.
All models support validation, diagnostic dumping, and representation as raw data (which can be translated into JSON or YAML) via
as_raw().-
as_raw¶
-
coerce_values(report_issues)¶
-
dump()¶
-
validate()¶
-
-
class
aria.modeling.mixins.ModelIDMixin¶ Bases:
object-
id= Column(None, Integer(), table=None, primary_key=True, nullable=False)¶
-
classmethod
id_column_name()¶
-
name= Column(None, Text(), table=None)¶
-
classmethod
name_column_name()¶
-
-
class
aria.modeling.mixins.ModelMixin¶ Bases:
object-
classmethod
fields()¶ List of field names for this table.
Mostly for backwards compatibility in the code (that uses
fields).
-
classmethod
id_column_name()¶
-
classmethod
name_column_name()¶
-
to_dict(fields=None, suppress_error=False)¶ Create a dict representation of the model.
Parameters: suppress_error – if set to True, setsNoneto attributes that it’s unable to retrieve (e.g., if a relationship wasn’t established yet, and so it’s impossible to access a property through it)
-
classmethod
-
class
aria.modeling.mixins.ParameterMixin(method_cache=None)¶ Bases:
aria.modeling.mixins.TemplateModelMixin,aria.utils.caching.HasCachedMethodsMix-in for typed values. The value can contain nested intrinsic functions.
This model can be used as the
container_holderargument forevaluate().-
as_argument()¶
-
as_other_parameter_model(other_model_cls)¶
-
as_raw¶
-
coerce_values(report_issues)¶
-
container¶ The logical container for this parameter, which would be another model: service, node, group, or policy (or their templates).
The logical container is equivalent to the
SELFkeyword used by intrinsic functions in TOSCA.All parameters should have a container model.
Raises: ValueError – if failed to find a container model, which signifies an abnormal, orphaned parameter
-
description= Column(None, Text(), table=None)¶
-
dump()¶
-
instantiate(container)¶
-
owner¶ The sole owner of this parameter, which is another model that relates to it.
All parameters should have an owner model.
Raises: ValueError – if failed to find an owner, which signifies an abnormal, orphaned parameter
-
service¶ The
Servicemodel containing this parameter, orNoneif not contained in a service.Raises: ValueError – if failed to find a container model, which signifies an abnormal, orphaned parameter
-
service_template¶ The
ServiceTemplatemodel containing this parameter, orNoneif not contained in a service template.Raises: ValueError – if failed to find a container model, which signifies an abnormal, orphaned parameter
-
type_name= Column(None, Text(), table=None)¶
-
unwrapped¶
-
value¶
-
classmethod
wrap(name, value, description=None)¶ Wraps an arbitrary value as a parameter. The type will be guessed via introspection.
For primitive types, we will prefer their TOSCA aliases. See the TOSCA Simple Profile v1.0 cos01 specification
Parameters: - name (basestring) – parameter name
- value – parameter value
- description (basestring) – human-readable description (optional)
-
-
class
aria.modeling.mixins.TemplateModelMixin¶ Bases:
aria.modeling.mixins.InstanceModelMixinMix-in for service template models.
All model models can be instantiated into service instance models.
-
instantiate(container)¶
-
aria.modeling.relationship¶
ARIA modeling relationship module
-
aria.modeling.relationship.association_proxy(*args, **kwargs)¶
-
aria.modeling.relationship.foreign_key(other_table, nullable=False)¶ Declare a foreign key property, which will also create a foreign key column in the table with the name of the property. By convention the property name should end in “_fk”.
You are required to explicitly create foreign keys in order to allow for one-to-one, one-to-many, and many-to-one relationships (but not for many-to-many relationships). If you do not do so, SQLAlchemy will fail to create the relationship property and raise an exception with a clear error message.
You should normally not have to access this property directly, but instead use the associated relationship properties.
This utility method should only be used during class creation.
Parameters: - other_table (basestring) – other table name
- nullable (bool) –
Trueto allow null values (meaning that there is no relationship)
-
aria.modeling.relationship.many_to_many(model_class, other_table=None, prefix=None, dict_key=None, other_property=None, self=False)¶ Declare a many-to-many relationship property. The property value would be a list or dict of instances of the other table’s model.
You do not need associated foreign keys for this relationship. Instead, an extra table will be created for you.
The declaration will automatically create a matching many-to-many property at the other model, named after the plural form of our table name. Use the
other_propertyargument to override this name. Note: the automatic property will always be a SQLAlchemy query object; if you need a Python collection then usemany_to_many()again at that model.This utility method should only be used during class creation.
Parameters: - model_class (type) – class in which this relationship will be declared
- other_table (basestring) – parent table name
- prefix (basestring) – optional prefix for extra table name as well as for
other_property - dict_key (basestring) – if set the value will be a dict with this key as the dict key; otherwise will be a list
- other_property (basestring or bool) – override name of matching many-to-many property at other table; set to
Falseto disable - self (bool) – used for relationships between a table and itself. if set, other_table will become the same as the source table.
-
aria.modeling.relationship.many_to_one(model_class, parent_table, fk=None, parent_fk=None, back_populates=None)¶ Declare a many-to-one relationship property. The property value would be an instance of the parent table’s model.
You will need an associated foreign key to the parent table.
The declaration will automatically create a matching one-to-many property at the child model, named after the plural form of our table name. Use the
parent_propertyargument to override this name. Note: the automatic property will always be a SQLAlchemy query object; if you need a Python collection then useone_to_many()at that model.This utility method should only be used during class creation.
Parameters: - model_class (type) – class in which this relationship will be declared
- parent_table (basestring) – parent table name
- fk (basestring) – foreign key name at our table (no need specify if there’s no ambiguity)
- back_populates (basestring or bool) – override name of matching one-to-many property at parent table; set to
Falseto disable
-
aria.modeling.relationship.one_to_many(model_class, other_table=None, other_fk=None, dict_key=None, back_populates=None, rel_kwargs=None, self=False)¶ Declare a one-to-many relationship property. The property value would be a list or dict of instances of the child table’s model.
The child table will need an associated foreign key to our table.
The declaration will automatically create a matching many-to-one property at the child model, named after our table name. Use the
child_propertyargument to override this name.This utility method should only be used during class creation.
Parameters: - model_class (type) – class in which this relationship will be declared
- other_table (basestring) – other table name
- other_fk (basestring) – foreign key name at the other table (no need specify if there’s no ambiguity)
- dict_key (basestring) – if set the value will be a dict with this key as the dict key; otherwise will be a list
- back_populates (basestring or bool) – override name of matching many-to-one property at other table; set to
Falseto disable - rel_kwargs (dict) – additional relationship kwargs to be used by SQLAlchemy
- self (bool) – used for relationships between a table and itself. if set, other_table will become the same as the source table.
-
aria.modeling.relationship.one_to_one(model_class, other_table, fk=None, other_fk=None, back_populates=None)¶ Declare a one-to-one relationship property. The property value would be an instance of the other table’s model.
You have two options for the foreign key. Either this table can have an associated key to the other table (use the
fkargument) or the other table can have an associated foreign key to this our table (use theother_fkargument).This utility method should only be used during class creation.
Parameters: - model_class (type) – class in which this relationship will be declared
- other_table (basestring) – other table name
- fk (basestring) – foreign key name at our table (no need specify if there’s no ambiguity)
- other_fk (basestring) – foreign key name at the other table (no need specify if there’s no ambiguity)
- back_populates (basestring or bool) – override name of matching many-to-many property at other table; set to
Falseto disable
-
aria.modeling.relationship.one_to_one_self(model_class, fk)¶ Declare a one-to-one relationship property. The property value would be an instance of the same model.
You will need an associated foreign key to our own table.
This utility method should only be used during class creation.
Parameters: - model_class (type) – class in which this relationship will be declared
- fk (basestring) – foreign key name
aria.modeling.types¶
Allows JSON-serializable collections to be used as SQLAlchemy column types.
-
class
aria.modeling.types.Dict(*args, **kwargs)¶ Bases:
aria.modeling.types._MutableTypeJSON-serializable dict type for SQLAlchemy columns.
Construct a
TypeDecorator.Arguments sent here are passed to the constructor of the class assigned to the
implclass level attribute, assuming theimplis a callable, and the resulting object is assigned to theself.implinstance attribute (thus overriding the class attribute of the same name).If the class level
implis not a callable (the unusual case), it will be assigned to the same instance attribute ‘as-is’, ignoring those arguments passed to the constructor.Subclasses can override this to customize the generation of
self.implentirely.-
python_type¶
-
-
class
aria.modeling.types.List(*args, **kwargs)¶ Bases:
aria.modeling.types._MutableTypeJSON-serializable list type for SQLAlchemy columns.
Construct a
TypeDecorator.Arguments sent here are passed to the constructor of the class assigned to the
implclass level attribute, assuming theimplis a callable, and the resulting object is assigned to theself.implinstance attribute (thus overriding the class attribute of the same name).If the class level
implis not a callable (the unusual case), it will be assigned to the same instance attribute ‘as-is’, ignoring those arguments passed to the constructor.Subclasses can override this to customize the generation of
self.implentirely.-
python_type¶
-
-
aria.modeling.types.StrictDict= <aria.modeling.types._StrictDict object>¶ JSON-serializable strict dict type for SQLAlchemy columns.
Parameters: - key_cls –
- value_cls –
-
aria.modeling.types.StrictList= <aria.modeling.types._StrictList object>¶ JSON-serializable strict list type for SQLAlchemy columns.
Parameters: item_cls –
aria.modeling.utils¶
Miscellaneous modeling utilities.
-
class
aria.modeling.utils.ModelJSONEncoder(*args, **kwargs)¶ Bases:
json.encoder.JSONEncoderJSON encoder that automatically unwraps
valueattributes.-
default(o)¶
-
-
class
aria.modeling.utils.NodeTemplateContainerHolder(node_template)¶ Bases:
objectWrapper that allows using a
NodeTemplatemodel directly as thecontainer_holderinput forevaluate().-
service_template¶
-
-
aria.modeling.utils.coerce_dict_values(the_dict, report_issues=False)¶
-
aria.modeling.utils.coerce_list_values(the_list, report_issues=False)¶
-
aria.modeling.utils.dump_dict_values(the_dict, name)¶
-
aria.modeling.utils.dump_interfaces(interfaces, name=’Interfaces’)¶
-
aria.modeling.utils.dump_list_values(the_list, name)¶
-
aria.modeling.utils.fix_doc(cls)¶ Class decorator to use the last base class’s docstring and make sure Sphinx doesn’t grab the base constructor’s docstring.
-
aria.modeling.utils.instantiate_dict(container, the_dict, from_dict)¶
-
aria.modeling.utils.instantiate_list(container, the_list, from_list)¶
-
aria.modeling.utils.merge_parameter_values(parameter_values, declared_parameters, model_cls)¶ Merges parameter values according to those declared by a type.
Exceptions will be raised for validation errors.
Parameters: - parameter_values ({
basestring: object}) – provided parameter values or None - declared_parameters ({
basestring:Parameter}) – declared parameters
Returns: the merged parameters
Return type: {
basestring:Parameter}Raises: - UndeclaredParametersException – if a key in
parameter_valuesdoes not exist indeclared_parameters - MissingRequiredParametersException – if a key in
declared_parametersdoes not exist inparameter_valuesand also has no default value - ParametersOfWrongTypeException – if a value in
parameter_valuesdoes not match its type indeclared_parameters
- parameter_values ({
-
aria.modeling.utils.validate_dict_values(the_dict)¶
-
aria.modeling.utils.validate_list_values(the_list)¶