Debian Codegraph @

neutron_vpnaas/services/vpn/service_drivers/ipsec_validator.py

raw
1 # Copyright 2015 Awcloud Inc. All rights reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14
15 from neutron_lib import exceptions as nexception
16
17 from neutron_vpnaas._i18n import _
18 from neutron_vpnaas.services.vpn.service_drivers import driver_validator
19
20
21 class IpsecValidationFailure(nexception.BadRequest):
22 message = _("IPSec does not support %(resource)s attribute %(key)s "
23 "with value '%(value)s'")
24
25
26 class IpsecVpnValidator(driver_validator.VpnDriverValidator):
27
28 """Driver-specific validator methods for the Openswan, Strongswan
29 and Libreswan.
30 """
31
32 def _check_transform_protocol(self, context, transform_protocol):
33 """Restrict selecting ah-esp as IPSec Policy transform protocol.
34
35 For those *Swan implementations, the 'ah-esp' transform protocol
36 is not supported and therefore the request should be rejected.
37 """
38 if transform_protocol == "ah-esp":
39 raise IpsecValidationFailure(
40 resource='IPsec Policy',
41 key='transform_protocol',
42 value=transform_protocol)
43
44 def validate_ipsec_policy(self, context, ipsec_policy):
45 transform_protocol = ipsec_policy.get('transform_protocol')
46 self._check_transform_protocol(context, transform_protocol)
47
48 def validate_ipsec_site_connection(self, context, ipsec_sitecon):
49 if 'ipsecpolicy_id' in ipsec_sitecon:
50 ipsec_policy = self.driver.service_plugin.get_ipsecpolicy(
51 context, ipsec_sitecon['ipsecpolicy_id'])
52 self.validate_ipsec_policy(context, ipsec_policy)