grpc added get node terminal, updated corefx to leverage get node terminal to launch local terminals on double click

This commit is contained in:
bharnden 2019-05-31 22:20:19 -07:00
parent 43e18d820f
commit a8061b811d
5 changed files with 63 additions and 6 deletions

View file

@ -955,8 +955,15 @@ public class CoreGrpcClient implements ICoreClient {
@Override @Override
public String getTerminalCommand(CoreNode node) throws IOException { public String getTerminalCommand(CoreNode node) throws IOException {
// TODO: convert CoreProto.GetNodeTerminalRequest request = CoreProto.GetNodeTerminalRequest.newBuilder()
return null; .setSessionId(sessionId)
.setNodeId(node.getId())
.build();
try {
return blockingStub.getNodeTerminal(request).getTerminal();
} catch (StatusRuntimeException ex) {
throw new IOException(ex);
}
} }
@Override @Override

View file

@ -353,6 +353,19 @@ class CoreGrpcClient(object):
request = core_pb2.NodeCommandRequest(session_id=session_id, node_id=node_id, command=command) request = core_pb2.NodeCommandRequest(session_id=session_id, node_id=node_id, command=command)
return self.stub.NodeCommand(request) return self.stub.NodeCommand(request)
def get_node_terminal(self, session_id, node_id):
"""
Retrieve terminal command string for launching a local terminal.
:param int session_id: session id
:param int node_id: node id
:return: response with a node terminal command
:rtype: core_pb2.GetNodeTerminalResponse
:raises grpc.RpcError: when session or node doesn't exist
"""
request = core_pb2.GetNodeTerminalRequest(session_id=session_id, node_id=node_id)
return self.stub.GetNodeTerminal(request)
def get_node_links(self, session_id, node_id): def get_node_links(self, session_id, node_id):
""" """
Get current links for a node. Get current links for a node.

View file

@ -454,10 +454,13 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
interface_throughput.interface_id = interface_id interface_throughput.interface_id = interface_id
interface_throughput.throughput = throughput interface_throughput.throughput = throughput
elif key.startswith("b."): elif key.startswith("b."):
node_id = int(key.split(".")[1]) try:
bridge_throughput = throughputs_event.bridge_throughputs.add() node_id = int(key.split(".")[1])
bridge_throughput.node_id = node_id bridge_throughput = throughputs_event.bridge_throughputs.add()
bridge_throughput.throughput = throughput bridge_throughput.node_id = node_id
bridge_throughput.throughput = throughput
except ValueError:
pass
yield throughputs_event yield throughputs_event
@ -549,6 +552,13 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
_, output = node.cmd_output(request.command) _, output = node.cmd_output(request.command)
return core_pb2.NodeCommandResponse(output=output) return core_pb2.NodeCommandResponse(output=output)
def GetNodeTerminal(self, request, context):
logging.debug("getting node terminal: %s", request)
session = self.get_session(request.session_id, context)
node = self.get_node(session, request.node_id, context)
terminal = node.termcmdstring("/bin/bash")
return core_pb2.GetNodeTerminalResponse(terminal=terminal)
def GetNodeLinks(self, request, context): def GetNodeLinks(self, request, context):
logging.debug("get node links: %s", request) logging.debug("get node links: %s", request)
session = self.get_session(request.session_id, context) session = self.get_session(request.session_id, context)

View file

@ -43,6 +43,8 @@ service CoreApi {
} }
rpc NodeCommand (NodeCommandRequest) returns (NodeCommandResponse) { rpc NodeCommand (NodeCommandRequest) returns (NodeCommandResponse) {
} }
rpc GetNodeTerminal (GetNodeTerminalRequest) returns (GetNodeTerminalResponse) {
}
// link rpc // link rpc
rpc GetNodeLinks (GetNodeLinksRequest) returns (GetNodeLinksResponse) { rpc GetNodeLinks (GetNodeLinksRequest) returns (GetNodeLinksResponse) {
@ -323,6 +325,15 @@ message DeleteNodeResponse {
bool result = 1; bool result = 1;
} }
message GetNodeTerminalRequest {
int32 session_id = 1;
int32 node_id = 2;
}
message GetNodeTerminalResponse {
string terminal = 1;
}
message NodeCommandRequest { message NodeCommandRequest {
int32 session_id = 1; int32 session_id = 1;
int32 node_id = 2; int32 node_id = 2;

View file

@ -257,6 +257,22 @@ class TestGrpc:
# then # then
assert response.output == output assert response.output == output
def test_get_node_terminal(self, grpc_server):
# given
client = CoreGrpcClient()
session = grpc_server.coreemu.create_session()
session.set_state(EventTypes.CONFIGURATION_STATE)
node_options = NodeOptions(model="Host")
node = session.add_node(node_options=node_options)
session.instantiate()
# then
with client.context_connect():
response = client.get_node_terminal(session.id, node.objid)
# then
assert response.terminal is not None
def test_get_hooks(self, grpc_server): def test_get_hooks(self, grpc_server):
# given # given
client = CoreGrpcClient() client = CoreGrpcClient()