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",
60 re.compile(r'int_(.+?)_net_id')],
61 ["network", "string", "internal",
62 re.compile(r'int_(.+?)_net_name')],
63 ["network", "string", "external",
64 re.compile(r'(.+?)_net_id')],
65 ["network", "string", "external",
66 re.compile(r'(.+?)_net_name')]]
68 for k1, v1 in resource["properties"].items():
72 # get the network id or name
74 v1.get('get_param') or
75 v1.get('get_resource'))
80 m = v2[3].match(network)
87 def get_network_roles(resources):
89 for v in resources.values():
90 nr = get_network_role_from_port(v)
92 network_roles.append(nr)
94 return set(network_roles)
97 def get_network_type_from_port(resource):
99 get the network type from a neutron port resource
101 if not isinstance(resource, dict):
103 if 'type' not in resource:
105 if resource['type'] != 'OS::Neutron::Port':
107 if 'properties' not in resource:
111 ["network", "string", "internal",
112 re.compile(r'int_(.+?)_net_id')],
113 ["network", "string", "internal",
114 re.compile(r'int_(.+?)_net_name')],
115 ["network", "string", "external",
116 re.compile(r'(.+?)_net_id')],
117 ["network", "string", "external",
118 re.compile(r'(.+?)_net_name')]]
120 for k1, v1 in resource["properties"].items():
123 if "get_param" not in v1:
126 m = v2[3].match(v1["get_param"])
133 def is_valid_ip_address(ip_address, ip_type='ipv4'):
135 check if an ip address is valid
137 if ip_type == 'ipv4':
138 return is_valid_ipv4_address(ip_address)
139 elif ip_type == 'ipv6':
140 return is_valid_ipv6_address(ip_address)
144 def is_valid_ipv4_address(ip_address):
146 check if an ip address of the type ipv4
150 socket.inet_pton(socket.AF_INET, ip_address)
151 except AttributeError:
153 socket.inet_aton(ip_address)
154 except (OSError, socket.error):
156 return ip_address.count('.') == 3
157 except (OSError, socket.error):
162 def is_valid_ipv6_address(ip_address):
164 check if an ip address of the type ipv6
168 socket.inet_pton(socket.AF_INET6, ip_address)
169 except (OSError, socket.error):
174 def property_uses_get_resource(resource, property_name):
176 returns true if a port's network property
177 uses the get_resource function
179 if not isinstance(resource, dict):
181 if 'properties' not in resource:
183 for k1, v1 in resource["properties"].items():
184 if k1 != property_name:
186 if "get_resource" in v1: