core-daemon now allows configuration for grpc address and port, defaults to localhost, also fixed grpc example due to enum and event changes
This commit is contained in:
parent
4dd6dc1837
commit
e063fcd4fe
3 changed files with 13 additions and 11 deletions
|
@ -123,7 +123,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
def _cancel_stream(self, context):
|
||||
context.abort(grpc.StatusCode.CANCELLED, "server stopping")
|
||||
|
||||
def listen(self, address="[::]:50051"):
|
||||
def listen(self, address):
|
||||
logging.info("starting grpc api: %s", address)
|
||||
self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
|
||||
core_pb2_grpc.add_CoreApiServicer_to_server(self, self.server)
|
||||
|
|
|
@ -18,19 +18,14 @@ def main():
|
|||
|
||||
# handle events session may broadcast
|
||||
session_id = response.session_id
|
||||
core.exception_events(session_id, log_event)
|
||||
core.node_events(session_id, log_event)
|
||||
core.session_events(session_id, log_event)
|
||||
core.link_events(session_id, log_event)
|
||||
core.file_events(session_id, log_event)
|
||||
core.config_events(session_id, log_event)
|
||||
core.events(session_id, log_event)
|
||||
|
||||
# change session state
|
||||
response = core.set_session_state(session_id, core_pb2.STATE_CONFIGURATION)
|
||||
response = core.set_session_state(session_id, core_pb2.SessionState.CONFIGURATION)
|
||||
logging.info("set session state: %s", response)
|
||||
|
||||
# create switch node
|
||||
switch = core_pb2.Node(type=core_pb2.NODE_SWITCH)
|
||||
switch = core_pb2.Node(type=core_pb2.NodeType.SWITCH)
|
||||
response = core.add_node(session_id, switch)
|
||||
logging.info("created switch: %s", response)
|
||||
switch_id = response.node_id
|
||||
|
@ -52,7 +47,7 @@ def main():
|
|||
logging.info("created link: %s", response)
|
||||
|
||||
# change session state
|
||||
response = core.set_session_state(session_id, core_pb2.STATE_INSTANTIATION)
|
||||
response = core.set_session_state(session_id, core_pb2.SessionState.INSTANTIATION)
|
||||
logging.info("set session state: %s", response)
|
||||
|
||||
|
||||
|
|
|
@ -57,7 +57,8 @@ def cored(cfg):
|
|||
# initialize grpc api
|
||||
if cfg["grpc"] == "True":
|
||||
grpc_server = CoreGrpcServer(server.coreemu)
|
||||
grpc_thread = threading.Thread(target=grpc_server.listen)
|
||||
grpc_address = "%s:%s" % (cfg["grpcaddress"], cfg["grpcport"])
|
||||
grpc_thread = threading.Thread(target=grpc_server.listen, args=(grpc_address,))
|
||||
grpc_thread.daemon = True
|
||||
grpc_thread.start()
|
||||
|
||||
|
@ -80,6 +81,8 @@ def get_merged_config(filename):
|
|||
"listenaddr": "localhost",
|
||||
"xmlfilever": "1.0",
|
||||
"numthreads": "1",
|
||||
"grpcport": "50051",
|
||||
"grpcaddress": "localhost"
|
||||
}
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
|
@ -92,6 +95,10 @@ def get_merged_config(filename):
|
|||
help="number of server threads; default = %s" % defaults["numthreads"])
|
||||
parser.add_argument("--ovs", action="store_true", help="enable experimental ovs mode, default is false")
|
||||
parser.add_argument("--grpc", action="store_true", help="enable grpc api, default is false")
|
||||
parser.add_argument("--grpc-port", dest="grpcport",
|
||||
help="grpc port to listen on; default %s" % defaults["grpcport"])
|
||||
parser.add_argument("--grpc-address", dest="grpcaddress",
|
||||
help="grpc address to listen on; default %s" % defaults["grpcaddress"])
|
||||
|
||||
# parse command line options
|
||||
args = parser.parse_args()
|
||||
|
|
Loading…
Reference in a new issue