mirror of https://git.48k.eu/ogclient
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"}more_events
parent
f566579f8e
commit
2fa8aa4ff7
|
@ -13,6 +13,8 @@ class HTTPParser:
|
||||||
self.operation = None
|
self.operation = None
|
||||||
self.URI = None
|
self.URI = None
|
||||||
self.cmd = None
|
self.cmd = None
|
||||||
|
self.partition = None
|
||||||
|
self.disk = None
|
||||||
|
|
||||||
def parser(self,data):
|
def parser(self,data):
|
||||||
self.requestLine, self.headersAlone = data.split('\n', 1)
|
self.requestLine, self.headersAlone = data.split('\n', 1)
|
||||||
|
@ -43,6 +45,12 @@ class HTTPParser:
|
||||||
if "run" in cmd:
|
if "run" in cmd:
|
||||||
self.cmd = jsoncmd["run"]
|
self.cmd = jsoncmd["run"]
|
||||||
|
|
||||||
|
if "disk" in cmd:
|
||||||
|
self.disk = jsoncmd["disk"]
|
||||||
|
|
||||||
|
if "partition" in cmd:
|
||||||
|
self.partition = jsoncmd["partition"]
|
||||||
|
|
||||||
def getHeaderLine(self):
|
def getHeaderLine(self):
|
||||||
return self.headersAlone
|
return self.headersAlone
|
||||||
|
|
||||||
|
@ -69,3 +77,9 @@ class HTTPParser:
|
||||||
|
|
||||||
def getCMD(self):
|
def getCMD(self):
|
||||||
return self.cmd
|
return self.cmd
|
||||||
|
|
||||||
|
def getDisk(self):
|
||||||
|
return self.disk
|
||||||
|
|
||||||
|
def getPartition(self):
|
||||||
|
return self.partition
|
||||||
|
|
|
@ -23,3 +23,7 @@ def execCMD(cmd):
|
||||||
raise ValueError('Error: Incorrect command value')
|
raise ValueError('Error: Incorrect command value')
|
||||||
|
|
||||||
return result.decode('utf-8')
|
return result.decode('utf-8')
|
||||||
|
|
||||||
|
def procsession(disk, partition):
|
||||||
|
result = subprocess.check_output([OG_PATH + 'interfaceAdm/IniciarSesion', disk, partition], shell=True)
|
||||||
|
return result.decode('utf-8')
|
||||||
|
|
|
@ -89,7 +89,7 @@ class ogClient:
|
||||||
|
|
||||||
if self.trailer and len(self.data) >= self.content_len:
|
if self.trailer and len(self.data) >= self.content_len:
|
||||||
httpparser.parser(self.data)
|
httpparser.parser(self.data)
|
||||||
self.ogrest.processOperation(httpparser.getRequestOP(), httpparser.getURI(), httpparser.getCMD(), self)
|
self.ogrest.processOperation(httpparser, self)
|
||||||
|
|
||||||
# Cleanup state information from request
|
# Cleanup state information from request
|
||||||
self.data = ""
|
self.data = ""
|
||||||
|
|
|
@ -5,6 +5,8 @@ from enum import Enum
|
||||||
import json
|
import json
|
||||||
import queue
|
import queue
|
||||||
|
|
||||||
|
from src.HTTPParser import *
|
||||||
|
|
||||||
if platform.system() == 'Linux':
|
if platform.system() == 'Linux':
|
||||||
from src.linux import ogOperations
|
from src.linux import ogOperations
|
||||||
|
|
||||||
|
@ -33,6 +35,11 @@ class ogThread():
|
||||||
def reboot():
|
def reboot():
|
||||||
ogOperations.reboot()
|
ogOperations.reboot()
|
||||||
|
|
||||||
|
# Process session
|
||||||
|
def procsession(msgqueue, disk, partition):
|
||||||
|
msgqueue.queue.clear()
|
||||||
|
msgqueue.put(ogOperations.procsession(disk, partition))
|
||||||
|
|
||||||
class ogResponses(Enum):
|
class ogResponses(Enum):
|
||||||
BAD_REQUEST=0
|
BAD_REQUEST=0
|
||||||
IN_PROGRESS=1
|
IN_PROGRESS=1
|
||||||
|
@ -61,7 +68,9 @@ class ogRest():
|
||||||
msg = msg + '\r\n\r\n'
|
msg = msg + '\r\n\r\n'
|
||||||
return msg
|
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 ("GET" in op):
|
||||||
if ("probe" in URI):
|
if ("probe" in URI):
|
||||||
self.process_probe(client)
|
self.process_probe(client)
|
||||||
|
@ -75,7 +84,9 @@ class ogRest():
|
||||||
elif ("reboot" in URI):
|
elif ("reboot" in URI):
|
||||||
self.process_reboot(client)
|
self.process_reboot(client)
|
||||||
elif ("shell/run" in URI):
|
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:
|
else:
|
||||||
client.send(self.getResponse(ogResponses.BAD_REQUEST))
|
client.send(self.getResponse(ogResponses.BAD_REQUEST))
|
||||||
else:
|
else:
|
||||||
|
@ -118,3 +129,7 @@ class ogRest():
|
||||||
else:
|
else:
|
||||||
jsonResp.addElement('out', self.msgqueue.get())
|
jsonResp.addElement('out', self.msgqueue.get())
|
||||||
client.send(self.getResponse(ogResponses.OK, jsonResp))
|
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))
|
||||||
|
|
Loading…
Reference in New Issue