summaryrefslogtreecommitdiffstats
path: root/src/ogRest.py
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-08-08 10:26:06 +0200
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-08-09 11:04:56 +0200
commitfe40f9c5d66916cad4cee8d5b2d9e172fc1c0477 (patch)
tree624d4660cef9c2e8efea72d6e0e463d1bd887fb1 /src/ogRest.py
parent89d711be2a59aba8ba2e6fd1c07bc1ee0d20fe55 (diff)
src: add POST cache/fetch method
Add API REST method to fetch an image. Consolidate image fetch loging for cache/fetch and image/restore. Resquest payload structure: { 'image': 'linux.img' 'type': 'TIPTORRENT' 'repository': '12.141.10.2' } The client will try to fetch'image' from 'repository' into cache. Resquest response structure: { 'cache': [ {'name': 'windows.img', 'size': 2432370213, checksum: '5d4dcc677bc19f40a647d0002f4ade90'}, {'name': 'linux.img', 'size': 243234534213, checksum: '3eb22f888f88a55ad954f55644e1192e'} ] }
Diffstat (limited to 'src/ogRest.py')
-rw-r--r--src/ogRest.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/ogRest.py b/src/ogRest.py
index 4a734f7..fc46e8d 100644
--- a/src/ogRest.py
+++ b/src/ogRest.py
@@ -228,6 +228,19 @@ class ogThread():
client.send(response.get())
ogRest.state = ThreadState.IDLE
+ def cache_fetch(client, request, ogRest):
+ try:
+ out = ogRest.operations.cache_fetch(request, ogRest)
+ except Exception as e:
+ ogRest.send_internal_server_error(client, exc=e)
+ return
+
+ json_body = jsonBody(out)
+
+ response = restResponse(ogResponses.OK, json_body, seq=client.seq)
+ client.send(response.get())
+ ogRest.state = ThreadState.IDLE
+
def refresh(client, ogRest):
try:
out = ogRest.operations.refresh(ogRest)
@@ -343,6 +356,8 @@ class ogRest():
self.process_imagecreate(client, request)
elif ("cache/delete" in URI):
self.process_cache_delete(client, request)
+ elif ("cache/fetch" in URI):
+ self.process_cache_fetch(client, request)
else:
logging.warn('Unsupported request: %s',
URI[:ogRest.LOG_LENGTH])
@@ -448,5 +463,8 @@ class ogRest():
def process_cache_delete(self, client, request):
threading.Thread(target=ogThread.cache_delete, args=(client, request, self,)).start()
+ def process_cache_fetch(self, client, request):
+ threading.Thread(target=ogThread.cache_fetch, args=(client, request, self,)).start()
+
def process_refresh(self, client):
threading.Thread(target=ogThread.refresh, args=(client, self,)).start()