mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-04-19 10:47:15 +00:00
Add current_start_only param
This commit is contained in:
parent
606db3585c
commit
9471de0388
@ -16,7 +16,7 @@ from .audio import APIAudio
|
||||
from .auth import APIAuth
|
||||
from .backups import APIBackups
|
||||
from .cli import APICli
|
||||
from .const import CONTENT_TYPE_TEXT
|
||||
from .const import CONTENT_TYPE_TEXT, QUERY_CURRENT_START_ONLY
|
||||
from .discovery import APIDiscovery
|
||||
from .dns import APICoreDNS
|
||||
from .docker import APIDocker
|
||||
@ -525,7 +525,13 @@ class RestAPI(CoreSysAttributes):
|
||||
@api_process_raw(CONTENT_TYPE_TEXT, error_type=CONTENT_TYPE_TEXT)
|
||||
async def get_addon_logs(request, *args, **kwargs):
|
||||
addon = api_addons.get_addon_for_request(request)
|
||||
kwargs["identifier"] = f"addon_{addon.slug}"
|
||||
if (
|
||||
QUERY_CURRENT_START_ONLY in request.query
|
||||
and await addon.instance.is_running()
|
||||
):
|
||||
kwargs["container_id_full"] = addon.instance.id
|
||||
else:
|
||||
kwargs["identifier"] = f"addon_{addon.slug}"
|
||||
return await self._api_host.advanced_logs(request, *args, **kwargs)
|
||||
|
||||
self.webapp.add_routes(
|
||||
|
@ -75,6 +75,8 @@ ATTR_USER_PATH = "user_path"
|
||||
ATTR_VENDOR = "vendor"
|
||||
ATTR_VIRTUALIZATION = "virtualization"
|
||||
|
||||
QUERY_CURRENT_START_ONLY = "current_start_only"
|
||||
|
||||
|
||||
class BootSlot(StrEnum):
|
||||
"""Boot slots used by HAOS."""
|
||||
|
@ -31,6 +31,7 @@ from ..coresys import CoreSysAttributes
|
||||
from ..exceptions import APIDBMigrationInProgress, APIError, HostLogError
|
||||
from ..host.const import (
|
||||
PARAM_BOOT_ID,
|
||||
PARAM_CONTAINER_ID_FULL,
|
||||
PARAM_FOLLOW,
|
||||
PARAM_SYSLOG_IDENTIFIER,
|
||||
LogFormat,
|
||||
@ -191,7 +192,11 @@ class APIHost(CoreSysAttributes):
|
||||
return possible_offset
|
||||
|
||||
async def advanced_logs_handler(
|
||||
self, request: web.Request, identifier: str | None = None, follow: bool = False
|
||||
self,
|
||||
request: web.Request,
|
||||
identifier: str | None = None,
|
||||
follow: bool = False,
|
||||
container_id_full: str | None = None,
|
||||
) -> web.StreamResponse:
|
||||
"""Return systemd-journald logs."""
|
||||
log_formatter = LogFormatter.PLAIN
|
||||
@ -211,6 +216,8 @@ class APIHost(CoreSysAttributes):
|
||||
)
|
||||
if follow:
|
||||
params[PARAM_FOLLOW] = ""
|
||||
if container_id_full:
|
||||
params[PARAM_CONTAINER_ID_FULL] = container_id_full
|
||||
|
||||
if ACCEPT in request.headers and request.headers[ACCEPT] not in [
|
||||
CONTENT_TYPE_TEXT,
|
||||
@ -273,7 +280,13 @@ class APIHost(CoreSysAttributes):
|
||||
|
||||
@api_process_raw(CONTENT_TYPE_TEXT, error_type=CONTENT_TYPE_TEXT)
|
||||
async def advanced_logs(
|
||||
self, request: web.Request, identifier: str | None = None, follow: bool = False
|
||||
self,
|
||||
request: web.Request,
|
||||
identifier: str | None = None,
|
||||
follow: bool = False,
|
||||
container_id_full: str | None = None,
|
||||
) -> web.StreamResponse:
|
||||
"""Return systemd-journald logs. Wrapped as standard API handler."""
|
||||
return await self.advanced_logs_handler(request, identifier, follow)
|
||||
return await self.advanced_logs_handler(
|
||||
request, identifier, follow, container_id_full
|
||||
)
|
||||
|
@ -176,6 +176,11 @@ class DockerInterface(JobGroup):
|
||||
"""Healthcheck of instance if it has one."""
|
||||
return self.meta_config.get("Healthcheck")
|
||||
|
||||
@property
|
||||
def id(self) -> str:
|
||||
"""Return id of container (if running) or image (if not)."""
|
||||
return self._meta["Id"]
|
||||
|
||||
def _get_credentials(self, image: str) -> dict:
|
||||
"""Return a dictionay with credentials for docker login."""
|
||||
registry = None
|
||||
|
@ -5,6 +5,7 @@ from enum import StrEnum
|
||||
PARAM_BOOT_ID = "_BOOT_ID"
|
||||
PARAM_FOLLOW = "follow"
|
||||
PARAM_SYSLOG_IDENTIFIER = "SYSLOG_IDENTIFIER"
|
||||
PARAM_CONTAINER_ID_FULL = "CONTAINER_ID_FULL"
|
||||
|
||||
|
||||
class InterfaceMethod(StrEnum):
|
||||
|
Loading…
x
Reference in New Issue
Block a user