MetadataAware mixin added to Core Library

Added a mixin class 'MetadataAware' which contains logic to retrieve
metadata attributes from the object of class which inherits it and
from all objects owning this one. Metadata attrbiutes applied to
objects which are deeper in the stack ovewrite ones from objects which
are higher.

The mixin can also validate if the attribute may be applied to the
objects of the given resource type; the type is defined by its
overridable abstract method 'getResourceType'. This check uses
MetadefBrowser class to retrieve the meta definition namespaces of the
needed resource type.

Instance and CinderVolume classes now inherit this mixin.

Change-Id: I43a081fe2a88e666f61de04b8a2789e1b8e96e38
Targets-blueprint: metadata-assignment-and-propagation
This commit is contained in:
Alexander Tivelkov 2016-09-28 21:12:28 +03:00
parent f17a8f3dae
commit f258b577fb
5 changed files with 89 additions and 4 deletions

View File

@ -13,10 +13,13 @@
Namespaces:
std: io.murano
=: io.murano.resources
sys: io.murano.system
Name: CinderVolume
Extends: Volume
Extends:
- Volume
- MetadataAware
Properties:
name:
@ -53,6 +56,7 @@ Methods:
Body:
- $properties:
size: $.size
metadata: $this.getMetadata($this.getRegion())
- If: $.availabilityZone != null
Then:
@ -86,7 +90,7 @@ Methods:
- Return:
resources:
format('vol-{0}', id($)):
type: 'OS::Cinder::Volume'
type: $this.getResourceType()
properties: $properties
outputs:
format('vol-{0}-id', id($)):
@ -133,3 +137,8 @@ Methods:
Body:
Return:
get_resource: format('vol-{0}', id($))
getResourceType:
Body:
- Return: 'OS::Cinder::Volume'

View File

@ -17,7 +17,9 @@ Namespaces:
Name: Instance
Extends: std:CloudResource
Extends:
- std:CloudResource
- MetadataAware
Properties:
name:
@ -138,6 +140,7 @@ Methods:
user_data: $preparedUserData.data
user_data_format: $preparedUserData.format
key_name: $.keyname
metadata: $this.getMetadata($region)
- If: len($.blockDevices) > 0
Then:
@ -149,7 +152,7 @@ Methods:
- $template:
resources:
$.name:
type: 'OS::Nova::Server'
type: $this.getResourceType()
properties: $properties
outputs:
@ -382,3 +385,7 @@ Methods:
Body:
Return:
get_resource: $.name
getResourceType:
Body:
- Return: 'OS::Nova::Server'

View File

@ -0,0 +1,64 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
Namespaces:
=: io.murano.resources
std: io.murano
sys: io.murano.system
Name: MetadataAware
Properties:
checkApplicability:
Contract: $.bool().notNull()
Default: true
Methods:
.init:
Body:
- $this._metadefBrowsers: {}
getMetadefBrowser:
Arguments:
- region:
Contract: $.class(std:CloudRegion).notNull()
Body:
- $browser: $this._metadefBrowsers.get($region.name)
- If: $browser = null
Then:
- $browser: new(sys:MetadefBrowser, $region)
- $this._metadefBrowsers[$region.name]: $browser
- Return: $browser
getMetadata:
Arguments:
- region:
Contract: $.class(std:CloudRegion).notNull()
Body:
- $thisMeta: metadata($this) or {}
- $parentsMeta: {}
- $p: $this.find(std:Object)
- While: $p != null
Do:
- $pmeta: metadata($p) or {}
- $pmeta: dict($pmeta.items().where(not $[0] in $parentsMeta.keys()))
- $parentsMeta: $parentsMeta.set($pmeta)
- $p: $p.find(std:Object)
- $resourceType: $this.getResourceType()
- If: $this.checkApplicability and $resourceType
Then:
- $browser: $this.getMetadefBrowser($region)
- $parentsMeta: dict($parentsMeta.items().where($browser.canBeAppliedTo($[0], $resourceType)))
- Return: $parentsMeta.set($thisMeta)
getResourceType:

View File

@ -57,6 +57,7 @@ Classes:
io.murano.resources.ExistingCinderVolume: resources/ExistingCinderVolume.yaml
io.murano.resources.CinderVolumeBackup: resources/CinderVolumeBackup.yaml
io.murano.resources.CinderVolumeSnapshot: resources/CinderVolumeSnapshot.yaml
io.murano.resources.MetadataAware: resources/MetadataAware.yaml
io.murano.system.Agent: system/Agent.yaml
io.murano.system.AgentListener: system/AgentListener.yaml

View File

@ -0,0 +1,4 @@
---
features:
- Added a MetadataAware mixin class capable to retrieve the metadata
attributes from the implementing objects and all its parents.