Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def do_request(name, method, params_string):
params = ovs.json.from_string(params_string)
msg = ovs.jsonrpc.Message.create_request(method, params)
s = msg.is_valid()
if s:
sys.stderr.write("not a valid JSON-RPC request: %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(msg)
if error:
sys.stderr.write("could not send request: %s\n" % os.strerror(error))
sys.exit(1)
error, msg = rpc.recv_block()
if error:
sys.stderr.write("error waiting for reply: %s\n" % os.strerror(error))
sys.exit(1)
print(ovs.json.to_string(msg.to_json()))
rpc.close()
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:
sys.stderr.write("could not send notification: %s\n"
% os.strerror(error))
sys.exit(1)
rpc.close()
# that the parent process created.
error, pstream = ovs.stream.PassiveStream.open(name)
if error:
sys.stderr.write("could not listen on \"%s\": %s\n"
% (name, os.strerror(error)))
sys.exit(1)
ovs.daemon.daemonize()
rpcs = []
done = False
while True:
# Accept new connections.
error, stream = pstream.accept()
if stream:
rpcs.append(ovs.jsonrpc.Connection(stream))
elif error != errno.EAGAIN:
sys.stderr.write("PassiveStream.accept() failed\n")
sys.exit(1)
# Service existing connections.
dead_rpcs = []
for rpc in rpcs:
rpc.run()
error = 0
if not rpc.get_backlog():
error, msg = rpc.recv()
if not error:
if handle_rpc(rpc, msg):
done = True
'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:
RuntimeError('can not open socket to %s: %s' %
(self.remote, os.strerror(error)))
raise
rpc = jsonrpc.Connection(stream_)
ret = _COMMANDS[command](rpc, *args)
LOG.info('ret %s', ret)
rpc.close()
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:
def _rpc_get_schema_json(self, database):
LOG.debug('remote %s', self.remote)
error, stream_ = stream.Stream.open_block(
stream.Stream.open(self.remote))
if error:
vsctl_fatal('error %s' % os.strerror(error))
rpc = jsonrpc.Connection(stream_)
request = jsonrpc.Message.create_request('get_schema', [database])
error, reply = rpc.transact_block(request)
rpc.close()
if error:
vsctl_fatal(os.strerror(error))
elif reply.error:
vsctl_fatal('error %s' % reply.error)
return reply.result