mirror of https://git.48k.eu/ogclient
live: add checksum field to image/create response
Report image checksum to ogserver through HTTP response.master
parent
43039749c5
commit
9d8a95cc74
|
@ -157,15 +157,20 @@ class OgLiveOperations:
|
||||||
m.update(buf)
|
m.update(buf)
|
||||||
return m.hexdigest()
|
return m.hexdigest()
|
||||||
|
|
||||||
def _write_md5_file(self, path):
|
def _md5_file(self, path):
|
||||||
|
if not os.path.exists(path):
|
||||||
|
raise OgError(f'Failed to calculate checksum, image file {path} does not exist')
|
||||||
|
|
||||||
|
return self._compute_md5(path)
|
||||||
|
|
||||||
|
def _write_md5_file(self, path, checksum):
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
raise OgError(f'Failed to calculate checksum, image file {path} does not exist')
|
raise OgError(f'Failed to calculate checksum, image file {path} does not exist')
|
||||||
|
|
||||||
filename = path + ".full.sum"
|
filename = path + ".full.sum"
|
||||||
dig = self._compute_md5(path)
|
|
||||||
try:
|
try:
|
||||||
with open(filename, 'w') as f:
|
with open(filename, 'w') as f:
|
||||||
f.write(dig)
|
f.write(checksum)
|
||||||
except:
|
except:
|
||||||
logging.error(f'Cannot write checksum {filename}')
|
logging.error(f'Cannot write checksum {filename}')
|
||||||
return -1
|
return -1
|
||||||
|
@ -585,9 +590,15 @@ class OgLiveOperations:
|
||||||
logging.info(f'Writing checksum file {name}.img.full.sum...')
|
logging.info(f'Writing checksum file {name}.img.full.sum...')
|
||||||
logging.info('*DO NOT REBOOT OR POWEROFF* the client during this time')
|
logging.info('*DO NOT REBOOT OR POWEROFF* the client during this time')
|
||||||
|
|
||||||
if self._write_md5_file(f'/opt/opengnsys/images/{name}.img') == -1:
|
checksum = self._md5_file(f'/opt/opengnsys/images/{name}.img')
|
||||||
|
if checksum == -1:
|
||||||
|
raise OgError(f'Cannot access {name}.full.sum file')
|
||||||
|
|
||||||
|
if self._write_md5_file(f'/opt/opengnsys/images/{name}.img', checksum) == -1:
|
||||||
raise OgError(f'Cannot write {name}.full.sum file')
|
raise OgError(f'Cannot write {name}.full.sum file')
|
||||||
|
|
||||||
|
image_info.checksum = checksum
|
||||||
|
|
||||||
self._restartBrowser(self._url)
|
self._restartBrowser(self._url)
|
||||||
|
|
||||||
logging.info('Image creation command OK')
|
logging.info('Image creation command OK')
|
||||||
|
|
|
@ -209,6 +209,7 @@ class ogThread():
|
||||||
json_body.add_element('size', image_info.size)
|
json_body.add_element('size', image_info.size)
|
||||||
json_body.add_element('perms', image_info.perms)
|
json_body.add_element('perms', image_info.perms)
|
||||||
json_body.add_element('lastupdate', image_info.mtime)
|
json_body.add_element('lastupdate', image_info.mtime)
|
||||||
|
json_body.add_element('checksum', image_info.checksum)
|
||||||
|
|
||||||
response = restResponse(ogResponses.OK, json_body, seq=client.seq)
|
response = restResponse(ogResponses.OK, json_body, seq=client.seq)
|
||||||
client.send(response.get())
|
client.send(response.get())
|
||||||
|
|
|
@ -32,6 +32,7 @@ class ImageInfo:
|
||||||
self.perms = 0
|
self.perms = 0
|
||||||
self.clonator = 'PARTCLONE'
|
self.clonator = 'PARTCLONE'
|
||||||
self.compressor = 'LZOP'
|
self.compressor = 'LZOP'
|
||||||
|
self.checksum = 0
|
||||||
|
|
||||||
|
|
||||||
def human_to_kb(size, unit):
|
def human_to_kb(size, unit):
|
||||||
|
|
Loading…
Reference in New Issue