Add current_start_only param

This commit is contained in:
Mike Degatano 2025-02-18 21:43:51 +00:00
parent 606db3585c
commit 9471de0388
5 changed files with 32 additions and 5 deletions

View File

@ -16,7 +16,7 @@ from .audio import APIAudio
from .auth import APIAuth from .auth import APIAuth
from .backups import APIBackups from .backups import APIBackups
from .cli import APICli 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 .discovery import APIDiscovery
from .dns import APICoreDNS from .dns import APICoreDNS
from .docker import APIDocker from .docker import APIDocker
@ -525,7 +525,13 @@ class RestAPI(CoreSysAttributes):
@api_process_raw(CONTENT_TYPE_TEXT, error_type=CONTENT_TYPE_TEXT) @api_process_raw(CONTENT_TYPE_TEXT, error_type=CONTENT_TYPE_TEXT)
async def get_addon_logs(request, *args, **kwargs): async def get_addon_logs(request, *args, **kwargs):
addon = api_addons.get_addon_for_request(request) 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) return await self._api_host.advanced_logs(request, *args, **kwargs)
self.webapp.add_routes( self.webapp.add_routes(

View File

@ -75,6 +75,8 @@ ATTR_USER_PATH = "user_path"
ATTR_VENDOR = "vendor" ATTR_VENDOR = "vendor"
ATTR_VIRTUALIZATION = "virtualization" ATTR_VIRTUALIZATION = "virtualization"
QUERY_CURRENT_START_ONLY = "current_start_only"
class BootSlot(StrEnum): class BootSlot(StrEnum):
"""Boot slots used by HAOS.""" """Boot slots used by HAOS."""

View File

@ -31,6 +31,7 @@ from ..coresys import CoreSysAttributes
from ..exceptions import APIDBMigrationInProgress, APIError, HostLogError from ..exceptions import APIDBMigrationInProgress, APIError, HostLogError
from ..host.const import ( from ..host.const import (
PARAM_BOOT_ID, PARAM_BOOT_ID,
PARAM_CONTAINER_ID_FULL,
PARAM_FOLLOW, PARAM_FOLLOW,
PARAM_SYSLOG_IDENTIFIER, PARAM_SYSLOG_IDENTIFIER,
LogFormat, LogFormat,
@ -191,7 +192,11 @@ class APIHost(CoreSysAttributes):
return possible_offset return possible_offset
async def advanced_logs_handler( 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: ) -> web.StreamResponse:
"""Return systemd-journald logs.""" """Return systemd-journald logs."""
log_formatter = LogFormatter.PLAIN log_formatter = LogFormatter.PLAIN
@ -211,6 +216,8 @@ class APIHost(CoreSysAttributes):
) )
if follow: if follow:
params[PARAM_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 [ if ACCEPT in request.headers and request.headers[ACCEPT] not in [
CONTENT_TYPE_TEXT, CONTENT_TYPE_TEXT,
@ -273,7 +280,13 @@ class APIHost(CoreSysAttributes):
@api_process_raw(CONTENT_TYPE_TEXT, error_type=CONTENT_TYPE_TEXT) @api_process_raw(CONTENT_TYPE_TEXT, error_type=CONTENT_TYPE_TEXT)
async def advanced_logs( 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: ) -> web.StreamResponse:
"""Return systemd-journald logs. Wrapped as standard API handler.""" """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
)

View File

@ -176,6 +176,11 @@ class DockerInterface(JobGroup):
"""Healthcheck of instance if it has one.""" """Healthcheck of instance if it has one."""
return self.meta_config.get("Healthcheck") 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: def _get_credentials(self, image: str) -> dict:
"""Return a dictionay with credentials for docker login.""" """Return a dictionay with credentials for docker login."""
registry = None registry = None

View File

@ -5,6 +5,7 @@ from enum import StrEnum
PARAM_BOOT_ID = "_BOOT_ID" PARAM_BOOT_ID = "_BOOT_ID"
PARAM_FOLLOW = "follow" PARAM_FOLLOW = "follow"
PARAM_SYSLOG_IDENTIFIER = "SYSLOG_IDENTIFIER" PARAM_SYSLOG_IDENTIFIER = "SYSLOG_IDENTIFIER"
PARAM_CONTAINER_ID_FULL = "CONTAINER_ID_FULL"
class InterfaceMethod(StrEnum): class InterfaceMethod(StrEnum):