Debian Codegraph @

neutron_vpnaas/agent/ovn/vpn/ovsdb.py

raw
1 # Copyright 2017 Red Hat, Inc.
2 # Copyright 2023 SysEleven GmbH
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain 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,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 from neutron.conf.plugins.ml2.drivers.ovn import ovn_conf as config
17 from neutron.plugins.ml2.drivers.ovn.mech_driver.ovsdb import impl_idl_ovn
18 from neutron.plugins.ml2.drivers.ovn.mech_driver.ovsdb import ovsdb_monitor
19 from oslo_log import log as logging
20 from ovs.db import idl
21 from ovsdbapp.backend.ovs_idl import connection
22 from ovsdbapp.backend.ovs_idl import idlutils
23 from ovsdbapp.schema.open_vswitch import impl_idl as idl_ovs
24 import tenacity
25
26 LOG = logging.getLogger(__name__)
27
28
29 class VPNAgentOvnSbIdl(ovsdb_monitor.OvnIdl):
30
31 SCHEMA = 'OVN_Southbound'
32
33 def __init__(self, chassis=None, events=None, tables=None):
34 connection_string = config.get_ovn_sb_connection()
35 ovsdb_monitor._check_and_set_ssl_files(self.SCHEMA)
36 helper = self._get_ovsdb_helper(connection_string)
37 if tables is None:
38 tables = ('Chassis', 'SB_Global')
39 for table in tables:
40 helper.register_table(table)
41 try:
42 super().__init__(
43 None, connection_string, helper, leader_only=False)
44 except TypeError:
45 # TODO(bpetermann) We can remove this when we require ovs>=2.12.0
46 super().__init__(None, connection_string, helper)
47 if chassis:
48 table = ('Chassis_Private' if 'Chassis_Private' in tables
49 else 'Chassis')
50 self.set_table_condition(table, [['name', '==', chassis]])
51 if events:
52 self.notify_handler.watch_events(events)
53
54 @tenacity.retry(
55 wait=tenacity.wait_exponential(max=180),
56 reraise=True)
57 def _get_ovsdb_helper(self, connection_string):
58 return idlutils.get_schema_helper(connection_string, self.SCHEMA)
59
60 def start(self):
61 conn = connection.Connection(
62 self, timeout=config.get_ovn_ovsdb_timeout())
63 return impl_idl_ovn.OvsdbSbOvnIdl(conn)
64
65
66 class VPNAgentOvsIdl:
67
68 def start(self):
69 connection_string = config.cfg.CONF.ovs.ovsdb_connection
70 helper = idlutils.get_schema_helper(connection_string,
71 'Open_vSwitch')
72 tables = ('Open_vSwitch', 'Bridge', 'Port', 'Interface')
73 for table in tables:
74 helper.register_table(table)
75 ovs_idl = idl.Idl(
76 connection_string, helper,
77 probe_interval=config.get_ovn_ovsdb_probe_interval())
78 conn = connection.Connection(
79 ovs_idl, timeout=config.cfg.CONF.ovs.ovsdb_connection_timeout)
80 return idl_ovs.OvsdbIdl(conn)