How to use the ovs.db.idl function in ovs

To help you get started, we’ve selected a few ovs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github osrg / ryu / ryu / lib / ovs / vsctl.py View on Github external
def _do_main(self, commands):
        """
        :type commands: list of VSCtlCommand
        """
        self._reset()
        self._init_schema_helper()
        self._run_prerequisites(commands)

        idl_ = idl.Idl(self.remote, self.schema_helper)
        seqno = idl_.change_seqno
        while True:
            self._idl_wait(idl_, seqno)

            seqno = idl_.change_seqno
            if self._do_vsctl(idl_, commands):
                break

            if self.txn:
                self.txn.abort()
                self.txn = None
            # TODO:XXX
            # ovsdb_symbol_table_destroy(symtab)

        idl_.close()
github openstack / dragonflow / dragonflow / db / drivers / ovsdb_nb_impl.py View on Github external
def register_local_ports(self, chassis_name, local_ports_ids):
        txn = idl.Transaction(self.idl)

        chassis = idlutils.row_by_value(self.idl,
                                        'Chassis',
                                        'name', chassis_name)

        for binding in self.idl.tables['Binding'].rows.values():
            if binding.logical_port in local_ports_ids:
                if binding.chassis == chassis_name:
                    continue
                # Bind this port to this chassis
                binding.chassis = chassis
            elif binding.chassis == chassis_name:
                binding.chassis = []

        status = txn.commit_block()
        return status
github osrg / ryu / ryu / lib / ovs / vsctl.py View on Github external
def _init_schema_helper(self):
        if self.schema_json is None:
            self.schema_json = self._rpc_get_schema_json(
                vswitch_idl.OVSREC_DB_NAME)
            schema_helper = idl.SchemaHelper(None, self.schema_json)
            schema_helper.register_all()
            self.schema = schema_helper.get_idl_schema()
        # LOG.debug('schema_json %s', schema_json)
        self.schema_helper = idl.SchemaHelper(None, self.schema_json)
github openstack / networking-ovn / networking_ovn / ovsdb / row_event.py View on Github external
import abc

from oslo_log import log as logging
from ovs.db import idl
import six

from ovsdbapp.backend.ovs_idl import idlutils

LOG = logging.getLogger(__name__)


@six.add_metaclass(abc.ABCMeta)
class RowEvent(object):
    ROW_CREATE = idl.ROW_CREATE
    ROW_UPDATE = idl.ROW_UPDATE
    ROW_DELETE = idl.ROW_DELETE
    ONETIME = False

    def __init__(self, events, table, conditions, old_conditions=None):
        self.table = table
        self.events = events
        self.conditions = conditions
        self.old_conditions = old_conditions
        self.event_name = 'RowEvent'

    def _key(self):
        return (self.__class__, self.table, self.events, self.conditions)

    def __hash__(self):
        return hash(self._key())

    def __eq__(self, other):
github frenetic-lang / pyretic / pyretic / vendor / ryu / ryu / lib / ovs / vsctl.py View on Github external
#     for command in commands:
        #         if not command.post_func:
        #             continue
        #         ctx = VSCtlContext(idl_, txn, self.ovs)
        #         command.post_func(ctx)
        #         ctx.done()

        txn_ = self.txn
        self.txn = None
        txn = None

        if status in (idl.Transaction.UNCOMMITTED, idl.Transaction.INCOMPLETE):
            not_reached()
        elif status == idl.Transaction.ABORTED:
            vsctl_fatal('transaction aborted')
        elif status in (idl.Transaction.UNCHANGED, idl.Transaction.SUCCESS):
            pass
        elif status == idl.Transaction.TRY_AGAIN:
            return False
        elif status == idl.Transaction.ERROR:
            vsctl_fatal('transaction error: %s' % txn_.get_error())
        elif status == idl.Transaction.NOT_LOCKED:
            vsctl_fatal('database not locked')
        else:
            not_reached()

        if self.wait_for_reload and status != idl.Transaction.UNCHANGED:
            while True:
                idl_.run()
                if (ovs_.cur_cfg >= next_cfg):
                    break
                self._idl_block(idl_)
github openstack / networking-l2gw / networking_l2gw / services / l2gateway / agent / ovsdb / native / connection.py View on Github external
def get_schema_helper_for_vtep():
    current_dir = os.path.dirname(os.path.realpath(__file__))
    return idl.SchemaHelper(current_dir + '/../vtep/vtep.ovsschema')
github osrg / ryu / ryu / lib / ovs / vsctl.py View on Github external
def _clear(self, ctx, table_name, record_id, column):
        vsctl_table = self._get_table(table_name)
        ovsrec_row = ctx.must_get_row(vsctl_table, record_id)
        column_schema = ctx.idl.tables[table_name].columns[column]
        if column_schema.type.n_min > 0:
            vsctl_fatal('"clear" operation cannot be applied to column %s '
                        'of table %s, which is not allowed to be empty' %
                        (column, table_name))

        # assuming that default datum is empty.
        default_datum = ovs.db.data.Datum.default(column_schema.type)
        setattr(ovsrec_row, column,
                default_datum.to_python(ovs.db.idl._uuid_to_row))
        ctx.invalidate_cache()
github openstack / networking-l2gw / networking_l2gw / services / l2gateway / agent / ovsdb / native / connection.py View on Github external
def __init__(self, connection, timeout, schema_name):
        idl_ = idl.Idl(connection, get_schema_helper_for_vtep())
        super(Connection, self).__init__(idl_, timeout)
github osrg / ryu / ryu / lib / ovs / vsctl.py View on Github external
elif status == idl.Transaction.ABORTED:
            vsctl_fatal('transaction aborted')
        elif status == idl.Transaction.UNCHANGED:
            LOG.debug('unchanged')
        elif status == idl.Transaction.SUCCESS:
            LOG.debug('success')
        elif status == idl.Transaction.TRY_AGAIN:
            return False
        elif status == idl.Transaction.ERROR:
            vsctl_fatal('transaction error: %s' % txn_.get_error())
        elif status == idl.Transaction.NOT_LOCKED:
            vsctl_fatal('database not locked')
        else:
            not_reached()

        if self.wait_for_reload and status != idl.Transaction.UNCHANGED:
            while True:
                idl_.run()
                if ovs_.cur_cfg >= next_cfg:
                    break
                self._idl_block(idl_)

        return True
github frenetic-lang / pyretic / pyretic / vendor / ryu / ryu / lib / ovs / vsctl.py View on Github external
def _init_schema_helper(self):
        if self.schema_json is None:
            self.schema_json = self._rpc_get_schema_json(
                vswitch_idl.OVSREC_DB_NAME)
            schema_helper = idl.SchemaHelper(None, self.schema_json)
            schema_helper.register_all()
            self.schema = schema_helper.get_idl_schema()
        # LOG.debug('schema_json %s', schema_json)
        self.schema_helper = idl.SchemaHelper(None, self.schema_json)