How to use the ovs.json 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 ovn-org / ovn / tests / test-jsonrpc.py View on Github external
def do_notify(name, method, params_string):
    params = ovs.json.from_string(params_string)
    msg = ovs.jsonrpc.Message.create_notify(method, params)
    s = msg.is_valid()
    if s:
        sys.stderr.write("not a valid JSON-RPC notification: %s\n" % s)
        sys.exit(1)

    error, stream = ovs.stream.Stream.open_block(ovs.stream.Stream.open(name))
    if error:
        sys.stderr.write("could not open \"%s\": %s\n"
                         % (name, os.strerror(error)))
        sys.exit(1)

    rpc = ovs.jsonrpc.Connection(stream)

    error = rpc.send_block(msg)
    if error:
github ovn-org / ovn / tests / test-ovsdb.py View on Github external
def do_parse_base_type(type_string):
    type_json = unbox_json(ovs.json.from_string(type_string))
    base_type = ovs.db.types.BaseType.from_json(type_json)
    print(ovs.json.to_string(base_type.to_json(), sort_keys=True))
github ovn-org / ovn / tests / test-ovsdb.py View on Github external
def do_parse_base_type(type_string):
    type_json = unbox_json(ovs.json.from_string(type_string))
    base_type = ovs.db.types.BaseType.from_json(type_json)
    print(ovs.json.to_string(base_type.to_json(), sort_keys=True))
github ovn-org / ovn / tests / test-json.py View on Github external
def parse_multiple(stream):
    buf = stream.read(4096)
    ok = True
    parser = None
    while len(buf):
        if parser is None and buf[0] in " \t\r\n":
            buf = buf[1:]
        else:
            if parser is None:
                parser = ovs.json.Parser()
            n = parser.feed(buf)
            buf = buf[n:]
            if len(buf):
                if not print_json(parser.finish()):
                    ok = False
                parser = None
        if len(buf) == 0:
            buf = stream.read(4096)
    if parser and not print_json(parser.finish()):
        ok = False
    return ok
github frenetic-lang / pyretic / pyretic / vendor / ryu / ryu / contrib / ovs / db / idl.py View on Github external
def __set_error_json(self, json):
        if self._error is None:
            self._error = ovs.json.to_string(json)
github ovn-org / ovn / ovsdb / ovsdbmonitor / OVEConfig.py View on Github external
def saveConfig(self):
        settings = QtCore.QSettings()
        settings.setValue('config/hosts', QVariant(ovs.json.to_string((self.hosts))))
        settings.setValue('config/logTraffic', QVariant(self.logTraffic))
        settings.setValue('config/truncateUuids', QVariant(self.truncateUuids))
        settings.setValue('config/ssgList', QVariant(ovs.json.to_string(self.ssgList)))
        settings.sync()
        self.emitUpdated()
github ovn-org / ovn / python / ovs / db / idl.py View on Github external
def __set_error_json(self, json):
        if self._error is None:
            self._error = ovs.json.to_string(json)
github frenetic-lang / pyretic / pyretic / vendor / ryu / ryu / contrib / ovs / db / idl.py View on Github external
def __init__(self, location=None, schema_json=None):
        """Creates a new Schema object.

        'location' file path to ovs schema. None means default location
        'schema_json' schema in json preresentation in memory
        """

        if location and schema_json:
            raise ValueError("both location and schema_json can't be "
                             "specified. it's ambiguous.")
        if schema_json is None:
            if location is None:
                location = "%s/vswitch.ovsschema" % ovs.dirs.PKGDATADIR
            schema_json = ovs.json.from_file(location)

        self.schema_json = schema_json
        self._tables = {}
        self._all = False
github frenetic-lang / pyretic / pyretic / vendor / ryu / ryu / contrib / ovs / jsonrpc.py View on Github external
return error, None
                    else:
                        # XXX rate-limit
                        vlog.warn("%s: receive error: %s"
                                  % (self.name, os.strerror(error)))
                        self.error(error)
                        return self.status, None
                elif not data:
                    self.error(EOF)
                    return EOF, None
                else:
                    self.input += data
                    self.received_bytes += len(data)
            else:
                if self.parser is None:
                    self.parser = ovs.json.Parser()
                self.input = self.input[self.parser.feed(self.input):]
                if self.parser.is_done():
                    msg = self.__process_msg()
                    if msg:
                        return 0, msg
                    else:
                        return self.status, None
github ovn-org / ovn / python / ovs / jsonrpc.py View on Github external
def recv(self):
        if self.status:
            return self.status, None

        decoder = codecs.getincrementaldecoder('utf-8')()
        while True:
            if not self.input:
                error, data = self.stream.recv(4096)
                # Python 3 has separate types for strings and bytes.  We
                # received bytes from a socket.  We expect it to be string
                # data, so we convert it here as soon as possible.
                if data and not error:
                    try:
                        if six.PY3 or ovs.json.PARSER == ovs.json.PARSER_PY:
                            data = decoder.decode(data)
                    except UnicodeError:
                        error = errno.EILSEQ
                if error:
                    if (sys.platform == "win32" and
                            error == errno.WSAEWOULDBLOCK):
                        # WSAEWOULDBLOCK would be the equivalent on Windows
                        # for EAGAIN on Unix.
                        error = errno.EAGAIN
                    if error == errno.EAGAIN:
                        return error, None
                    else:
                        # XXX rate-limit
                        vlog.warn("%s: receive error: %s"
                                  % (self.name, os.strerror(error)))
                        self.error(error)