blob: a46770d182c6cf26f5bdd5412bd36835701e2f7c [file] [log] [blame]
Matteo Scandoloc3c0f0a2017-10-18 09:53:30 +02001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain 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,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Matteo Scandolo727e19c2017-12-05 12:53:16 -080015def xproto_tosca_required(null, blank, default=None):
16
17 if null == 'True' or blank == 'True' or default != 'False':
18 return "false"
19 return "true"
20
21def xproto_tosca_field_type(type):
22 """
23 TOSCA requires fields of type 'bool' to be 'boolean'
24 TOSCA requires fields of type 'int32' to be 'integer'
25 """
26
27 if type == "bool":
28 return "boolean"
29 elif type == "int32":
30 return "integer"
31 else:
32 return type
33
Matteo Scandoloc3c0f0a2017-10-18 09:53:30 +020034def xproto_fields_to_tosca_keys(fields):
35 keys = []
36 # look for explicit keys
37 for f in fields:
38 if 'tosca_key' in f['options'] and f['options']['tosca_key'] and 'link' not in f:
39 keys.append(f['name'])
40 if 'tosca_key' in f['options'] and f['options']['tosca_key'] and ('link' in f and f['link']):
41 keys.append("%s_id" % f['name'])
42 # if not keys are specified and there is a name field, use that as key.
43 if len(keys) == 0 and 'name' in map(lambda f: f['name'], fields):
44 keys.append('name')
45 return keys