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.
41 from .network_roles import get_network_role_from_port
42 from .vm_types import get_vm_type_for_nova_server
46 def is_valid_ip_address(ip_address, vm_type, network_role, port_property):
48 Check the ip_address to make sure it is properly formatted and
49 also contains {vm_type} and {network_role}
53 ["allowed_address_pairs", "string", "internal",
54 re.compile(r'(.+?)_int_(.+?)_floating_v6_ip')],
55 ["allowed_address_pairs", "string", "internal",
56 re.compile(r'(.+?)_int_(.+?)_floating_ip')],
57 ["allowed_address_pairs", "string", "external",
58 re.compile(r'(.+?)_floating_v6_ip')],
59 ["allowed_address_pairs", "string", "external",
60 re.compile(r'(.+?)_floating_ip')],
61 ["allowed_address_pairs", "string", "internal",
62 re.compile(r'(.+?)_int_(.+?)_v6_ip_\d+')],
63 ["allowed_address_pairs", "string", "internal",
64 re.compile(r'(.+?)_int_(.+?)_ip_\d+')],
65 ["allowed_address_pairs", "string", "external",
66 re.compile(r'(.+?)_v6_ip_\d+')],
67 ["allowed_address_pairs", "string", "external",
68 re.compile(r'(.+?)_ip_\d+')],
69 ["allowed_address_pairs", "comma_delimited_list",
70 "internal", re.compile(r'(.+?)_int_(.+?)_v6_ips')],
71 ["allowed_address_pairs", "comma_delimited_list",
72 "internal", re.compile(r'(.+?)_int_(.+?)_ips')],
73 ["allowed_address_pairs", "comma_delimited_list",
74 "external", re.compile(r'(.+?)_v6_ips')],
75 ["allowed_address_pairs", "comma_delimited_list",
76 "external", re.compile(r'(.+?)_ips')],
77 ["fixed_ips", "string", "internal",
78 re.compile(r'(.+?)_int_(.+?)_v6_ip_\d+')],
79 ["fixed_ips", "string", "internal",
80 re.compile(r'(.+?)_int_(.+?)_ip_\d+')],
81 ["fixed_ips", "string", "external",
82 re.compile(r'(.+?)_v6_ip_\d+')],
83 ["fixed_ips", "string", "external",
84 re.compile(r'(.+?)_ip_\d+')],
85 ["fixed_ips", "comma_delimited_list", "internal",
86 re.compile(r'(.+?)_int_(.+?)_v6_ips')],
87 ["fixed_ips", "comma_delimited_list", "internal",
88 re.compile(r'(.+?)_int_(.+?)_ips')],
89 ["fixed_ips", "comma_delimited_list", "external",
90 re.compile(r'(.+?)_v6_ips')],
91 ["fixed_ips", "comma_delimited_list", "external",
92 re.compile(r'(.+?)_ips')],
95 for v3 in allowed_formats:
96 if v3[0] != port_property:
98 # check if pattern matches
99 m = v3[3].match(ip_address)
101 if (v3[2] == "internal" and
102 len(m.groups()) > 1):
103 return m.group(1) == vm_type and\
104 m.group(2) == network_role
105 elif (v3[2] == "external" and
106 len(m.groups()) > 0):
107 return m.group(1) == vm_type + "_" + network_role
112 def get_invalid_ip_addresses(resources, port_property):
114 Get a list of valid ip addresses for a heat resources section
116 invalid_ip_addresses = []
118 for k, v in resources.items():
119 if not isinstance(v, dict):
123 if v['type'] not in 'OS::Nova::Server':
125 if 'properties' not in v:
127 if 'networks' not in v['properties']:
132 vm_type = get_vm_type_for_nova_server(v)
136 # get all ports associated with the nova server
137 properties = v['properties']
138 for network in properties['networks']:
139 for k3, v3 in network.items():
142 if not isinstance(v3, dict):
145 if 'get_resource' in v3:
146 port_id = v3['get_resource']
147 if not resources[port_id]:
149 port_resource = resources[port_id]
153 network_role = get_network_role_from_port(port_resource)
157 for k1, v1 in port_resource["properties"].items():
158 if k1 != port_property:
161 if "ip_address" not in v2:
163 if "get_param" not in v2["ip_address"]:
166 ip_address = v2["ip_address"]["get_param"]
168 if isinstance(ip_address, list):
169 ip_address = ip_address[0]
171 valid_ip_address = is_valid_ip_address(ip_address,
176 if not valid_ip_address:
177 invalid_ip_addresses.append(ip_address)
179 return invalid_ip_addresses