Matteo Scandolo | c3c0f0a | 2017-10-18 09:53:30 +0200 | [diff] [blame] | 1 | # 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 | |
| 15 | def xproto_fields_to_tosca_keys(fields): |
| 16 | keys = [] |
| 17 | # look for explicit keys |
| 18 | for f in fields: |
| 19 | if 'tosca_key' in f['options'] and f['options']['tosca_key'] and 'link' not in f: |
| 20 | keys.append(f['name']) |
| 21 | if 'tosca_key' in f['options'] and f['options']['tosca_key'] and ('link' in f and f['link']): |
| 22 | keys.append("%s_id" % f['name']) |
| 23 | # if not keys are specified and there is a name field, use that as key. |
| 24 | if len(keys) == 0 and 'name' in map(lambda f: f['name'], fields): |
| 25 | keys.append('name') |
| 26 | return keys |