def from_server(cls, schema_map, tables): """Create the Idl instance by pulling the schema from OVSDB server""" connection_string = schema_map[cls.schema] helper = idlutils.get_schema_helper(connection_string, cls.schema) for table in tables: helper.register_table(table) return cls(connection_string, helper)
def from_server(cls, connection_string, schema_name, *args, helper=None, helper_tables=None, **kwargs): """Create the Idl instance by pulling the schema from OVSDB server :param connection_string: Connection name :type connection_string: string :param schema_name: Schema name :type schema: string :param helper: Helper instance :type helper: ``idl.SchemaHelper`` :param helper_tables: Tables to be registered in the helper :type helper_tables: Iterator of strings """ if not helper: helper = idlutils.get_schema_helper(connection_string, schema_name) if not helper_tables: helper.register_all() else: for table in helper_tables: helper.register_table(table) return cls(connection_string, helper, **kwargs)
def from_server(cls, connection_string, schema_name, driver): _check_and_set_ssl_files(schema_name) helper = idlutils.get_schema_helper(connection_string, schema_name) helper.register_all() _idl = cls(driver, connection_string, helper) _idl.set_lock(_idl.event_lock_name) return _idl
def from_server(cls, connection_string, schema_name): _check_and_set_ssl_files(schema_name) helper = idlutils.get_schema_helper(connection_string, schema_name) helper.register_table('Chassis') helper.register_table('Encap') helper.register_table('Port_Binding') helper.register_table('Datapath_Binding') return cls(connection_string, helper)
def get_ovsdb_connection(connection_string, schema, timeout, tables=None): helper = idlutils.get_schema_helper(connection_string, schema) if tables: for table in tables: helper.register_table(table) else: helper.register_all() return connection.Connection(idl.Idl(connection_string, helper), timeout)
def from_server(cls, connection_string, schema_name): _check_and_set_ssl_files(schema_name) helper = idlutils.get_schema_helper(connection_string, schema_name) helper.register_table('Chassis') if ovn_config.is_ovn_metadata_enabled(): helper.register_table('Port_Binding') helper.register_table('Datapath_Binding') return cls(connection_string, helper)
def __init__(self, events=None): connection_string = config.get_ovn_sb_connection() helper = idlutils.get_schema_helper(connection_string, self.SCHEMA) tables = ('Chassis', 'Port_Binding', 'Datapath_Binding') for table in tables: helper.register_table(table) super(MetadataAgentOvnSbIdl, self).__init__(None, connection_string, helper) if events: self.notify_handler.watch_events(events)
def start(self): connection_string = config.cfg.CONF.ovs.ovsdb_connection helper = idlutils.get_schema_helper(connection_string, 'Open_vSwitch') tables = ('Open_vSwitch', 'Bridge', 'Port', 'Interface') for table in tables: helper.register_table(table) ovs_idl = idl.Idl(connection_string, helper) conn = connection.Connection( ovs_idl, timeout=config.cfg.CONF.ovs.ovsdb_connection_timeout) return idl_ovs.OvsdbIdl(conn)
def df_idl_from_server(connection_string, schema_name, db_change_callback): """Create the Idl instance by pulling the schema from OVSDB server""" helper = idlutils.get_schema_helper(connection_string, schema_name) tables = ovsdb_monitor_table_filter_default for table_name, columns in tables.items(): if columns == 'all': helper.register_table(table_name) else: helper.register_columns(table_name, columns) return DFIdl(connection_string, helper, db_change_callback)
def from_server(cls, connection_string, schema_name, driver): _check_and_set_ssl_files(schema_name) helper = idlutils.get_schema_helper(connection_string, schema_name) helper.register_table('Chassis') helper.register_table('Encap') helper.register_table('Port_Binding') helper.register_table('Datapath_Binding') _idl = cls(driver, connection_string, helper) _idl.set_lock(_idl.event_lock_name) return _idl
def from_server(cls, connection_string, schema_name, driver): _check_and_set_ssl_files(schema_name) helper = idlutils.get_schema_helper(connection_string, schema_name) if 'Chassis_Private' in helper.schema_json['tables']: helper.register_table('Chassis_Private') helper.register_table('Chassis') helper.register_table('Encap') helper.register_table('Port_Binding') helper.register_table('Datapath_Binding') helper.register_table('MAC_Binding') return cls(driver, connection_string, helper)
def start(self, connection_string): helper = idlutils.get_schema_helper(connection_string, 'Open_vSwitch') tables = ('Open_vSwitch', 'Bridge', 'Port', 'Interface') for table in tables: helper.register_table(table) ovs_idl = idl.Idl(connection_string, helper) ovs_idl._session.reconnect.set_probe_interval(60000) conn = connection.Connection( ovs_idl, timeout=180) self.idl_ovs = idl_ovs.OvsdbIdl(conn)
def __init__(self, driver, remote, schema='Open_vSwitch'): helper = idlutils.get_schema_helper(remote, schema_name=schema) helper.register_all() super(OvsNotificationIdl, self).__init__(driver, remote, helper) # it gets a dump of all events when connected to ovsdb-server, # if you watch events here. self._port_event = PortEvent(self.driver) self._bridge_event = BridgeEvent(self.driver) self.notify_handler.watch_events([self._port_event, self._bridge_event])
def schema_helper(cls): # SchemaHelper.get_idl_schema() sets schema_json to None which is # called in Idl.__init__(), so if we've done that return new helper try: if cls._schema_helper.schema_json: return cls._schema_helper except AttributeError: pass ovsdb_monitor._check_and_set_ssl_files(cls.schema) cls._schema_helper = idlutils.get_schema_helper(cls.connection_string, cls.schema) return cls._schema_helper
def from_server(cls, connection_string, schema_name, driver, pg_only=False): _check_and_set_ssl_files(schema_name) helper = idlutils.get_schema_helper(connection_string, schema_name) if pg_only: helper.register_table('Port_Group') else: for table in cls.tables: helper.register_table(table) return cls(driver, connection_string, helper)
def from_server(cls, connection_string, schema_name): """Create the Idl instance by pulling the schema from OVSDB server""" remotes = connection_string.split(',') for remote in remotes: try: helper = idlutils.get_schema_helper(remote, schema_name) helper.register_all() return cls(connection_string, helper) except Exception as e: # one of multiple servers is not available, try next one logger.debug("connection to {} failed: {}".format(remote, e)) continue raise Exception("Could not connect to any of the remotes %s" % connection_string.split(','))
def test_ovsdb_connections(self): klasses = { ovsdb_monitor.OvnNbIdl: ('OVN_Northbound', { 'driver': self.mech_driver }), ovsdb_monitor.OvnSbIdl: ('OVN_Southbound', { 'driver': self.mech_driver }) } for kls, (schema, kwargs) in klasses.items(): conns = self.connections[schema] idl = kls.from_server(conns, idlutils.get_schema_helper(conns, schema), **kwargs) self.assertEqual(set(idlutils.parse_connection(conns)), set(idl._session.remotes))
def idl_factory(): conn = cfg.CONF.OVS.ovsdb_connection schema_name = 'Open_vSwitch' try: helper = idlutils.get_schema_helper(conn, schema_name) except Exception: helpers.enable_connection_uri(conn) @tenacity.retry(wait=tenacity.wait_exponential(multiplier=0.01), stop=tenacity.stop_after_delay(1), reraise=True) def do_get_schema_helper(): return idlutils.get_schema_helper(conn, schema_name) helper = do_get_schema_helper() # TODO(twilson) We should still select only the tables/columns we use helper.register_all() return idl.Idl(conn, helper)
def test_ovsdb_probe_interval(self): klasses = { ovsdb_monitor.BaseOvnIdl: ('OVN_Northbound', {}), ovsdb_monitor.OvnNbIdl: ('OVN_Northbound', { 'driver': self.mech_driver }), ovsdb_monitor.OvnSbIdl: ('OVN_Southbound', { 'driver': self.mech_driver }) } idls = [ kls.from_server( self.connections[schema], idlutils.get_schema_helper(self.connections[schema], schema), **kwargs) for kls, (schema, kwargs) in klasses.items() ] interval = ovn_conf.get_ovn_ovsdb_probe_interval() for idl in idls: self.assertEqual(interval, idl._session.reconnect.probe_interval)
def from_server(cls, connection_string, schema_name): """Create the Idl instance by pulling the schema from OVSDB server""" helper = idlutils.get_schema_helper(connection_string, schema_name) helper.register_all() return cls(connection_string, helper)
def from_server(cls, connection_string, schema_name): _check_and_set_ssl_files(schema_name) helper = idlutils.get_schema_helper(connection_string, schema_name) helper.register_all() return cls(connection_string, helper)
def idl_factory(conn, schema): helper = idlutils.get_schema_helper(conn, schema) helper.register_all() return idl.Idl(conn, helper)
def get_schema(self): with mock.patch.object( idlutils, 'create_schema_helper', side_effect=create_schema_helper): return idlutils.get_schema_helper( self.schema_map[TestingOvsIdl.schema], TestingOvsIdl.schema)
def _get_ovsdb_helper(self, connection): try: return idlutils.get_schema_helper(connection, self.SCHEMA) except Exception: helpers.enable_connection_uri(connection) return self._do_get_schema_helper(connection)
def _do_get_schema_helper(self, connection): return idlutils.get_schema_helper(connection, self.SCHEMA)
def do_get_schema_helper(): return idlutils.get_schema_helper(conn, schema_name)
def idl_factory(config): conn = config.connection schema_name = 'Open_vSwitch' helper = idlutils.get_schema_helper(conn, schema_name) helper.register_all() return idl.Idl(conn, helper)
def _get_ovsdb_helper(self, connection_string): return idlutils.get_schema_helper(connection_string, self.SCHEMA)
# # 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. import os from ovsdbapp.backend.ovs_idl import connection from ovsdbapp.backend.ovs_idl import idlutils from ovsdbapp.schema.ovn_northbound import impl_idl import ovs.db.idl remote = 'unix:/usr/local/var/run/openvswitch/ovnnb_db.sock' schema = idlutils.get_schema_helper(remote, 'OVN_Northbound') schema.register_all() idl = ovs.db.idl.Idl(remote, schema) conn = connection.Connection(idl, timeout=60) api = impl_idl.OvnNbApiIdlImpl(conn) def _get_mac_ip_from_port(port, ip_version=4): addresses = port.addresses[0].split() return addresses[0], addresses[1 if ip_version == 4 else 2] def _get_lsp_ls_id(lsp): # OpenStack saves the network name in the external_ids of the port net = lsp.external_ids.get('neutron:network_name') if not net:
def __init__(self, connection_string, schema_name, notification_backend): helper = idlutils.get_schema_helper(connection_string, schema_name) helper.register_all() self._notification_backend = notification_backend super(OvnIdl, self).__init__(connection_string, helper)