Skip to content

Commit

Permalink
feat: restart button
Browse files Browse the repository at this point in the history
  • Loading branch information
MSchmoecker committed Aug 16, 2024
1 parent d4aa203 commit 1fc0274
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 1 deletion.
3 changes: 3 additions & 0 deletions controller/thymis_controller/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,6 @@ def create_build_device_image_task(self, device_identifier: str):
return task.global_task_controller.add_task(
task.BuildDeviceImageTask(self.path, device_identifier)
)

def create_restart_device_task(self, device_identifier: str):
return task.global_task_controller.add_task(task.RestartDeviceTask(device_identifier))
9 changes: 9 additions & 0 deletions controller/thymis_controller/routers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ async def build_download_image(
await project.create_build_device_image_task(identifier)


@router.post("/action/restart-device")
def deploy(
identifier: str,
background_tasks: BackgroundTasks,
project: project.Project = Depends(get_project),
):
background_tasks.add_task(project.create_restart_device_task(identifier))


@router.get("/download-image")
def download_image(
identifier: str,
Expand Down
10 changes: 10 additions & 0 deletions controller/thymis_controller/task/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,3 +533,13 @@ def get_model(self) -> models.CommandTask:
"args": self.args,
},
)

class RestartDeviceTask(CommandTask):
def __init__(self, identifier):
super().__init__(
"ssh",
["-o StrictHostKeyChecking=accept-new", f"root@{identifier}", "reboot"],
)

self.display_name = f"Restarting {identifier}"
self.identifier = identifier
1 change: 1 addition & 0 deletions frontend/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"actions": {
"edit": "Bearbeiten",
"download": "Image Herunterladen",
"restart": "Neustarten",
"delete": "Löschen"
},
"status": {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"actions": {
"edit": "Edit",
"download": "Download Image",
"restart": "Restart",
"delete": "Delete"
},
"status": {
Expand Down
14 changes: 13 additions & 1 deletion frontend/src/routes/devices/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
saveState();
}
function restartDevice(device: Device) {
fetch(
`${controllerProtocol}://${controllerHost}/action/restart-device?identifier=${device.identifier}`,
{
method: 'POST'
}
);
}
const downloadUri = (uri: string) => {
const link = document.createElement('a');
link.href = uri;
Expand Down Expand Up @@ -225,7 +234,10 @@
<Button color="alternative" on:click={() => buildAndDownloadImage(device.data)}>
{$t('devices.actions.download')}
</Button>
<Button color="alternative" on:click={() => deleteDevice(device.data)}>
<Button color="alternative" on:click={() => restartDevice(device.data)}>
{$t('devices.actions.restart')}
</Button>
<Button class="ml-8" color="alternative" on:click={() => deleteDevice(device.data)}>
{$t('devices.actions.delete')}
</Button>
</div>
Expand Down

0 comments on commit 1fc0274

Please sign in to comment.