コード例 #1
0
ファイル: db_client.py プロジェクト: MrCocoaCat/ryu
    def run_command(self, args):
        _COMMANDS = {
            'list-dbs': self._list_dbs,
            'get-schema': self._get_schema,
            'get-schema-version': self._get_schema_version,
            'list-tables': self._list_tables,
            'list-columns': self._list_columns,
            'transact': self._transact,
            'monitor': self._monitor,
            'dump': self._dump,
        }

        command = args[0]
        args = args[1:]

        error, stream_ = stream.Stream.open_block(
            stream.Stream.open(self.remote))
        if error:
            raise RuntimeError('can not open socket to %s: %s' %
                               (self.remote, os.strerror(error)))
        rpc = jsonrpc.Connection(stream_)

        ret = _COMMANDS[command](rpc, *args)
        LOG.info('ret %s', ret)
        rpc.close()
コード例 #2
0
ファイル: idlutils.py プロジェクト: anlaneg/ovsdbapp
def get_schema_helper(connection, schema_name):
    """Create a schema helper object by querying an ovsdb-server

    :param connection: The ovsdb-server connection string
    :type connection: string
    :param schema_name: The schema on the server to pull
    :type schema_name: string
    """
    err, strm = stream.Stream.open_block(stream.Stream.open(connection))
    if err:
        #有错误,扔异常
        raise Exception("Could not connect to %s" % connection)
    #创建jsonrpc连接,请求命令'get_schema'
    rpc = jsonrpc.Connection(strm)
    req = jsonrpc.Message.create_request('get_schema', [schema_name])
    #等待响应
    err, resp = rpc.transact_block(req)
    rpc.close()
    if err:
        raise Exception("Could not retrieve schema from %(conn)s: "
                        "%(err)s" % {
                            'conn': connection,
                            'err': os.strerror(err)
                        })
    elif resp.error:
        raise Exception(resp.error)
    #封装返回的库描述信息(例如含哪些表,表结构是什么)
    return idl.SchemaHelper(None, resp.result)
コード例 #3
0
def get_schema_helper(connection, schema_name):
    err, strm = stream.Stream.open_block(stream.Stream.open(connection))
    if err:
        raise Exception("Could not connect to %s" % (connection, ))
    rpc = jsonrpc.Connection(strm)
    req = jsonrpc.Message.create_request('get_schema', [schema_name])
    err, resp = rpc.transact_block(req)
    rpc.close()
    if err:
        raise Exception("Could not retrieve schema from %s: %s" %
                        (connection, os.strerror(err)))
    elif resp.error:
        raise Exception(resp.error)
    return idl.SchemaHelper(None, resp.result)
コード例 #4
0
    def factory(cls, sock, address, *args, **kwargs):
        ovs_stream = stream.Stream(sock, None, None)
        connection = jsonrpc.Connection(ovs_stream)
        schemas = discover_schemas(connection)

        if not schemas:
            return

        fsm = reconnect.Reconnect(now())
        fsm.set_name('%s:%s' % address)
        fsm.enable(now())
        fsm.set_passive(True, now())
        fsm.set_max_tries(-1)
        fsm.connected(now())

        session = jsonrpc.Session(fsm, connection)
        idl = Idl(session, schemas[0])

        system_id = discover_system_id(idl)

        if not system_id:
            return None

        name = cls.instance_name(system_id)
        ovs_stream.name = name
        connection.name = name
        fsm.set_name(name)

        kwargs = kwargs.copy()
        kwargs['address'] = address
        kwargs['idl'] = idl
        kwargs['name'] = name
        kwargs['system_id'] = system_id

        app_mgr = app_manager.AppManager.get_instance()

        old_app = app_manager.lookup_service_brick(name)
        old_events = None
        if old_app:
            old_events = old_app.events
            app_mgr.uninstantiate(name)

        app = app_mgr.instantiate(cls, *args, **kwargs)

        if old_events:
            app.events = old_events

        return app
コード例 #5
0
ファイル: oidl.py プロジェクト: vinay200/utilities
def get_schema_helper(connection, schema_name):
    err, strm = stream.Stream.open_block(
        stream.Stream.open(connection))
    if err:
        print "Failure 1"
        raise Exception(_("Could not connect to %s") % connection)
    rpc = jsonrpc.Connection(strm)
    req = jsonrpc.Message.create_request('get_schema', [schema_name])
    err, resp = rpc.transact_block(req)
    rpc.close()
    if err:
        print "Failure 2"
        raise Exception(_("Could not retrieve schema from %(conn)s: "
                          "%(err)s") % {'conn': connection,
                                        'err': os.strerror(err)})
    elif resp.error:
        print "Failure 3"
        print resp.error
        raise Exception(resp.error)
    return idl.SchemaHelper(None, resp.result)
コード例 #6
0
def fetch_schema_json(connection, schema_name):
    """Retrieve the schema json from an ovsdb-server

    :param connection: The ovsdb-server connection string
    :type connection: string
    :param schema_name: The schema on the server to pull
    :type schema_name: string
    """
    parsed_connections = parse_connection(connection)

    for c in parsed_connections:
        err, strm = stream.Stream.open_block(stream.Stream.open(c))
        if err:
            LOG.error(
                "Unable to open stream to %(conn)s to retrieve schema: "
                "%(err)s", {
                    'conn': c,
                    'err': os.strerror(err)
                })
            continue
        rpc = jsonrpc.Connection(strm)
        req = jsonrpc.Message.create_request('get_schema', [schema_name])
        err, resp = rpc.transact_block(req)
        rpc.close()
        if err:
            LOG.info("Could not retrieve schema from %(conn)s: "
                     "%(err)s", {
                         'conn': c,
                         'err': os.strerror(err)
                     })
            continue
        if resp.error:
            LOG.error(
                "TRXN error, failed to retrieve schema from %(conn)s: "
                "%(err)s", {
                    'conn': c,
                    'err': resp.error
                })
            continue
        return resp.result
    raise Exception("Could not retrieve schema from %s" % connection)
コード例 #7
0
    def factory(cls,
                sock,
                address,
                probe_interval=None,
                min_backoff=None,
                max_backoff=None,
                schema_tables=None,
                schema_exclude_columns=None,
                *args,
                **kwargs):
        schema_exclude_columns = schema_exclude_columns or {}
        ovs_stream = stream.Stream(sock, None, None)
        connection = jsonrpc.Connection(ovs_stream)
        schemas = discover_schemas(connection)

        if not schemas:
            return

        if schema_tables or schema_exclude_columns:
            schemas = _filter_schemas(schemas, schema_tables,
                                      schema_exclude_columns)

        fsm = reconnect.Reconnect(now())
        fsm.set_name('%s:%s' % address[:2])
        fsm.enable(now())
        fsm.set_passive(True, now())
        fsm.set_max_tries(-1)

        if probe_interval is not None:
            fsm.set_probe_interval(probe_interval)

        if min_backoff is None:
            min_backoff = fsm.get_min_backoff()

        if max_backoff is None:
            max_backoff = fsm.get_max_backoff()

        if min_backoff and max_backoff:
            fsm.set_backoff(min_backoff, max_backoff)

        fsm.connected(now())

        session = jsonrpc.Session(fsm, connection)
        idl = Idl(session, schemas[0])

        system_id = discover_system_id(idl)

        if not system_id:
            return None

        name = cls.instance_name(system_id)
        ovs_stream.name = name
        connection.name = name
        fsm.set_name(name)

        kwargs = kwargs.copy()
        kwargs['socket'] = sock
        kwargs['address'] = address
        kwargs['idl'] = idl
        kwargs['name'] = name
        kwargs['system_id'] = system_id

        app_mgr = app_manager.AppManager.get_instance()

        old_app = app_manager.lookup_service_brick(name)
        old_events = None
        if old_app:
            old_events = old_app.events
            app_mgr.uninstantiate(name)

        app = app_mgr.instantiate(cls, *args, **kwargs)

        if old_events:
            app.events = old_events

        return app