Metadata storage in object model
Modified serializer/deserializer to load and persist the "metadata" block of the ?-section of object model. Added a "metadata()" function to read the value of this block for any object. Change-Id: Ideee8a9d242738d3e7fea03d2adc847ed95401f3 Targets-blueprint: metadata-assignment-and-propagation
This commit is contained in:
parent
343f8b49e3
commit
e43eb9321b
@ -59,3 +59,4 @@ RUNTIME_VERSION_1_1 = semantic_version.Version('1.1.0')
|
||||
RUNTIME_VERSION_1_2 = semantic_version.Version('1.2.0')
|
||||
RUNTIME_VERSION_1_3 = semantic_version.Version('1.3.0')
|
||||
RUNTIME_VERSION_1_4 = semantic_version.Version('1.4.0')
|
||||
RUNTIME_VERSION_1_5 = semantic_version.Version('1.5.0')
|
||||
|
@ -570,6 +570,7 @@ def parse_object_definition(spec, scope_type, context):
|
||||
'properties': yaqlutils.filter_parameters_dict(props),
|
||||
'id': system_data.get('id'),
|
||||
'name': system_data.get('name'),
|
||||
'metadata': system_data.get('metadata'),
|
||||
'destroyed': system_data.get('destroyed', False),
|
||||
'dependencies': system_data.get('dependencies', {}),
|
||||
'extra': {
|
||||
@ -585,6 +586,7 @@ def assemble_object_definition(parsed, model_format=dsl_types.DumpTypes.Mixed):
|
||||
parsed['type']: parsed['properties'],
|
||||
'id': parsed['id'],
|
||||
'name': parsed['name'],
|
||||
'metadata': parsed['metadata'],
|
||||
'dependencies': parsed['dependencies'],
|
||||
'destroyed': parsed['destroyed']
|
||||
}
|
||||
@ -593,7 +595,8 @@ def assemble_object_definition(parsed, model_format=dsl_types.DumpTypes.Mixed):
|
||||
result = parsed['properties']
|
||||
header = {
|
||||
'id': parsed['id'],
|
||||
'name': parsed['name']
|
||||
'name': parsed['name'],
|
||||
'metadata': parsed['metadata']
|
||||
}
|
||||
if parsed['destroyed']:
|
||||
header['destroyed'] = True
|
||||
|
@ -25,7 +25,7 @@ from murano.dsl import yaql_integration
|
||||
|
||||
class MuranoObject(dsl_types.MuranoObject):
|
||||
def __init__(self, murano_class, owner, object_id=None, name=None,
|
||||
known_classes=None, this=None):
|
||||
known_classes=None, this=None, metadata=None):
|
||||
self._initialized = False
|
||||
self._destroyed = False
|
||||
if known_classes is None:
|
||||
@ -42,6 +42,7 @@ class MuranoObject(dsl_types.MuranoObject):
|
||||
self._executor = helpers.weak_ref(helpers.get_executor())
|
||||
self._config = murano_class.package.get_class_config(
|
||||
murano_class.name)
|
||||
self._metadata = metadata
|
||||
if not isinstance(self._config, dict):
|
||||
self._config = {}
|
||||
known_classes[murano_class.name] = self
|
||||
@ -66,6 +67,10 @@ class MuranoObject(dsl_types.MuranoObject):
|
||||
def name(self):
|
||||
return self.real_this._name
|
||||
|
||||
@property
|
||||
def metadata(self):
|
||||
return self.real_this._metadata
|
||||
|
||||
@extension.setter
|
||||
def extension(self, value):
|
||||
self._extension = value
|
||||
@ -325,7 +330,8 @@ class MuranoObject(dsl_types.MuranoObject):
|
||||
result = {
|
||||
self.type: result,
|
||||
'id': self.object_id,
|
||||
'name': self.name
|
||||
'name': self.name,
|
||||
'metadata': self.metadata
|
||||
}
|
||||
header = result
|
||||
else:
|
||||
@ -334,12 +340,14 @@ class MuranoObject(dsl_types.MuranoObject):
|
||||
'type': self.type,
|
||||
'id': self.object_id,
|
||||
'name': self.name,
|
||||
'metadata': self.metadata
|
||||
}})
|
||||
else:
|
||||
result.update({'?': {
|
||||
'type': helpers.format_type_string(self.type),
|
||||
'id': self.object_id,
|
||||
'name': self.name
|
||||
'name': self.name,
|
||||
'metadata': self.metadata
|
||||
}})
|
||||
header = result['?']
|
||||
if self.destroyed:
|
||||
|
@ -273,6 +273,7 @@ class InitializationObjectStore(ObjectStore):
|
||||
obj = mo_type(
|
||||
class_obj, owner,
|
||||
name=parsed['name'],
|
||||
metadata=parsed['metadata'],
|
||||
object_id=object_id if self._keep_ids else None)
|
||||
obj.load_dependencies(parsed['dependencies'])
|
||||
if parsed['destroyed']:
|
||||
|
@ -154,6 +154,11 @@ def name(object_):
|
||||
return None if object_ is None else object_.name
|
||||
|
||||
|
||||
@specs.parameter('object_', dsl.MuranoObjectParameter())
|
||||
def metadata(object_):
|
||||
return object_.object.metadata
|
||||
|
||||
|
||||
@specs.parameter('obj', dsl.MuranoObjectParameter(decorate=False))
|
||||
@specs.parameter('property_name', yaqltypes.Keyword())
|
||||
@specs.name('#operator_.')
|
||||
@ -270,6 +275,7 @@ def register(context, runtime_version):
|
||||
context.register_function(typeinfo)
|
||||
context.register_function(typeinfo_for_class)
|
||||
context.register_function(name)
|
||||
context.register_function(metadata)
|
||||
context.register_function(obj_attribution)
|
||||
context.register_function(obj_attribution_static)
|
||||
context.register_function(op_dot)
|
||||
|
@ -116,6 +116,7 @@ class TestDump(test_case.DslTestCase):
|
||||
self.assertNotIn('qux', res)
|
||||
|
||||
def _get_body(self, obj):
|
||||
body_key = [k for k in obj.keys() if k not in ('id', 'name')][0]
|
||||
body_key = [k for k in obj.keys()
|
||||
if k not in ('id', 'name', 'metadata')][0]
|
||||
self.assertIsInstance(body_key, dsl_types.MuranoType)
|
||||
return obj[body_key]
|
||||
|
6
releasenotes/notes/metadata-getter-76907aa1f0325adc.yaml
Normal file
6
releasenotes/notes/metadata-getter-76907aa1f0325adc.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
features:
|
||||
- Added a ``metadata()`` yaql function to retrieve the meta information about the
|
||||
object, stored in the "?/metadata" section of object model.
|
||||
other:
|
||||
- Bumped the RUNTIME_VERSION attribute to 1.5
|
Loading…
x
Reference in New Issue
Block a user