grpc: node_command improvements to include return code and options for wait and shell when running commands
This commit is contained in:
parent
29d09c8397
commit
7b2dd59c81
3 changed files with 20 additions and 4 deletions
|
@ -597,7 +597,12 @@ class CoreGrpcClient:
|
||||||
return self.stub.DeleteNode(request)
|
return self.stub.DeleteNode(request)
|
||||||
|
|
||||||
def node_command(
|
def node_command(
|
||||||
self, session_id: int, node_id: int, command: str
|
self,
|
||||||
|
session_id: int,
|
||||||
|
node_id: int,
|
||||||
|
command: str,
|
||||||
|
wait: bool = True,
|
||||||
|
shell: bool = False,
|
||||||
) -> core_pb2.NodeCommandResponse:
|
) -> core_pb2.NodeCommandResponse:
|
||||||
"""
|
"""
|
||||||
Send command to a node and get the output.
|
Send command to a node and get the output.
|
||||||
|
@ -605,11 +610,17 @@ class CoreGrpcClient:
|
||||||
:param session_id: session id
|
:param session_id: session id
|
||||||
:param node_id: node id
|
:param node_id: node id
|
||||||
:param command: command to run on node
|
:param command: command to run on node
|
||||||
|
:param wait: wait for command to complete
|
||||||
|
:param shell: send shell command
|
||||||
:return: response with command combined stdout/stderr
|
:return: response with command combined stdout/stderr
|
||||||
:raises grpc.RpcError: when session or node doesn't exist
|
:raises grpc.RpcError: when session or node doesn't exist
|
||||||
"""
|
"""
|
||||||
request = core_pb2.NodeCommandRequest(
|
request = core_pb2.NodeCommandRequest(
|
||||||
session_id=session_id, node_id=node_id, command=command
|
session_id=session_id,
|
||||||
|
node_id=node_id,
|
||||||
|
command=command,
|
||||||
|
wait=wait,
|
||||||
|
shell=shell,
|
||||||
)
|
)
|
||||||
return self.stub.NodeCommand(request)
|
return self.stub.NodeCommand(request)
|
||||||
|
|
||||||
|
|
|
@ -796,10 +796,12 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
session = self.get_session(request.session_id, context)
|
session = self.get_session(request.session_id, context)
|
||||||
node = self.get_node(session, request.node_id, context, CoreNode)
|
node = self.get_node(session, request.node_id, context, CoreNode)
|
||||||
try:
|
try:
|
||||||
output = node.cmd(request.command)
|
output = node.cmd(request.command, request.wait, request.shell)
|
||||||
|
return_code = 0
|
||||||
except CoreCommandError as e:
|
except CoreCommandError as e:
|
||||||
output = e.stderr
|
output = e.stderr
|
||||||
return core_pb2.NodeCommandResponse(output=output)
|
return_code = e.returncode
|
||||||
|
return core_pb2.NodeCommandResponse(output=output, return_code=return_code)
|
||||||
|
|
||||||
def GetNodeTerminal(
|
def GetNodeTerminal(
|
||||||
self, request: core_pb2.GetNodeTerminalRequest, context: ServicerContext
|
self, request: core_pb2.GetNodeTerminalRequest, context: ServicerContext
|
||||||
|
|
|
@ -467,10 +467,13 @@ message NodeCommandRequest {
|
||||||
int32 session_id = 1;
|
int32 session_id = 1;
|
||||||
int32 node_id = 2;
|
int32 node_id = 2;
|
||||||
string command = 3;
|
string command = 3;
|
||||||
|
bool wait = 4;
|
||||||
|
bool shell = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message NodeCommandResponse {
|
message NodeCommandResponse {
|
||||||
string output = 1;
|
string output = 1;
|
||||||
|
int32 return_code = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetNodeLinksRequest {
|
message GetNodeLinksRequest {
|
||||||
|
|
Loading…
Reference in a new issue