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"}
more_events
Alvaro Neira Ayuso 2020-01-03 11:33:25 +01:00 committed by Alvaro Neira Ayuso
parent efbe8a7960
commit cc11d8f38f
3 changed files with 53 additions and 0 deletions

View File

@ -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

View File

@ -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')

View File

@ -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))