diff options
author | Alvaro Neira Ayuso <aneira@soleta.eu> | 2020-01-18 14:10:31 +0100 |
---|---|---|
committer | Alvaro Neira Ayuso <alvaroneay@gmail.com> | 2020-01-19 19:50:44 +0100 |
commit | 8fc251eff34d28ccc500362f0051eee72f700510 (patch) | |
tree | f846da513eb5009b7ce10fbaaa07993853692496 | |
parent | 44a4662fef5bac67503820b850614ac203c19664 (diff) |
(Clean-Up) Rename HTTPParser to restRequest
-rw-r--r-- | src/HTTPParser.py | 2 | ||||
-rw-r--r-- | src/linux/ogOperations.py | 52 | ||||
-rw-r--r-- | src/ogClient.py | 8 | ||||
-rw-r--r-- | src/ogRest.py | 96 |
4 files changed, 79 insertions, 79 deletions
diff --git a/src/HTTPParser.py b/src/HTTPParser.py index 2095e95..c9d4881 100644 --- a/src/HTTPParser.py +++ b/src/HTTPParser.py @@ -10,7 +10,7 @@ import email from io import StringIO import json -class HTTPParser: +class restRequest: def __init__(self): self.requestLine = None self.headersAlone = None diff --git a/src/linux/ogOperations.py b/src/linux/ogOperations.py index df78927..074320c 100644 --- a/src/linux/ogOperations.py +++ b/src/linux/ogOperations.py @@ -47,8 +47,8 @@ def reboot(): else: subprocess.call(['/sbin/reboot']) -def execCMD(httpparser, ogRest): - cmd = httpparser.getrun() +def execCMD(request, ogRest): + cmd = request.getrun() cmds = cmd.split(" ") try: ogRest.proc = subprocess.Popen(cmds, stdout=subprocess.PIPE, shell=True) @@ -58,9 +58,9 @@ def execCMD(httpparser, ogRest): return output.decode('utf-8') -def procsession(httpparser, ogRest): - disk = httpparser.getDisk() - partition = httpparser.getPartition() +def procsession(request, ogRest): + disk = request.getDisk() + partition = request.getPartition() try: ogRest.proc = subprocess.Popen([OG_PATH + 'interfaceAdm/IniciarSesion', disk, partition], stdout=subprocess.PIPE, shell=True) @@ -70,9 +70,9 @@ def procsession(httpparser, ogRest): return output.decode('utf-8') -def procsoftware(httpparser, path, ogRest): - disk = httpparser.getDisk() - partition = httpparser.getPartition() +def procsoftware(request, path, ogRest): + disk = request.getDisk() + partition = request.getPartition() try: ogRest.proc = subprocess.Popen([OG_PATH + 'interfaceAdm/InventarioSoftware', disk, partition, path], stdout=subprocess.PIPE, shell=True) @@ -91,11 +91,11 @@ def prochardware(path, ogRest): return output.decode('utf-8') -def procsetup(httpparser, ogRest): - disk = httpparser.getDisk() - cache = httpparser.getCache() - cachesize = httpparser.getCacheSize() - partlist = httpparser.getPartitionSetup() +def procsetup(request, ogRest): + disk = request.getDisk() + cache = request.getCache() + cachesize = request.getCacheSize() + partlist = request.getPartitionSetup() listConfigs = [] for part in partlist: @@ -112,14 +112,14 @@ def procsetup(httpparser, ogRest): result = subprocess.check_output([OG_PATH + 'interfaceAdm/getConfiguration'], shell=True) return parseGetConf(result.decode('utf-8'))[1] -def procirestore(httpparser, ogRest): - disk = httpparser.getDisk() - partition = httpparser.getPartition() - name = httpparser.getName() - repo = httpparser.getRepo() - ctype = httpparser.getType() - profile = httpparser.getProfile() - cid = httpparser.getId() +def procirestore(request, ogRest): + disk = request.getDisk() + partition = request.getPartition() + name = request.getName() + repo = request.getRepo() + ctype = request.getType() + profile = request.getProfile() + cid = request.getId() try: ogRest.proc = subprocess.Popen([OG_PATH + 'interfaceAdm/RestaurarImagen', disk, partition, name, repo, ctype], stdout=subprocess.PIPE, shell=True) @@ -129,11 +129,11 @@ def procirestore(httpparser, ogRest): return output.decode('utf-8') -def procicreate(path, httpparser, ogRest): - disk = httpparser.getDisk() - partition = httpparser.getPartition() - name = httpparser.getName() - repo = httpparser.getRepo() +def procicreate(path, request, ogRest): + disk = request.getDisk() + partition = request.getPartition() + name = request.getName() + repo = request.getRepo() try: ogRest.proc = subprocess.Popen([OG_PATH + 'interfaceAdm/InventarioSoftware', disk, partition, path], stdout=subprocess.PIPE, shell=True) diff --git a/src/ogClient.py b/src/ogClient.py index 8f1d954..9ad38ff 100644 --- a/src/ogClient.py +++ b/src/ogClient.py @@ -13,7 +13,7 @@ import time import email from io import StringIO -from src.HTTPParser import * +from src.restRequest import * from src.ogRest import * from enum import Enum @@ -83,7 +83,7 @@ class ogClient: self.connect() self.data = self.data + data - httpparser = HTTPParser() + request = restRequest() if not self.trailer: if self.data.find("\r\n") > 0: @@ -97,8 +97,8 @@ class ogClient: self.trailer = True if self.trailer and len(self.data) >= self.content_len: - httpparser.parser(self.data) - self.ogrest.processOperation(httpparser, self) + request.parser(self.data) + self.ogrest.processOperation(request, self) # Cleanup state information from request self.data = "" diff --git a/src/ogRest.py b/src/ogRest.py index a4a7d6f..88cb708 100644 --- a/src/ogRest.py +++ b/src/ogRest.py @@ -60,18 +60,18 @@ class restResponse(): class ogThread(): # Executing cmd thread - def execcmd(client, httpparser, ogRest): - if httpparser.getrun() == None: + def execcmd(client, request, ogRest): + if request.getrun() == None: client.send(restResponse.getResponse(ogResponses.BAD_REQUEST)) return try: - shellout = ogOperations.execCMD(httpparser, ogRest) + shellout = ogOperations.execCMD(request, ogRest) except ValueError as err: client.send(restResponse.getResponse(ogResponses.BAD_REQUEST)) return - if httpparser.getEcho(): + if request.getEcho(): jsonResp = jsonResponse() jsonResp.addElement('out', shellout) client.send(restResponse.getResponse(ogResponses.OK, jsonResp)) @@ -88,9 +88,9 @@ class ogThread(): ogOperations.reboot() # Process session - def procsession(client, httpparser, ogRest): + def procsession(client, request, ogRest): try: - ogOperations.procsession(httpparser, ogRest) + ogOperations.procsession(request, ogRest) except ValueError as err: client.send(restResponse.getResponse(ogResponses.INTERNAL_ERR)) return @@ -98,16 +98,16 @@ class ogThread(): client.send(restResponse.getResponse(ogResponses.OK)) # Process software - def procsoftware(client, httpparser, path, ogRest): + def procsoftware(client, request, path, ogRest): try: - ogOperations.procsoftware(httpparser, path, ogRest) + ogOperations.procsoftware(request, path, ogRest) except ValueError as err: client.send(restResponse.getResponse(ogResponses.INTERNAL_ERR)) return jsonResp = jsonResponse() - jsonResp.addElement('disk', httpparser.getDisk()) - jsonResp.addElement('partition', httpparser.getPartition()) + jsonResp.addElement('disk', request.getDisk()) + jsonResp.addElement('partition', request.getPartition()) f = open(path, "r") lines = f.readlines() @@ -132,19 +132,19 @@ class ogThread(): client.send(restResponse.getResponse(ogResponses.OK, jsonResp)) # Process setup - def procsetup(client, httpparser, ogRest): + def procsetup(client, request, ogRest): jsonResp = jsonResponse() - jsonResp.addElement('disk', httpparser.getDisk()) - jsonResp.addElement('cache', httpparser.getCache()) - jsonResp.addElement('cache_size', httpparser.getCacheSize()) - listconfig = ogOperations.procsetup(httpparser, ogRest) + jsonResp.addElement('disk', request.getDisk()) + jsonResp.addElement('cache', request.getCache()) + jsonResp.addElement('cache_size', request.getCacheSize()) + listconfig = ogOperations.procsetup(request, ogRest) jsonResp.addElement('partition_setup', listconfig) client.send(restResponse.getResponse(ogResponses.OK, jsonResp)) # Process image restore - def procirestore(client, httpparser, ogRest): + def procirestore(client, request, ogRest): try: - ogOperations.procirestore(httpparser, ogRest) + ogOperations.procirestore(request, ogRest) except ValueError as err: client.send(restResponse.getResponse(ogResponses.INTERNAL_ERR)) return @@ -152,20 +152,20 @@ class ogThread(): client.send(restResponse.getResponse(ogResponses.OK)) # Process image create - def procicreate(client, path, httpparser, ogRest): + def procicreate(client, path, request, ogRest): try: - ogOperations.procicreate(path, httpparser, ogRest) + ogOperations.procicreate(path, request, ogRest) except ValueError as err: client.send(restResponse.getResponse(ogResponses.INTERNAL_ERR)) return jsonResp = jsonResponse() - jsonResp.addElement('disk', httpparser.getDisk()) - jsonResp.addElement('partition', httpparser.getPartition()) - jsonResp.addElement('code', httpparser.getCode()) - jsonResp.addElement('id', httpparser.getId()) - jsonResp.addElement('name', httpparser.getName()) - jsonResp.addElement('repository', httpparser.getRepo()) + jsonResp.addElement('disk', request.getDisk()) + jsonResp.addElement('partition', request.getPartition()) + jsonResp.addElement('code', request.getCode()) + jsonResp.addElement('id', request.getId()) + jsonResp.addElement('name', request.getName()) + jsonResp.addElement('repository', request.getRepo()) f = open(path, "r") lines = f.readlines() f.close() @@ -198,9 +198,9 @@ class ogRest(): self.proc = None self.terminated = False - def processOperation(self, httpparser, client): - op = httpparser.getRequestOP() - URI = httpparser.getURI() + def processOperation(self, request, client): + op = request.getRequestOP() + URI = request.getURI() if (not "stop" in URI and not self.proc == None and self.proc.poll() == None): client.send(restResponse.getResponse(ogResponses.UNAUTHORIZED)) @@ -221,19 +221,19 @@ class ogRest(): elif ("reboot" in URI): self.process_reboot(client) elif ("shell/run" in URI): - self.process_shellrun(client, httpparser) + self.process_shellrun(client, request) elif ("session" in URI): - self.process_session(client, httpparser) + self.process_session(client, request) elif ("software" in URI): - self.process_software(client, httpparser) + self.process_software(client, request) elif ("setup" in URI): - self.process_setup(client, httpparser) + self.process_setup(client, request) elif ("image/restore" in URI): - self.process_irestore(client, httpparser) + self.process_irestore(client, request) elif ("stop" in URI): self.process_stop(client) elif ("image/create" in URI): - self.process_icreate(client, httpparser) + self.process_icreate(client, request) elif ("refresh" in URI): self.process_refresh(client) else: @@ -258,15 +258,15 @@ class ogRest(): jsonResp.addElement('status', 'OPG') client.send(restResponse.getResponse(ogResponses.OK, jsonResp)) - def process_shellrun(self, client, httpparser): - threading.Thread(target=ogThread.execcmd, args=(client, httpparser, self,)).start() + def process_shellrun(self, client, request): + threading.Thread(target=ogThread.execcmd, args=(client, request, self,)).start() - def process_session(self, client, httpparser): - threading.Thread(target=ogThread.procsession, args=(client, httpparser, self,)).start() + def process_session(self, client, request): + threading.Thread(target=ogThread.procsession, args=(client, request, self,)).start() - def process_software(self, client, httpparser): - path = '/tmp/CSft-' + client.ip + '-' + httpparser.getPartition() - threading.Thread(target=ogThread.procsoftware, args=(client, httpparser, path, self,)).start() + def process_software(self, client, request): + path = '/tmp/CSft-' + client.ip + '-' + request.getPartition() + threading.Thread(target=ogThread.procsoftware, args=(client, request, path, self,)).start() def process_hardware(self, client): path = '/tmp/Chrd-' + client.ip @@ -275,11 +275,11 @@ class ogRest(): def process_schedule(self, client): client.send(restResponse.getResponse(ogResponses.OK)) - def process_setup(self, client, httpparser): - threading.Thread(target=ogThread.procsetup, args=(client, httpparser, self,)).start() + def process_setup(self, client, request): + threading.Thread(target=ogThread.procsetup, args=(client, request, self,)).start() - def process_irestore(self, client, httpparser): - threading.Thread(target=ogThread.procirestore, args=(client, httpparser, self,)).start() + def process_irestore(self, client, request): + threading.Thread(target=ogThread.procirestore, args=(client, request, self,)).start() def process_stop(self, client): client.disconnect() @@ -291,9 +291,9 @@ class ogRest(): self.terminated = True sys.exit(0) - def process_icreate(self, client, httpparser): - path = '/tmp/CSft-' + client.ip + '-' + httpparser.getPartition() - threading.Thread(target=ogThread.procicreate, args=(client, path, httpparser, self,)).start() + def process_icreate(self, client, request): + path = '/tmp/CSft-' + client.ip + '-' + request.getPartition() + threading.Thread(target=ogThread.procicreate, args=(client, path, request, self,)).start() def process_refresh(self, client): threading.Thread(target=ogThread.procrefresh, args=(client, self,)).start() |