From 2fa8aa4ff7deaf92c5b69be0c69fee95ce18ac37 Mon Sep 17 00:00:00 2001 From: Alvaro Neira Ayuso Date: Thu, 2 Jan 2020 19:48:14 +0100 Subject: Add session command to init the opengnsys session ogAdmClient has a support for initializing the session in the machine. This new command allows the new ogClient to execute the same script to init the session. The arguments will be received from the server as a json message. Format: { "disk" : "0", "partition" : "1"} --- src/ogRest.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/ogRest.py') diff --git a/src/ogRest.py b/src/ogRest.py index 1e60495..07a5052 100644 --- a/src/ogRest.py +++ b/src/ogRest.py @@ -5,6 +5,8 @@ from enum import Enum import json import queue +from src.HTTPParser import * + if platform.system() == 'Linux': from src.linux import ogOperations @@ -33,6 +35,11 @@ class ogThread(): def reboot(): ogOperations.reboot() + # Process session + def procsession(msgqueue, disk, partition): + msgqueue.queue.clear() + msgqueue.put(ogOperations.procsession(disk, partition)) + class ogResponses(Enum): BAD_REQUEST=0 IN_PROGRESS=1 @@ -61,7 +68,9 @@ class ogRest(): msg = msg + '\r\n\r\n' return msg - def processOperation(self, op, URI, cmd, client): + def processOperation(self, httpparser, client): + op = httpparser.getRequestOP() + URI = httpparser.getURI() if ("GET" in op): if ("probe" in URI): self.process_probe(client) @@ -75,7 +84,9 @@ class ogRest(): elif ("reboot" in URI): self.process_reboot(client) elif ("shell/run" in URI): - self.process_shellrun(client, cmd) + self.process_shellrun(client, httpparser.getCMD()) + elif ("session" in URI): + self.process_session(client, httpparser.getDisk(), httpparser.getPartition()) else: client.send(self.getResponse(ogResponses.BAD_REQUEST)) else: @@ -118,3 +129,7 @@ class ogRest(): else: jsonResp.addElement('out', self.msgqueue.get()) client.send(self.getResponse(ogResponses.OK, jsonResp)) + + def process_session(self, client, disk, partition): + threading.Thread(target=ogThread.procsession, args=(self.msgqueue, disk, partition,)).start() + client.send(self.getResponse(ogResponses.OK)) -- cgit v1.2.3-18-g5258