| 1 |
# Copyright (C) 2016 Midokura SARL. |
| 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.exceptions import taas |
| 16 |
|
| 17 |
from oslo_log import log |
| 18 |
|
| 19 |
LOG = log.getLogger(__name__) |
| 20 |
|
| 21 |
|
| 22 |
class ServiceDriverContext: |
| 23 |
"""ServiceDriverContext context base class""" |
| 24 |
def __init__(self, service_plugin, plugin_context): |
| 25 |
self._plugin = service_plugin |
| 26 |
self._plugin_context = plugin_context |
| 27 |
|
| 28 |
|
| 29 |
class TapServiceContext(ServiceDriverContext): |
| 30 |
|
| 31 |
def __init__(self, service_plugin, plugin_context, tap_service): |
| 32 |
super().__init__(service_plugin, plugin_context) |
| 33 |
self._tap_service = tap_service |
| 34 |
self._tap_id_association = None |
| 35 |
self._setup_tap_id_association(tap_service['id']) |
| 36 |
|
| 37 |
def _setup_tap_id_association(self, tap_service_id): |
| 38 |
try: |
| 39 |
self._tap_id_association = self._plugin.get_tap_id_association( |
| 40 |
self._plugin_context, tap_service_id) |
| 41 |
except taas.TapServiceNotFound: |
| 42 |
LOG.debug("Not found tap_ip_association for tap_service: %s", |
| 43 |
tap_service_id) |
| 44 |
|
| 45 |
@property |
| 46 |
def tap_service(self): |
| 47 |
return self._tap_service |
| 48 |
|
| 49 |
@property |
| 50 |
def tap_id_association(self): |
| 51 |
return self._tap_id_association |
| 52 |
|
| 53 |
@tap_id_association.setter |
| 54 |
def tap_id_association(self, tap_id_association): |
| 55 |
"""Set tap_id_association in context""" |
| 56 |
self._tap_id_association = tap_id_association |
| 57 |
|
| 58 |
|
| 59 |
class TapFlowContext(ServiceDriverContext): |
| 60 |
|
| 61 |
def __init__(self, service_plugin, plugin_context, tap_flow): |
| 62 |
super().__init__(service_plugin, plugin_context) |
| 63 |
self._tap_flow = tap_flow |
| 64 |
|
| 65 |
@property |
| 66 |
def tap_flow(self): |
| 67 |
return self._tap_flow |
| 68 |
|
| 69 |
|
| 70 |
class TapMirrorContext(ServiceDriverContext): |
| 71 |
|
| 72 |
def __init__(self, service_plugin, plugin_context, tap_mirror): |
| 73 |
super().__init__(service_plugin, plugin_context) |
| 74 |
self._tap_mirror = tap_mirror |
| 75 |
|
| 76 |
@property |
| 77 |
def tap_mirror(self): |
| 78 |
return self._tap_mirror |