upgrade_server: Implement client specific upgrade overrides

This commit is contained in:
deajan 2025-01-14 22:27:24 +01:00
parent d3f0d26998
commit ba0e6b831c
3 changed files with 26 additions and 8 deletions

View file

@ -7,7 +7,7 @@ __intname__ = "npbackup.upgrade_server.api"
__author__ = "Orsiris de Jong"
__copyright__ = "Copyright (C) 2023-2025 NetInvent"
__license__ = "GPL-3.0-only"
__build__ = "2024091701"
__build__ = "2025011401"
__appname__ = "npbackup.upgrader"
@ -190,7 +190,7 @@ async def upgrades(
# TODO:
# This can be amended by adding specific rules for host identity or groups or installed
file = FileGet(platform=platform, arch=arch, build_type=build_type)
file = FileGet(platform=platform, arch=arch, build_type=build_type, auto_upgrade_host_identity=auto_upgrade_host_identity, installed_version=installed_version, group=group)
try:
result = crud.get_file(file)
if not result:
@ -257,7 +257,7 @@ async def download(
crud.store_host_info(config_dict["upgrades"]["statistics_file"], host_id=data)
except KeyError:
logger.error("No statistics file set.")
file = FileGet(platform=platform, arch=arch, build_type=build_type)
file = FileGet(platform=platform, arch=arch, build_type=build_type, auto_upgrade_host_identity=auto_upgrade_host_identity, installed_version=installed_version, group=group)
try:
result = crud.get_file(file, content=True)
if not result:

View file

@ -7,7 +7,7 @@ __intname__ = "npbackup.upgrade_server.crud"
__author__ = "Orsiris de Jong"
__copyright__ = "Copyright (C) 2023-2025 NetInvent"
__license__ = "GPL-3.0-only"
__build__ = "2024112601"
__build__ = "2025011401"
import os
@ -94,13 +94,27 @@ def get_file(
else:
extension = "tar.gz"
possible_filename = f"npbackup-{file.build_type.value}.{extension}"
path = os.path.join(
base_path = os.path.join(
config_dict["upgrades"]["data_root"],
file.platform.value,
file.arch.value,
possible_filename,
)
logger.info("Searching for %s", path)
for posssible_sub_path in [
file.auto_upgrade_host_identity.value,
file.installed_version.value,
file.group.value,
]:
if posssible_sub_path:
possibile_sub_path = os.path.join(base_path, posssible_sub_path)
if os.path.isdir(possibile_sub_path):
logger.info(f"Found specific upgrade path in {possibile_sub_path}")
base_path = possibile_sub_path
break
path = os.path.join(base_path, possible_filename)
logger.info(f"Searching for {path}")
if not os.path.isfile(path):
logger.info(f"No upgrade file found in {path}")
return {

View file

@ -7,9 +7,10 @@ __intname__ = "npbackup.upgrade_server.models.files"
__author__ = "Orsiris de Jong"
__copyright__ = "Copyright (C) 2023-2025 NetInvent"
__license__ = "GPL-3.0-only"
__build__ = "2024112601"
__build__ = "2025011401"
from typing import Optional
from enum import Enum
from pydantic import BaseModel, constr
@ -33,6 +34,9 @@ class FileBase(BaseModel):
arch: Arch
platform: Platform
build_type: BuildType
auto_upgrade_host_identity: Optional[str] = None
installed_version: Optional[str] = None
group: Optional[str] = None
class FileGet(FileBase):