2016-12-07 14:47:26 -08:00
|
|
|
# Copyright (c) 2016 Cisco Systems, Inc.
|
|
|
|
# All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
|
2016-12-19 12:19:47 -08:00
|
|
|
# Some constants and verifier functions have been deprecated but are still
|
|
|
|
# used by earlier releases of neutron. In order to maintain
|
|
|
|
# backwards-compatibility with stable/mitaka this will act as a translator
|
|
|
|
# that passes constants and functions according to version number.
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
2016-12-22 20:11:13 -08:00
|
|
|
# Mitaka+
|
2016-12-19 12:19:47 -08:00
|
|
|
import neutron_lib.constants
|
|
|
|
import neutron_lib.exceptions
|
|
|
|
|
|
|
|
n_const = neutron_lib.constants
|
|
|
|
n_exec = neutron_lib.exceptions
|
|
|
|
|
|
|
|
except ImportError:
|
2017-01-06 15:53:38 -07:00
|
|
|
import neutron.common.constants
|
2016-12-19 12:19:47 -08:00
|
|
|
import neutron.common.exceptions
|
|
|
|
|
2017-01-06 15:53:38 -07:00
|
|
|
n_const = neutron.common.constants
|
2016-12-19 12:19:47 -08:00
|
|
|
n_exec = neutron.common.exceptions
|
2016-12-22 20:11:13 -08:00
|
|
|
|
|
|
|
try:
|
|
|
|
# Newton+
|
|
|
|
import neutron_lib.db.model_base
|
|
|
|
import neutron_lib.plugins.directory
|
|
|
|
|
|
|
|
model_base = neutron_lib.db.model_base
|
|
|
|
directory = neutron_lib.plugins.directory
|
|
|
|
|
|
|
|
except ImportError:
|
2016-12-23 00:30:20 -08:00
|
|
|
import neutron.db.model_base
|
2016-12-22 20:11:13 -08:00
|
|
|
import neutron.manager
|
|
|
|
|
2016-12-19 12:19:47 -08:00
|
|
|
directory = neutron.manager.NeutronManager
|
2016-12-22 20:11:13 -08:00
|
|
|
model_base = neutron.db.model_base
|
2016-12-19 12:19:47 -08:00
|
|
|
|
2016-12-07 14:47:26 -08:00
|
|
|
import os
|
|
|
|
|
|
|
|
from neutron.agent.linux import bridge_lib
|
|
|
|
|
|
|
|
|
|
|
|
def monkey_patch():
|
|
|
|
"""Add backward compatibility to networking-vpp for Liberty
|
|
|
|
|
|
|
|
This monkey-patches a couple of bits of Neutron
|
|
|
|
to enable compatibility with Liberty.
|
|
|
|
"""
|
2016-12-19 12:19:47 -08:00
|
|
|
|
2016-12-07 14:47:26 -08:00
|
|
|
if 'owns_interface' not in dir(bridge_lib.BridgeDevice):
|
|
|
|
BRIDGE_INTERFACE_FS = "/sys/class/net/%(bridge)s/brif/%(interface)s"
|
|
|
|
|
|
|
|
def owns_interface(self, interface):
|
|
|
|
return os.path.exists(
|
|
|
|
BRIDGE_INTERFACE_FS % {'bridge': self.name,
|
|
|
|
'interface': interface})
|
|
|
|
|
|
|
|
bridge_lib.BridgeDevice.owns_interface = owns_interface
|
|
|
|
|
|
|
|
if 'get_log_fail_as_error' not in dir(bridge_lib.BridgeDevice):
|
|
|
|
|
|
|
|
def get_log_fail_as_error(self):
|
|
|
|
return self.log_fail_as_error
|
|
|
|
|
|
|
|
bridge_lib.BridgeDevice.get_log_fail_as_error = get_log_fail_as_error
|
|
|
|
|
|
|
|
if 'exists' not in dir(bridge_lib.BridgeDevice):
|
|
|
|
|
|
|
|
def exists(self):
|
|
|
|
orig_log_fail_as_error = self.get_log_fail_as_error()
|
|
|
|
self.set_log_fail_as_error(False)
|
|
|
|
try:
|
|
|
|
return bool(self.link.address)
|
|
|
|
except RuntimeError:
|
|
|
|
return False
|
|
|
|
finally:
|
|
|
|
self.set_log_fail_as_error(orig_log_fail_as_error)
|
|
|
|
|
|
|
|
bridge_lib.BridgeDevice.exists = exists
|