#1004 Add new fields to /image/create response

Extend ogClient to include more information about the image that has been
created. This patch modifies ogClient to read an info file created by image
creation script, add this info to the JSON response and then remove the file.

Example of new /image/create response:

{
  "disk": "1",
  "partition": "1",
  "code": "131",
  "id": "1",
  "name": "ubuntu",
  "repository": "192.168.56.10",
  "software": "Ubuntu 18.04.5 LTS \naccountsservice 0.6.45\n...",
  "clonator": "PARTCLONE",
  "compressor": "LZOP",
  "filesystem": "EXTFS",
  "datasize": 2100000
}

New fields are "clonator", "compressor", "filesystem" and "datasize".
more_events
Javier Sánchez Parra 2020-09-10 14:03:57 +02:00 committed by OpenGnSys Support Team
parent 36b5064970
commit c86eae48fe
2 changed files with 21 additions and 2 deletions

View File

@ -239,9 +239,22 @@ class OgLinuxOperations:
except:
raise ValueError('Error: Incorrect command value')
with open('/tmp/image.info') as file_info:
line = file_info.readline().rstrip()
image_info = {}
(image_info['clonator'],
image_info['compressor'],
image_info['filesystem'],
image_info['datasize'],
image_info['clientname']) = line.split(':', 5)
os.remove('/tmp/image.info')
self._restartBrowser(self._url)
return output.decode('utf-8')
return image_info
def refresh(self, ogRest):
self._restartBrowser(self._url_log)

View File

@ -191,7 +191,9 @@ class ogThread():
def image_create(client, path, request, ogRest):
try:
ogRest.operations.image_create(path, request, ogRest)
image_info = ogRest.operations.image_create(path,
request,
ogRest)
software = ogRest.operations.software(request, path, ogRest)
except ValueError as err:
response = restResponse(ogResponses.INTERNAL_ERR)
@ -207,6 +209,10 @@ class ogThread():
json_body.add_element('name', request.getName())
json_body.add_element('repository', request.getRepo())
json_body.add_element('software', software)
json_body.add_element('clonator', image_info['clonator'])
json_body.add_element('compressor', image_info['compressor'])
json_body.add_element('filesystem', image_info['filesystem'])
json_body.add_element('datasize', int(image_info['datasize']))
response = restResponse(ogResponses.OK, json_body)
client.send(response.get())