heat-translator/translator/toscalib/elements/property_definition.py
Yaoguo Jiang 154b0e716a add blockstorage attachment notation
Implement blockstorage attachment notations described in E1.4.2
and E1.4.3 of TOSCA wd02.

Partially Implements: blueprint new-blockstorage-templates-tosca

Change-Id: I7fe61b4458840bedeac88f58161cece12f2929bb
2015-01-07 00:45:27 +08:00

46 lines
1.5 KiB
Python

# 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.
from translator.toscalib.common.exception import InvalidSchemaError
class PropertyDef(object):
'''TOSCA built-in Property type.'''
def __init__(self, name, value=None, schema=None):
self.name = name
self.value = value
self.schema = schema
try:
self.schema['type']
except KeyError:
msg = (_("Property definition of %(pname)s must have type.") %
dict(pname=self.name))
raise InvalidSchemaError(message=msg)
@property
def required(self):
if self.schema:
for prop_key, prop_vale in self.schema.items():
if prop_key == 'required' and prop_vale:
return True
return False
@property
def default(self):
if self.schema:
for prop_key, prop_value in self.schema.items():
if prop_key == 'default':
return prop_value
return None