Skip to content

Commit

Permalink
Problem: Now the operator API just allow to reboot well ephemeral VMs…
Browse files Browse the repository at this point in the history
…, not the persistent ones.

Solution: Use the VM Pool to control reboot, stop and erase operations.
  • Loading branch information
nesitor authored and MHHukiewitz committed Feb 8, 2024
1 parent 932eba6 commit 2b0bdcd
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/aleph/vm/orchestrator/views/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ async def operate_stop(request: web.Request, authenticated_sender: str) -> web.R

if execution.is_running:
logger.info(f"Stopping {execution.vm_hash}")
await execution.stop()
execution.persistent = False
await pool.stop_vm(execution.vm_hash)
return web.Response(status=200, body=f"Stopped VM with ref {vm_hash}")
else:
return web.Response(status=200, body="Already stopped, nothing to do")
Expand All @@ -170,10 +169,13 @@ async def operate_reboot(request: web.Request, authenticated_sender: str) -> web

if execution.is_running:
logger.info(f"Rebooting {execution.vm_hash}")
await pool.stop_vm(vm_hash)
await pool.forget_vm(vm_hash)
if execution.persistent:
await pool.systemd_manager.restart(execution.controller_service)
else:
await pool.stop_vm(vm_hash)
pool.forget_vm(vm_hash)

await create_vm_execution(vm_hash=vm_hash, pool=pool)
await create_vm_execution(vm_hash=vm_hash, pool=pool)
return web.Response(status=200, body=f"Rebooted VM with ref {vm_hash}")
else:
return web.Response(status=200, body="Starting VM (was not running) with ref {vm_hash}")
Expand All @@ -194,7 +196,7 @@ async def operate_erase(request: web.Request, authenticated_sender: str) -> web.
logger.info(f"Erasing {execution.vm_hash}")

# Stop the VM
await execution.stop()
await pool.stop_vm(execution.vm_hash)
await pool.forget_vm(execution.vm_hash)

# Delete all data
Expand Down

0 comments on commit 2b0bdcd

Please sign in to comment.