| 1 |
# (c) Copyright 2016 IBM Corporation |
| 2 |
# (c) Copyright 2023 SysEleven GmbH |
| 3 |
# All Rights Reserved. |
| 4 |
# |
| 5 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 |
# not use this file except in compliance with the License. You may obtain |
| 7 |
# a copy of the License at |
| 8 |
# |
| 9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
# |
| 11 |
# Unless required by applicable law or agreed to in writing, software |
| 12 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 |
# License for the specific language governing permissions and limitations |
| 15 |
# under the License. |
| 16 |
|
| 17 |
from neutron_lib.callbacks import events |
| 18 |
from neutron_lib.callbacks import registry |
| 19 |
from neutron_lib.callbacks import resources |
| 20 |
from oslo_config import cfg |
| 21 |
from oslo_utils import importutils |
| 22 |
|
| 23 |
from neutron_vpnaas.api.rpc.agentnotifiers import vpn_rpc_agent_api as nfy_api |
| 24 |
from neutron_vpnaas.db.vpn import vpn_agentschedulers_db as agent_db |
| 25 |
from neutron_vpnaas.db.vpn.vpn_db import VPNPluginDb |
| 26 |
from neutron_vpnaas.db.vpn import vpn_ext_gw_db |
| 27 |
from neutron_vpnaas.services.vpn.common import constants |
| 28 |
from neutron_vpnaas.services.vpn.ovn import agent_monitor |
| 29 |
from neutron_vpnaas.services.vpn.plugin import VPNDriverPlugin |
| 30 |
|
| 31 |
|
| 32 |
class VPNOVNPlugin(VPNPluginDb, |
| 33 |
vpn_ext_gw_db.VPNExtGWPlugin_db, |
| 34 |
agent_db.AZVPNAgentSchedulerDbMixin, |
| 35 |
agent_monitor.OVNVPNAgentMonitor): |
| 36 |
"""Implementation of the VPN Service Plugin. |
| 37 |
|
| 38 |
This class manages the workflow of VPNaaS request/response. |
| 39 |
Most DB related works are implemented in class |
| 40 |
vpn_db.VPNPluginDb. |
| 41 |
""" |
| 42 |
def __init__(self): |
| 43 |
self.vpn_scheduler = importutils.import_object( |
| 44 |
cfg.CONF.vpn_scheduler_driver) |
| 45 |
self.add_periodic_vpn_agent_status_check() |
| 46 |
self.agent_notifiers[constants.AGENT_TYPE_VPN] = \ |
| 47 |
nfy_api.VPNAgentNotifyAPI() |
| 48 |
super().__init__() |
| 49 |
registry.subscribe(self.post_fork_initialize, |
| 50 |
resources.PROCESS, |
| 51 |
events.AFTER_INIT) |
| 52 |
|
| 53 |
def check_router_in_use(self, context, router_id): |
| 54 |
pass |
| 55 |
|
| 56 |
def post_fork_initialize(self, resource, event, trigger, payload=None): |
| 57 |
self.watch_agent_events() |
| 58 |
|
| 59 |
def vpn_router_agent_binding_changed(self, context, router_id, host): |
| 60 |
pass |
| 61 |
|
| 62 |
supported_extension_aliases = ["vpnaas", |
| 63 |
"vpn-endpoint-groups", |
| 64 |
"service-type", |
| 65 |
"vpn-agent-scheduler", |
| 66 |
"vpn-aes-ctr"] |
| 67 |
path_prefix = "/vpn" |
| 68 |
|
| 69 |
|
| 70 |
class VPNOVNDriverPlugin(VPNOVNPlugin, VPNDriverPlugin): |
| 71 |
def vpn_router_agent_binding_changed(self, context, router_id, host): |
| 72 |
super().vpn_router_agent_binding_changed(context, router_id, host) |
| 73 |
filters = {'router_id': [router_id]} |
| 74 |
vpnservices = self.get_vpnservices(context, filters=filters) |
| 75 |
for vpnservice in vpnservices: |
| 76 |
driver = self._get_driver_for_vpnservice(context, vpnservice) |
| 77 |
driver.update_port_bindings(context, router_id, host) |