| 1 |
# (c) Copyright 2013 Hewlett-Packard Development Company, L.P. |
| 2 |
# All Rights Reserved. |
| 3 |
# |
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 |
# not use this file except in compliance with the License. You may obtain |
| 6 |
# a copy of the License at |
| 7 |
# |
| 8 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
# |
| 10 |
# Unless required by applicable law or agreed to in writing, software |
| 11 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 |
# License for the specific language governing permissions and limitations |
| 14 |
# under the License. |
| 15 |
|
| 16 |
import abc |
| 17 |
|
| 18 |
from neutron_lib.api.definitions import vpn |
| 19 |
from neutron_lib.api import extensions |
| 20 |
from neutron_lib import exceptions as nexception |
| 21 |
from neutron_lib.plugins import constants as nconstants |
| 22 |
from neutron_lib.services import base as service_base |
| 23 |
|
| 24 |
from neutron.api.v2 import resource_helper |
| 25 |
|
| 26 |
from neutron_vpnaas._i18n import _ |
| 27 |
|
| 28 |
|
| 29 |
class RouteInUseByVPN(nexception.InUse): |
| 30 |
"""Operational error indicating a route is used for VPN. |
| 31 |
|
| 32 |
:param destinations: Destination CIDRs that are peers for VPN |
| 33 |
""" |
| 34 |
message = _("Route(s) to %(destinations)s are used for VPN") |
| 35 |
|
| 36 |
|
| 37 |
class VPNGatewayNotReady(nexception.BadRequest): |
| 38 |
message = _("VPN gateway not ready") |
| 39 |
|
| 40 |
|
| 41 |
class VPNGatewayInError(nexception.Conflict): |
| 42 |
message = _("VPN gateway is in ERROR state. " |
| 43 |
"Please remove all errored VPN services and try again.") |
| 44 |
|
| 45 |
|
| 46 |
class NoVPNAgentAvailable(nexception.ServiceUnavailable): |
| 47 |
message = _("No VPN agent available") |
| 48 |
|
| 49 |
|
| 50 |
class Vpnaas(extensions.APIExtensionDescriptor): |
| 51 |
api_definition = vpn |
| 52 |
|
| 53 |
@classmethod |
| 54 |
def get_resources(cls): |
| 55 |
special_mappings = {'ikepolicies': 'ikepolicy', |
| 56 |
'ipsecpolicies': 'ipsecpolicy'} |
| 57 |
plural_mappings = resource_helper.build_plural_mappings( |
| 58 |
special_mappings, vpn.RESOURCE_ATTRIBUTE_MAP) |
| 59 |
plural_mappings['peer_cidrs'] = 'peer_cidr' |
| 60 |
return resource_helper.build_resource_info( |
| 61 |
plural_mappings, |
| 62 |
vpn.RESOURCE_ATTRIBUTE_MAP, |
| 63 |
nconstants.VPN, |
| 64 |
register_quota=True, |
| 65 |
translate_name=True) |
| 66 |
|
| 67 |
@classmethod |
| 68 |
def get_plugin_interface(cls): |
| 69 |
return VPNPluginBase |
| 70 |
|
| 71 |
|
| 72 |
class VPNPluginBase(service_base.ServicePluginBase, metaclass=abc.ABCMeta): |
| 73 |
|
| 74 |
def get_plugin_type(self): |
| 75 |
return nconstants.VPN |
| 76 |
|
| 77 |
def get_plugin_description(self): |
| 78 |
return 'VPN service plugin' |
| 79 |
|
| 80 |
@abc.abstractmethod |
| 81 |
def get_vpnservices(self, context, filters=None, fields=None): |
| 82 |
pass |
| 83 |
|
| 84 |
@abc.abstractmethod |
| 85 |
def get_vpnservice(self, context, vpnservice_id, fields=None): |
| 86 |
pass |
| 87 |
|
| 88 |
@abc.abstractmethod |
| 89 |
def create_vpnservice(self, context, vpnservice): |
| 90 |
pass |
| 91 |
|
| 92 |
@abc.abstractmethod |
| 93 |
def update_vpnservice(self, context, vpnservice_id, vpnservice): |
| 94 |
pass |
| 95 |
|
| 96 |
@abc.abstractmethod |
| 97 |
def delete_vpnservice(self, context, vpnservice_id): |
| 98 |
pass |
| 99 |
|
| 100 |
@abc.abstractmethod |
| 101 |
def get_ipsec_site_connections(self, context, filters=None, fields=None): |
| 102 |
pass |
| 103 |
|
| 104 |
@abc.abstractmethod |
| 105 |
def get_ipsec_site_connection(self, context, |
| 106 |
ipsecsite_conn_id, fields=None): |
| 107 |
pass |
| 108 |
|
| 109 |
@abc.abstractmethod |
| 110 |
def create_ipsec_site_connection(self, context, ipsec_site_connection): |
| 111 |
pass |
| 112 |
|
| 113 |
@abc.abstractmethod |
| 114 |
def update_ipsec_site_connection(self, context, |
| 115 |
ipsecsite_conn_id, ipsec_site_connection): |
| 116 |
pass |
| 117 |
|
| 118 |
@abc.abstractmethod |
| 119 |
def delete_ipsec_site_connection(self, context, ipsecsite_conn_id): |
| 120 |
pass |
| 121 |
|
| 122 |
@abc.abstractmethod |
| 123 |
def get_ikepolicy(self, context, ikepolicy_id, fields=None): |
| 124 |
pass |
| 125 |
|
| 126 |
@abc.abstractmethod |
| 127 |
def get_ikepolicies(self, context, filters=None, fields=None): |
| 128 |
pass |
| 129 |
|
| 130 |
@abc.abstractmethod |
| 131 |
def create_ikepolicy(self, context, ikepolicy): |
| 132 |
pass |
| 133 |
|
| 134 |
@abc.abstractmethod |
| 135 |
def update_ikepolicy(self, context, ikepolicy_id, ikepolicy): |
| 136 |
pass |
| 137 |
|
| 138 |
@abc.abstractmethod |
| 139 |
def delete_ikepolicy(self, context, ikepolicy_id): |
| 140 |
pass |
| 141 |
|
| 142 |
@abc.abstractmethod |
| 143 |
def get_ipsecpolicies(self, context, filters=None, fields=None): |
| 144 |
pass |
| 145 |
|
| 146 |
@abc.abstractmethod |
| 147 |
def get_ipsecpolicy(self, context, ipsecpolicy_id, fields=None): |
| 148 |
pass |
| 149 |
|
| 150 |
@abc.abstractmethod |
| 151 |
def create_ipsecpolicy(self, context, ipsecpolicy): |
| 152 |
pass |
| 153 |
|
| 154 |
@abc.abstractmethod |
| 155 |
def update_ipsecpolicy(self, context, ipsecpolicy_id, ipsecpolicy): |
| 156 |
pass |
| 157 |
|
| 158 |
@abc.abstractmethod |
| 159 |
def delete_ipsecpolicy(self, context, ipsecpolicy_id): |
| 160 |
pass |