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.
45 def get_network_role_from_port(resource):
47 get the network role from a neutron port resource
49 if not isinstance(resource, dict):
51 if "type" not in resource:
53 if resource["type"] != "OS::Neutron::Port":
55 if "properties" not in resource:
59 ["network", "string", "internal", re.compile(r"int_(.+?)_net_id")],
60 ["network", "string", "internal", re.compile(r"int_(.+?)_net_name")],
61 ["network", "string", "external", re.compile(r"(.+?)_net_id")],
62 ["network", "string", "external", re.compile(r"(.+?)_net_name")],
65 for k1, v1 in resource["properties"].items():
69 # get the network id or name
70 network = v1.get("get_param") or v1.get("get_resource")
75 m = v2[3].match(network)
82 def get_network_type_from_port(resource):
84 get the network type from a neutron port resource
86 if not isinstance(resource, dict):
88 if "type" not in resource:
90 if resource["type"] != "OS::Neutron::Port":
92 if "properties" not in resource:
96 ["network", "string", "internal", re.compile(r"int_(.+?)_net_id")],
97 ["network", "string", "internal", re.compile(r"int_(.+?)_net_name")],
98 ["network", "string", "external", re.compile(r"(.+?)_net_id")],
99 ["network", "string", "external", re.compile(r"(.+?)_net_name")],
102 for k1, v1 in resource["properties"].items():
105 if "get_param" not in v1:
108 m = v2[3].match(v1["get_param"])
115 def is_valid_ip_address(ip_address, ip_type="ipv4"):
117 check if an ip address is valid
119 if ip_type == "ipv4":
120 return is_valid_ipv4_address(ip_address)
121 elif ip_type == "ipv6":
122 return is_valid_ipv6_address(ip_address)
126 def is_valid_ipv4_address(ip_address):
128 check if an ip address of the type ipv4
132 socket.inet_pton(socket.AF_INET, ip_address)
133 except AttributeError:
135 socket.inet_aton(ip_address)
136 except (OSError, socket.error):
138 return ip_address.count(".") == 3
139 except (OSError, socket.error):
144 def is_valid_ipv6_address(ip_address):
146 check if an ip address of the type ipv6
150 socket.inet_pton(socket.AF_INET6, ip_address)
151 except (OSError, socket.error):
156 def property_uses_get_resource(resource, property_name):
158 returns true if a port's network property
159 uses the get_resource function
161 if not isinstance(resource, dict):
163 if "properties" not in resource:
165 for k1, v1 in resource["properties"].items():
166 if k1 != property_name:
168 if "get_resource" in v1: