From cc11d8f38f6a2f9dd46904272808bb25dac042b8 Mon Sep 17 00:00:00 2001 From: Alvaro Neira Ayuso Date: Fri, 3 Jan 2020 11:33:25 +0100 Subject: Add restore/image command for restoring images on the machine ogAdmClient has a support to restore image on the machine. This new command allows the new ogClient to execute the same script to restore the images on the machine. The json format sent from the server must be: { "disk" : "1", "partition" : "1", "name" : "test",\ "repository" : "192.168.56.10", "type" : "UNICAST", "profile": "1", "id": "1"} --- src/HTTPParser.py | 35 +++++++++++++++++++++++++++++++++++ src/linux/ogOperations.py | 4 ++++ src/ogRest.py | 14 ++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/src/HTTPParser.py b/src/HTTPParser.py index 7ee8972..819cd74 100644 --- a/src/HTTPParser.py +++ b/src/HTTPParser.py @@ -18,6 +18,11 @@ class HTTPParser: self.cache = None self.cache_size = None self.partition_setup = None + self.name = None + self.repo = None + self.type = None + self.profile = None + self.id = None def parser(self,data): self.requestLine, self.headersAlone = data.split('\n', 1) @@ -64,6 +69,21 @@ class HTTPParser: if "partition_setup" in cmd: self.partition_setup = jsoncmd["partition_setup"] + if "name" in cmd: + self.name = jsoncmd["name"] + + if "repository" in cmd: + self.repo = jsoncmd["repository"] + + if "type" in cmd: + self.type = jsoncmd["type"] + + if "profile" in cmd: + self.profile = jsoncmd["profile"] + + if "id" in cmd: + self.id = jsoncmd["id"] + def getHeaderLine(self): return self.headersAlone @@ -105,3 +125,18 @@ class HTTPParser: def getPartitionSetup(self): return self.partition_setup + + def getName(self): + return self.name + + def getRepo(self): + return self.repo + + def getType(self): + return self.type + + def getProfile(self): + return self.profile + + def getId(self): + return self.id diff --git a/src/linux/ogOperations.py b/src/linux/ogOperations.py index bbc3b1a..bbdfa3d 100644 --- a/src/linux/ogOperations.py +++ b/src/linux/ogOperations.py @@ -40,3 +40,7 @@ def procsetup(disk, cache, cachesize, partlist): for part in partlist: cfg = 'dis=' + disk + '*che=' + cache + '*tch=' + cachesize + '!par=' + part["partition"] + '*cpt='+part["code"] + '*sfi=' + part['filesystem'] + '*tam=' + part['size'] + '*ope=' + part['format'] + '%' subprocess.check_output([OG_PATH + 'interfaceAdm/Configurar', disk, cfg], shell=True) + +def procirestore(disk, partition, name, repo, ctype, profile, cid): + result = subprocess.check_output([OG_PATH + 'interfaceAdm/RestaurarImagen', disk, partition, name, repo, ctype], shell=True) + return result.decode('utf-8') diff --git a/src/ogRest.py b/src/ogRest.py index 43e3920..7efd7ea 100644 --- a/src/ogRest.py +++ b/src/ogRest.py @@ -54,6 +54,11 @@ class ogThread(): def procsetup(msgqueue, disk, cache, cachesize, partlist): ogOperations.procsetup(disk, cache, cachesize, partlist) + # Process image restore + def procirestore(msgqueue, disk, partition, name, repo, ctype, profile, cid): + msgqueue.queue.clear() + msgqueue.put(ogOperations.procirestore(disk, partition, name, repo, ctype, profile, cid)) + class ogResponses(Enum): BAD_REQUEST=0 IN_PROGRESS=1 @@ -109,6 +114,11 @@ class ogRest(): self.process_software(client, httpparser.getDisk(), httpparser.getPartition()) elif ("setup" in URI): self.process_setup(client, httpparser.getDisk(), httpparser.getCache(), httpparser.getCacheSize(), httpparser.getPartitionSetup()) + elif ("image/restore" in URI): + self.process_irestore(client, httpparser.getDisk(), + httpparser.getPartition(), httpparser.getName(), + httpparser.getRepo(), httpparser.getType(), + httpparser.getProfile(), httpparser.getId()) else: client.send(self.getResponse(ogResponses.BAD_REQUEST)) else: @@ -172,3 +182,7 @@ class ogRest(): def process_setup(self, client, disk, cache, cachesize, partlist): threading.Thread(target=ogThread.procsetup, args=(self.msgqueue, disk, cache, cachesize, partlist,)).start() client.send(self.getResponse(ogResponses.OK)) + + def process_irestore(self, client, disk, partition, name, repo, ctype, profile, cid): + threading.Thread(target=ogThread.procirestore, args=(self.msgqueue, disk, partition, name, repo, ctype, profile, cid,)).start() + client.send(self.getResponse(ogResponses.OK)) -- cgit v1.2.3-18-g5258