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}
54 "allowed_address_pairs",
57 re.compile(r"(.+?)_int_(.+?)_floating_v6_ip"),
60 "allowed_address_pairs",
63 re.compile(r"(.+?)_int_(.+?)_floating_ip"),
66 "allowed_address_pairs",
69 re.compile(r"(.+?)_floating_v6_ip"),
72 "allowed_address_pairs",
75 re.compile(r"(.+?)_floating_ip"),
78 "allowed_address_pairs",
81 re.compile(r"(.+?)_int_(.+?)_v6_ip_\d+"),
84 "allowed_address_pairs",
87 re.compile(r"(.+?)_int_(.+?)_ip_\d+"),
89 ["allowed_address_pairs", "string", "external", re.compile(r"(.+?)_v6_ip_\d+")],
90 ["allowed_address_pairs", "string", "external", re.compile(r"(.+?)_ip_\d+")],
92 "allowed_address_pairs",
93 "comma_delimited_list",
95 re.compile(r"(.+?)_int_(.+?)_v6_ips"),
98 "allowed_address_pairs",
99 "comma_delimited_list",
101 re.compile(r"(.+?)_int_(.+?)_ips"),
104 "allowed_address_pairs",
105 "comma_delimited_list",
107 re.compile(r"(.+?)_v6_ips"),
110 "allowed_address_pairs",
111 "comma_delimited_list",
113 re.compile(r"(.+?)_ips"),
115 ["fixed_ips", "string", "internal", re.compile(r"(.+?)_int_(.+?)_v6_ip_\d+")],
116 ["fixed_ips", "string", "internal", re.compile(r"(.+?)_int_(.+?)_ip_\d+")],
117 ["fixed_ips", "string", "external", re.compile(r"(.+?)_v6_ip_\d+")],
118 ["fixed_ips", "string", "external", re.compile(r"(.+?)_ip_\d+")],
121 "comma_delimited_list",
123 re.compile(r"(.+?)_int_(.+?)_v6_ips"),
127 "comma_delimited_list",
129 re.compile(r"(.+?)_int_(.+?)_ips"),
131 ["fixed_ips", "comma_delimited_list", "external", re.compile(r"(.+?)_v6_ips")],
132 ["fixed_ips", "comma_delimited_list", "external", re.compile(r"(.+?)_ips")],
135 for v3 in allowed_formats:
136 if v3[0] != port_property:
138 # check if pattern matches
139 m = v3[3].match(ip_address)
141 if v3[2] == "internal" and len(m.groups()) > 1:
142 return m.group(1) == vm_type and m.group(2) == network_role
143 elif v3[2] == "external" and len(m.groups()) > 0:
144 return m.group(1) == vm_type + "_" + network_role
149 def get_invalid_ip_addresses(resources, port_property):
151 Get a list of valid ip addresses for a heat resources section
153 invalid_ip_addresses = []
155 for k, v in resources.items():
156 if not isinstance(v, dict):
160 if v["type"] not in "OS::Nova::Server":
162 if "properties" not in v:
164 if "networks" not in v["properties"]:
169 vm_type = get_vm_type_for_nova_server(v)
173 # get all ports associated with the nova server
174 properties = v["properties"]
175 for network in properties["networks"]:
176 for k3, v3 in network.items():
179 if not isinstance(v3, dict):
182 if "get_resource" in v3:
183 port_id = v3["get_resource"]
184 if not resources[port_id]:
186 port_resource = resources[port_id]
190 network_role = get_network_role_from_port(port_resource)
194 for k1, v1 in port_resource["properties"].items():
195 if k1 != port_property:
198 if "ip_address" not in v2:
200 if "get_param" not in v2["ip_address"]:
203 ip_address = v2["ip_address"]["get_param"]
205 if isinstance(ip_address, list):
206 ip_address = ip_address[0]
208 valid_ip_address = is_valid_ip_address(
209 ip_address, vm_type, network_role, port_property
212 if not valid_ip_address:
213 invalid_ip_addresses.append(ip_address)
215 return invalid_ip_addresses
218 def is_reserved_port(port_id):
220 Checks to see if the resource id for a port follows
221 the reserve port concept
224 ["port_id", re.compile(r"reserve_port_(.+?)_floating_ip_\d+")],
225 ["port_id", re.compile(r"reserve_port_(.+?)_floating_v6_ip_\d+")],
228 m = f[1].match(port_id.lower())