]>
Commit | Line | Data |
---|---|---|
20effc67 TL |
1 | # -*- coding: utf-8 -*- |
2 | ||
3 | from typing import Optional | |
4 | ||
5 | from ..exceptions import DashboardException | |
6 | from ..security import Scope | |
7 | from ..services.exception import handle_orchestrator_error | |
8 | from ..services.orchestrator import OrchClient, OrchFeature | |
9 | from . import APIDoc, APIRouter, RESTController | |
10 | from ._version import APIVersion | |
11 | from .orchestrator import raise_if_no_orchestrator | |
12 | ||
13 | ||
14 | @APIRouter('/daemon', Scope.HOSTS) | |
15 | @APIDoc("Perform actions on daemons", "Daemon") | |
16 | class Daemon(RESTController): | |
17 | @raise_if_no_orchestrator([OrchFeature.DAEMON_ACTION]) | |
18 | @handle_orchestrator_error('daemon') | |
19 | @RESTController.MethodMap(version=APIVersion.EXPERIMENTAL) | |
20 | def set(self, daemon_name: str, action: str = '', | |
21 | container_image: Optional[str] = None): | |
22 | ||
23 | if action not in ['start', 'stop', 'restart', 'redeploy']: | |
24 | raise DashboardException( | |
25 | code='invalid_daemon_action', | |
26 | msg=f'Daemon action "{action}" is either not valid or not supported.') | |
27 | # non 'None' container_images change need a redeploy | |
28 | if container_image == '' and action != 'redeploy': | |
29 | container_image = None | |
30 | ||
31 | orch = OrchClient.instance() | |
32 | res = orch.daemons.action(action=action, daemon_name=daemon_name, image=container_image) | |
33 | return res |