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.ModelingException
ARIA modeling exception: cannot evaluate the function at this time.
-
exception
aria.modeling.exceptions.
MissingRequiredInputsException
(message=None, cause=None, cause_traceback=None)¶ Bases:
aria.modeling.exceptions.ParameterException
ARIA modeling exception: Required parameters have been omitted.
-
exception
aria.modeling.exceptions.
ModelingException
(message=None, cause=None, cause_traceback=None)¶ Bases:
aria.exceptions.AriaException
ARIA modeling exception.
-
exception
aria.modeling.exceptions.
ParameterException
(message=None, cause=None, cause_traceback=None)¶ Bases:
aria.modeling.exceptions.ModelingException
ARIA parameter exception.
-
exception
aria.modeling.exceptions.
ParametersOfWrongTypeException
(message=None, cause=None, cause_traceback=None)¶ Bases:
aria.modeling.exceptions.ParameterException
ARIA modeling exception: Parameters of the wrong types have been provided.
-
exception
aria.modeling.exceptions.
UndeclaredInputsException
(message=None, cause=None, cause_traceback=None)¶ Bases:
aria.modeling.exceptions.ParameterException
ARIA modeling exception: Undeclared parameters have been provided.
-
exception
aria.modeling.exceptions.
ValueFormatException
(message=None, cause=None, cause_traceback=None)¶ Bases:
aria.modeling.exceptions.ModelingException
ARIA 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:
object
An evaluated
Function
return value.Variables: - value – evaluated value
- final (boolean) – whether the value is final
-
class
aria.modeling.functions.
Function
¶ Bases:
object
Base 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 withvalue
andfinal
properties)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_holder
argument should have three properties:container
should return the model that contains the value,service
should return the containingService
model or None, andservice_template
should return the containingServiceTemplate
model orNone
.
aria.modeling.mixins
¶
ARIA modeling mix-ins module
-
class
aria.modeling.mixins.
InstanceModelMixin
¶ Bases:
aria.modeling.mixins.ModelMixin
Mix-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)¶
-
-
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
, setsNone
to 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.HasCachedMethods
Mix-in for typed values. The value can contain nested intrinsic functions.
This model can be used as the
container_holder
argument forevaluate()
.-
as_argument
()¶
-
as_other_parameter_model
(other_model_cls)¶
-
as_raw
¶
-
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
SELF
keyword 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)¶
-
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
Service
model containing this parameter, orNone
if not contained in a service.Raises: ValueError – if failed to find a container model, which signifies an abnormal, orphaned parameter
-
service_template
¶ The
ServiceTemplate
model containing this parameter, orNone
if 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.InstanceModelMixin
Mix-in for service template models.
All model models can be instantiated into service instance models.
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) –
True
to 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_property
argument 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
False
to 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_property
argument 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
False
to 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_property
argument 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
False
to 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
fk
argument) or the other table can have an associated foreign key to this our table (use theother_fk
argument).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
False
to 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._MutableType
JSON-serializable dict type for SQLAlchemy columns.
Construct a
TypeDecorator
.Arguments sent here are passed to the constructor of the class assigned to the
impl
class level attribute, assuming theimpl
is a callable, and the resulting object is assigned to theself.impl
instance attribute (thus overriding the class attribute of the same name).If the class level
impl
is 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.impl
entirely.-
python_type
¶
-
-
class
aria.modeling.types.
List
(*args, **kwargs)¶ Bases:
aria.modeling.types._MutableType
JSON-serializable list type for SQLAlchemy columns.
Construct a
TypeDecorator
.Arguments sent here are passed to the constructor of the class assigned to the
impl
class level attribute, assuming theimpl
is a callable, and the resulting object is assigned to theself.impl
instance attribute (thus overriding the class attribute of the same name).If the class level
impl
is 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.impl
entirely.-
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.JSONEncoder
JSON encoder that automatically unwraps
value
attributes.-
default
(o)¶
-
-
class
aria.modeling.utils.
NodeTemplateContainerHolder
(node_template)¶ Bases:
object
Wrapper that allows using a
NodeTemplate
model directly as thecontainer_holder
input forevaluate()
.-
service_template
¶
-
-
aria.modeling.utils.
dict_as_arguments
(the_dict)¶
-
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.
merge_parameter_values
(provided_values, declared_parameters, model_cls=None)¶ Merges parameter values according to those declared by a type.
Exceptions will be raised for validation errors.
Parameters: - provided_values ({
basestring
: object}) – provided parameter values or None - declared_parameters ({
basestring
:Parameter
}) – declared parameters - model_cls (
Input
orArgument
) – the model class that should be created from a provided value
Returns: the merged parameters
Return type: {
basestring
:Parameter
}Raises: - UndeclaredInputsException – if a key in
parameter_values
does not exist indeclared_parameters
- MissingRequiredInputsException – if a key in
declared_parameters
does not exist inparameter_values
and also has no default value - ParametersOfWrongTypeException – if a value in
parameter_values
does not match its type indeclared_parameters
- provided_values ({
-
aria.modeling.utils.
parameters_as_values
(the_dict)¶
-
aria.modeling.utils.
validate_no_undeclared_inputs
(declared_inputs, supplied_inputs)¶
-
aria.modeling.utils.
validate_required_inputs_are_supplied
(declared_inputs, supplied_inputs)¶