(Clean-Up) Rename all the functions in ogRest to new ones more clears

more_events
Alvaro Neira Ayuso 2020-01-19 19:29:13 +01:00
parent e39fe2fc52
commit 2e806531a0
2 changed files with 32 additions and 42 deletions

View File

@ -58,7 +58,7 @@ def execCMD(request, ogRest):
return output.decode('utf-8') return output.decode('utf-8')
def procsession(request, ogRest): def session(request, ogRest):
disk = request.getDisk() disk = request.getDisk()
partition = request.getPartition() partition = request.getPartition()
@ -70,7 +70,7 @@ def procsession(request, ogRest):
return output.decode('utf-8') return output.decode('utf-8')
def procsoftware(request, path, ogRest): def software(request, path, ogRest):
disk = request.getDisk() disk = request.getDisk()
partition = request.getPartition() partition = request.getPartition()
@ -82,7 +82,7 @@ def procsoftware(request, path, ogRest):
return output.decode('utf-8') return output.decode('utf-8')
def prochardware(path, ogRest): def hardware(path, ogRest):
try: try:
ogRest.proc = subprocess.Popen([OG_PATH + 'interfaceAdm/InventarioHardware', path], stdout=subprocess.PIPE, shell=True) ogRest.proc = subprocess.Popen([OG_PATH + 'interfaceAdm/InventarioHardware', path], stdout=subprocess.PIPE, shell=True)
(output, error) = ogRest.proc.communicate() (output, error) = ogRest.proc.communicate()
@ -91,7 +91,7 @@ def prochardware(path, ogRest):
return output.decode('utf-8') return output.decode('utf-8')
def procsetup(request, ogRest): def setup(request, ogRest):
disk = request.getDisk() disk = request.getDisk()
cache = request.getCache() cache = request.getCache()
cachesize = request.getCacheSize() cachesize = request.getCacheSize()
@ -112,7 +112,7 @@ def procsetup(request, ogRest):
result = subprocess.check_output([OG_PATH + 'interfaceAdm/getConfiguration'], shell=True) result = subprocess.check_output([OG_PATH + 'interfaceAdm/getConfiguration'], shell=True)
return parseGetConf(result.decode('utf-8'))[1] return parseGetConf(result.decode('utf-8'))[1]
def procirestore(request, ogRest): def image_restore(request, ogRest):
disk = request.getDisk() disk = request.getDisk()
partition = request.getPartition() partition = request.getPartition()
name = request.getName() name = request.getName()
@ -129,7 +129,7 @@ def procirestore(request, ogRest):
return output.decode('utf-8') return output.decode('utf-8')
def procicreate(path, request, ogRest): def image_create(path, request, ogRest):
disk = request.getDisk() disk = request.getDisk()
partition = request.getPartition() partition = request.getPartition()
name = request.getName() name = request.getName()
@ -152,7 +152,7 @@ def procicreate(path, request, ogRest):
return output.decode('utf-8') return output.decode('utf-8')
def procrefresh(ogRest): def refresh(ogRest):
listConfigs = [] listConfigs = []
disk = -1; disk = -1;

View File

@ -61,7 +61,6 @@ class restResponse():
return self.msg return self.msg
class ogThread(): class ogThread():
# Executing cmd thread
def execcmd(client, request, ogRest): def execcmd(client, request, ogRest):
if request.getrun() == None: if request.getrun() == None:
response = restResponse(ogResponses.BAD_REQUEST) response = restResponse(ogResponses.BAD_REQUEST)
@ -84,19 +83,16 @@ class ogThread():
response = restResponse(ogResponses.OK) response = restResponse(ogResponses.OK)
client.send(response.get()) client.send(response.get())
# Powering off thread
def poweroff(): def poweroff():
time.sleep(2) time.sleep(2)
ogOperations.poweroff() ogOperations.poweroff()
# Rebooting thread
def reboot(): def reboot():
ogOperations.reboot() ogOperations.reboot()
# Process session def session(client, request, ogRest):
def procsession(client, request, ogRest):
try: try:
ogOperations.procsession(request, ogRest) ogOperations.session(request, ogRest)
except ValueError as err: except ValueError as err:
response = restResponse(ogResponses.INTERNAL_ERR) response = restResponse(ogResponses.INTERNAL_ERR)
client.send(response.get()) client.send(response.get())
@ -105,10 +101,9 @@ class ogThread():
response = restResponse(ogResponses.OK) response = restResponse(ogResponses.OK)
client.send(response.get()) client.send(response.get())
# Process software def software(client, request, path, ogRest):
def procsoftware(client, request, path, ogRest):
try: try:
ogOperations.procsoftware(request, path, ogRest) ogOperations.software(request, path, ogRest)
except ValueError as err: except ValueError as err:
response = restResponse(ogResponses.INTERNAL_ERR) response = restResponse(ogResponses.INTERNAL_ERR)
client.send(response.get()) client.send(response.get())
@ -126,10 +121,9 @@ class ogThread():
response = restResponse(ogResponses.OK, jsonResp) response = restResponse(ogResponses.OK, jsonResp)
client.send(response.get()) client.send(response.get())
# Process hardware def hardware(client, path, ogRest):
def prochardware(client, path, ogRest):
try: try:
ogOperations.prochardware(path, ogRest) ogOperations.hardware(path, ogRest)
except ValueError as err: except ValueError as err:
response = restResponse(ogResponses.INTERNAL_ERR) response = restResponse(ogResponses.INTERNAL_ERR)
client.send(response.get()) client.send(response.get())
@ -144,12 +138,11 @@ class ogThread():
response = restResponse(ogResponses.OK, jsonResp) response = restResponse(ogResponses.OK, jsonResp)
client.send(response.get()) client.send(response.get())
# Process setup def setup(client, request, ogRest):
def procsetup(client, request, ogRest):
listconfig = [] listconfig = []
try: try:
listconfig = ogOperations.procsetup(request, ogRest) listconfig = ogOperations.setup(request, ogRest)
except ValueError as err: except ValueError as err:
response = restResponse(ogResponses.INTERNAL_ERR) response = restResponse(ogResponses.INTERNAL_ERR)
client.send(response.get()) client.send(response.get())
@ -164,10 +157,9 @@ class ogThread():
response = restResponse(ogResponses.OK, jsonResp) response = restResponse(ogResponses.OK, jsonResp)
client.send(response.get()) client.send(response.get())
# Process image restore def image_restore(client, request, ogRest):
def procirestore(client, request, ogRest):
try: try:
ogOperations.procirestore(request, ogRest) ogOperations.image_restore(request, ogRest)
except ValueError as err: except ValueError as err:
response = restResponse(ogResponses.INTERNAL_ERR) response = restResponse(ogResponses.INTERNAL_ERR)
client.send(response.get()) client.send(response.get())
@ -176,10 +168,9 @@ class ogThread():
response = restResponse(ogResponses.OK, jsonResp) response = restResponse(ogResponses.OK, jsonResp)
client.send(response.get()) client.send(response.get())
# Process image create def image_create(client, path, request, ogRest):
def procicreate(client, path, request, ogRest):
try: try:
ogOperations.procicreate(path, request, ogRest) ogOperations.image_create(path, request, ogRest)
except ValueError as err: except ValueError as err:
response = restResponse(ogResponses.INTERNAL_ERR) response = restResponse(ogResponses.INTERNAL_ERR)
client.send(response.get()) client.send(response.get())
@ -200,10 +191,9 @@ class ogThread():
response = restResponse(ogResponses.OK, jsonResp) response = restResponse(ogResponses.OK, jsonResp)
client.send(response.get()) client.send(response.get())
# Process refresh def refresh(client, ogRest):
def procrefresh(client, ogRest):
try: try:
out = ogOperations.procrefresh(ogRest) out = ogOperations.refresh(ogRest)
except ValueError as err: except ValueError as err:
response = restResponse(ogResponses.INTERNAL_ERR) response = restResponse(ogResponses.INTERNAL_ERR)
client.send(response.get()) client.send(response.get())
@ -261,11 +251,11 @@ class ogRest():
elif ("setup" in URI): elif ("setup" in URI):
self.process_setup(client, request) self.process_setup(client, request)
elif ("image/restore" in URI): elif ("image/restore" in URI):
self.process_irestore(client, request) self.process_imagerestore(client, request)
elif ("stop" in URI): elif ("stop" in URI):
self.process_stop(client) self.process_stop(client)
elif ("image/create" in URI): elif ("image/create" in URI):
self.process_icreate(client, request) self.process_imagecreate(client, request)
elif ("refresh" in URI): elif ("refresh" in URI):
self.process_refresh(client) self.process_refresh(client)
else: else:
@ -302,25 +292,25 @@ class ogRest():
threading.Thread(target=ogThread.execcmd, args=(client, request, self,)).start() threading.Thread(target=ogThread.execcmd, args=(client, request, self,)).start()
def process_session(self, client, request): def process_session(self, client, request):
threading.Thread(target=ogThread.procsession, args=(client, request, self,)).start() threading.Thread(target=ogThread.session, args=(client, request, self,)).start()
def process_software(self, client, request): def process_software(self, client, request):
path = '/tmp/CSft-' + client.ip + '-' + request.getPartition() path = '/tmp/CSft-' + client.ip + '-' + request.getPartition()
threading.Thread(target=ogThread.procsoftware, args=(client, request, path, self,)).start() threading.Thread(target=ogThread.software, args=(client, request, path, self,)).start()
def process_hardware(self, client): def process_hardware(self, client):
path = '/tmp/Chrd-' + client.ip path = '/tmp/Chrd-' + client.ip
threading.Thread(target=ogThread.prochardware, args=(client, path, self,)).start() threading.Thread(target=ogThread.hardware, args=(client, path, self,)).start()
def process_schedule(self, client): def process_schedule(self, client):
response = restResponse(ogResponses.OK) response = restResponse(ogResponses.OK)
client.send(response.get()) client.send(response.get())
def process_setup(self, client, request): def process_setup(self, client, request):
threading.Thread(target=ogThread.procsetup, args=(client, request, self,)).start() threading.Thread(target=ogThread.setup, args=(client, request, self,)).start()
def process_irestore(self, client, request): def process_imagerestore(self, client, request):
threading.Thread(target=ogThread.procirestore, args=(client, request, self,)).start() threading.Thread(target=ogThread.image_restore, args=(client, request, self,)).start()
def process_stop(self, client): def process_stop(self, client):
client.disconnect() client.disconnect()
@ -332,9 +322,9 @@ class ogRest():
self.terminated = True self.terminated = True
sys.exit(0) sys.exit(0)
def process_icreate(self, client, request): def process_imagecreate(self, client, request):
path = '/tmp/CSft-' + client.ip + '-' + request.getPartition() path = '/tmp/CSft-' + client.ip + '-' + request.getPartition()
threading.Thread(target=ogThread.procicreate, args=(client, path, request, self,)).start() threading.Thread(target=ogThread.image_create, args=(client, path, request, self,)).start()
def process_refresh(self, client): def process_refresh(self, client):
threading.Thread(target=ogThread.procrefresh, args=(client, self,)).start() threading.Thread(target=ogThread.refresh, args=(client, self,)).start()