Scott Baker | 083a3b6 | 2018-03-09 20:48:30 -0800 | [diff] [blame^] | 1 | {# |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | #} |
| 16 | |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 17 | {# Using regular variables has scoping issues. #} |
| 18 | {# See: https://stackoverflow.com/questions/7537439/how-to-increment-a-variable-on-a-for-loop-in-jinja-template/7537466 #} |
| 19 | {% set counter = { |
| 20 | 'num_service_models': 0, |
| 21 | 'num_service_instance_models': 0, |
| 22 | 'num_orphaned_models': 0, |
| 23 | } %} |
| 24 | {% macro increment(key) %} |
| 25 | {% if counter.update({key: counter[key] + 1}) %} {% endif %} |
| 26 | {% endmacro %} |
| 27 | {% for m in proto.messages %} |
| 28 | {% set matched = False %} |
| 29 | {% set base_names = m.bases | map(attribute='name') | list %} |
| 30 | {% if 'Service' in base_names %} |
| 31 | {{ increment('num_service_models') }} |
| 32 | {% set matched = True %} |
| 33 | {% endif %} |
| 34 | {% if not matched and 'ServiceInstance' in base_names or 'Tenant' in base_names or 'TenantWithContainer' in base_names %} |
| 35 | {{ increment('num_service_instance_models') }} |
| 36 | {% set matched = True %} |
| 37 | {% endif %} |
| 38 | {% if not matched and 'XOSBase' not in base_names %} |
| 39 | 501 Model does not have a parent - {{ m.name }} |
| 40 | {% endif %} |
| 41 | {% endfor %} |
| 42 | {% if counter.num_service_models !=1 %} |
| 43 | 502 {{ counter.num_service_models }} Service models instead of 1 |
| 44 | {% elif counter.num_service_instance_models !=1 %} |
| 45 | 503 {{ counter.num_service_instance_models }} ServiceInstance models instead of 1 |
| 46 | {% else %} |
| 47 | 200 OK |
| 48 | {% endif %} |