2 # ============LICENSE_START=======================================================
3 # org.onap.vvp/validation-scripts
4 # ===================================================================
5 # Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 # ===================================================================
8 # Unless otherwise specified, all software contained herein is licensed
9 # under the Apache License, Version 2.0 (the "License");
10 # you may not use this software except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
23 # Unless otherwise specified, all documentation contained herein is licensed
24 # under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25 # you may not use this documentation except in compliance with the License.
26 # You may obtain a copy of the License at
28 # https://creativecommons.org/licenses/by/4.0/
30 # Unless required by applicable law or agreed to in writing, documentation
31 # distributed under the License is distributed on an "AS IS" BASIS,
32 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 # See the License for the specific language governing permissions and
34 # limitations under the License.
36 # ============LICENSE_END============================================
38 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
44 def get_vm_types_for_resource(resource):
46 Get all unique vm_types for a resource
48 - Returns set([]) if the resource is not formatted
49 properly, the passed resource is not a nova server
50 - If more than one vm_type is detected all vm_types will
53 if not isinstance(resource, dict):
55 if 'type' not in resource:
57 if resource['type'] != 'OS::Nova::Server':
59 if 'properties' not in resource:
62 key_values = ["name", "flavor", "image"]
65 re.compile(r'(.+?)_name_\d+')],
66 ["name", "comma_delimited_list",
67 re.compile(r'(.+?)_names')],
69 re.compile(r'(.+?)_flavor_name')],
71 re.compile(r'(.+?)_image_name')],
75 for k2, v2 in resource['properties'].items():
76 if k2 not in key_values:
78 if "get_param" not in v2:
80 formats = [v for v in key_value_formats if v[0] == k2]
82 param = v2["get_param"]
83 if isinstance(param, list):
85 m = v3[2].match(param)
87 vm_types.append(m.group(1))
92 def get_vm_type_for_nova_server(resource):
94 Get the vm_type for a resource
95 Note: Returns None if not exactly one vm_type
96 is detected, if the resource is not formatted properly, or
97 the passed resource is not a nova server
99 vm_types = get_vm_types_for_resource(resource)
101 # if more than one vm_type was identified, return None
102 if len(vm_types) > 1:
105 return vm_types.pop()
108 def get_vm_types(resources):
110 Get all vm_types for a list of heat resources, do note that
111 some of the values retrieved may be invalid
114 for v in resources.values():
115 vm_types.extend(list(get_vm_types_for_resource(v)))