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')],
69 for k1, v1 in resource["properties"].items():
73 # get the network id or name
75 v1.get('get_param') or
76 v1.get('get_resource'))
81 m = v2[3].match(network)
88 def get_network_type_from_port(resource):
90 get the network type from a neutron port resource
92 if not isinstance(resource, dict):
94 if 'type' not in resource:
96 if resource['type'] != 'OS::Neutron::Port':
98 if 'properties' not in resource:
102 ["network", "string", "internal",
103 re.compile(r'int_(.+?)_net_id')],
104 ["network", "string", "internal",
105 re.compile(r'int_(.+?)_net_name')],
106 ["network", "string", "external",
107 re.compile(r'(.+?)_net_id')],
108 ["network", "string", "external",
109 re.compile(r'(.+?)_net_name')],
112 for k1, v1 in resource["properties"].items():
115 if "get_param" not in v1:
118 m = v2[3].match(v1["get_param"])
125 def is_valid_ip_address(ip_address, ip_type='ipv4'):
127 check if an ip address is valid
129 if ip_type == 'ipv4':
130 return is_valid_ipv4_address(ip_address)
131 elif ip_type == 'ipv6':
132 return is_valid_ipv6_address(ip_address)
136 def is_valid_ipv4_address(ip_address):
138 check if an ip address of the type ipv4
142 socket.inet_pton(socket.AF_INET, ip_address)
143 except AttributeError:
145 socket.inet_aton(ip_address)
146 except (OSError, socket.error):
148 return ip_address.count('.') == 3
149 except (OSError, socket.error):
154 def is_valid_ipv6_address(ip_address):
156 check if an ip address of the type ipv6
160 socket.inet_pton(socket.AF_INET6, ip_address)
161 except (OSError, socket.error):
166 def property_uses_get_resource(resource, property_name):
168 returns true if a port's network property
169 uses the get_resource function
171 if not isinstance(resource, dict):
173 if 'properties' not in resource:
175 for k1, v1 in resource["properties"].items():
176 if k1 != property_name:
178 if "get_resource" in v1: