murano  8.0.0
About: OpenStack Murano combines an application catalog with versatile tooling to simplify and accelerate packaging and deployment.
The "Train" series (latest release).
  Fossies Dox: murano-8.0.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

basic.py
Go to the documentation of this file.
1 # Copyright (c) 2016 Mirantis, Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14 
15 import six
16 
17 from murano.dsl import contracts
18 from murano.dsl import dsl_types
19 from murano.dsl import exceptions
20 from murano.dsl import helpers
21 
22 
24  name = 'string'
25 
26  def transform(self):
27  if self.value is None:
28  return None
29  if isinstance(self.value, six.text_type):
30  return self.value
31  if isinstance(self.value, six.string_types) or \
32  isinstance(self.value, six.integer_types):
33  return six.text_type(self.value)
34  if isinstance(self.value, dsl_types.MuranoObject):
35  return self.value.object_id
36  if isinstance(self.value, dsl_types.MuranoObjectInterface):
37  return self.value.id
39  'Value {0} violates string() contract'.format(
40  helpers.format_scalar(self.value)))
41 
42  def validate(self):
43  if self.value is None or isinstance(self.value, six.string_types):
44  return self.value
46 
47  def generate_schema(self):
48  types = 'string'
49  if '_notNull' not in self.value:
50  types = [types] + ['null']
51 
52  return {
53  'type': types
54  }
55 
56 
58  name = 'bool'
59 
60  def validate(self):
61  if self.value is None or isinstance(self.value, bool):
62  return self.value
64 
65  def transform(self):
66  if self.value is None:
67  return None
68  return True if self.value else False
69 
70  def generate_schema(self):
71  types = 'boolean'
72  if '_notNull' not in self.value:
73  types = [types] + ['null']
74 
75  return {
76  'type': types
77  }
78 
79 
81  name = 'int'
82 
83  def validate(self):
84  if self.value is None or isinstance(
85  self.value, int) and not isinstance(self.value, bool):
86  return self.value
88 
89  def transform(self):
90  if self.value is None:
91  return None
92  try:
93  return int(self.value)
94  except Exception:
96  'Value {0} violates int() contract'.format(
97  helpers.format_scalar(self.value)))
98 
99  def generate_schema(self):
100  types = 'integer'
101  if '_notNull' not in self.value:
102  types = [types] + ['null']
103 
104  return {
105  'type': types
106  }
107 
108 
110  name = 'not_null'
111 
112  def validate(self):
113  if self.value is None:
115  'null value violates notNull() contract')
116  return self.value
117 
118  def transform(self):
119  return self.validate()
120 
121  def generate_schema(self):
122  types = self.value.get('type')
123  if isinstance(types, list) and 'null' in types:
124  types.remove('null')
125  if len(types) == 1:
126  types = types[0]
127  self.value['type'] = types
128  self.value['_notNull'] = True
129  return self.value
murano.dsl.contracts.basic.String.transform
def transform(self)
Definition: basic.py:26
murano.dsl.dsl_types.MuranoObjectInterface
Definition: dsl_types.py:142
murano.dsl.contracts.basic.NotNull.generate_schema
def generate_schema(self)
Definition: basic.py:121
murano.dsl.contracts.basic.NotNull.transform
def transform(self)
Definition: basic.py:118
murano.dsl.contracts.basic.Int.validate
def validate(self)
Definition: basic.py:83
murano.dsl.exceptions.ContractViolationException
Definition: exceptions.py:100
murano.dsl.dsl_types.MuranoObject
Definition: dsl_types.py:95
murano.dsl.contracts.basic.String.generate_schema
def generate_schema(self)
Definition: basic.py:47
murano.dsl.contracts.basic.NotNull
Definition: basic.py:109
murano.dsl.contracts.basic.Bool.transform
def transform(self)
Definition: basic.py:65
murano.dsl.contracts.basic.NotNull.validate
def validate(self)
Definition: basic.py:112
murano.dsl.contracts.basic.Int.transform
def transform(self)
Definition: basic.py:89
murano.dsl.contracts.basic.String
Definition: basic.py:23
murano.dsl.contracts.basic.String.validate
def validate(self)
Definition: basic.py:42
murano.dsl
Definition: __init__.py:1
murano.dsl.contracts.basic.Bool.generate_schema
def generate_schema(self)
Definition: basic.py:70
murano.dsl.contracts.basic.Int
Definition: basic.py:80
murano.dsl.contracts.ContractMethod.validate
def validate(self)
Definition: __init__.py:24
murano.dsl.contracts.basic.Bool
Definition: basic.py:57
murano.dsl.contracts.ContractMethod
Definition: __init__.py:18
murano.dsl.contracts.basic.Int.generate_schema
def generate_schema(self)
Definition: basic.py:99
murano.dsl.contracts.basic.Bool.validate
def validate(self)
Definition: basic.py:60