mirror of
https://github.com/netinvent/npbackup.git
synced 2025-09-13 08:24:40 +08:00
Make upgrade server and client exchange full client stats
This commit is contained in:
parent
9aab2745d0
commit
4f06814a1e
5 changed files with 53 additions and 11 deletions
|
@ -168,7 +168,7 @@ def auto_upgrader(
|
|||
We assume that we run a onefile nuitka binary
|
||||
"""
|
||||
is_nuitka = "__compiled__" in globals()
|
||||
if not is_nuitka:
|
||||
if is_nuitka:
|
||||
logger.info(
|
||||
"Auto upgrade will only upgrade compiled verions. Please use 'pip install --upgrade npbackup' instead"
|
||||
)
|
||||
|
@ -195,7 +195,7 @@ def auto_upgrader(
|
|||
logger.error("Cannot get file description")
|
||||
return False
|
||||
|
||||
file_data = requestor.requestor("upgrades/" + platform_and_arch + "/data", raw=True)
|
||||
file_data = requestor.requestor("download/" + id_record, raw=True)
|
||||
if not file_data:
|
||||
logger.error("Cannot get update file")
|
||||
return False
|
||||
|
|
|
@ -7,8 +7,8 @@ __intname__ = "npbackup.upgrade_server.upgrade_server"
|
|||
__author__ = "Orsiris de Jong"
|
||||
__copyright__ = "Copyright (C) 2023 NetInvent"
|
||||
__license__ = "GPL-3.0-only"
|
||||
__build__ = "202303102"
|
||||
__version__ = "1.1.0"
|
||||
__build__ = "2023020301"
|
||||
__version__ = "1.2.0"
|
||||
|
||||
|
||||
DEVEL = True
|
||||
|
|
|
@ -5,7 +5,7 @@ __intname__ = "npbackup.upgrade_server.api"
|
|||
__author__ = "Orsiris de Jong"
|
||||
__copyright__ = "Copyright (C) 2023 NetInvent"
|
||||
__license__ = "GPL-3.0-only"
|
||||
__build__ = "202303102"
|
||||
__build__ = "2023020301"
|
||||
__appname__ = "npbackup.upgrader"
|
||||
|
||||
|
||||
|
@ -63,7 +63,21 @@ async def api_root(auth=Depends(get_current_username)):
|
|||
|
||||
|
||||
@app.get("/current_version", response_model=CurrentVersion, status_code=200)
|
||||
async def current_version(auth=Depends(get_current_username)):
|
||||
async def current_version(request: Request, auth=Depends(get_current_username)):
|
||||
data = {
|
||||
"action": "check_version",
|
||||
"ip": request.client.host,
|
||||
"auto_upgrade_host_identity": '',
|
||||
"installed_version": '',
|
||||
"group": '',
|
||||
"platform": '',
|
||||
"arch": '',
|
||||
}
|
||||
|
||||
try:
|
||||
crud.store_host_info(config_dict["upgrades"]["statistics_file"], host_id=data)
|
||||
except KeyError:
|
||||
logger.error("No statistics file set.")
|
||||
try:
|
||||
result = crud.get_current_version()
|
||||
if not result:
|
||||
|
@ -105,6 +119,7 @@ async def upgrades(
|
|||
auth=Depends(get_current_username),
|
||||
):
|
||||
data = {
|
||||
"action": "get_file_info",
|
||||
"ip": request.client.host,
|
||||
"auto_upgrade_host_identity": auto_upgrade_host_identity,
|
||||
"installed_version": installed_version,
|
||||
|
@ -134,8 +149,34 @@ async def upgrades(
|
|||
)
|
||||
|
||||
|
||||
@app.get("/upgrades/{platform}/{arch}/data", status_code=200)
|
||||
async def download(platform: Platform, arch: Arch, auth=Depends(get_current_username)):
|
||||
@app.get(
|
||||
"/download/{platform}/{arch}/{auto_upgrade_host_identity}/{installed_version}/{group}",
|
||||
response_model=FileSend,
|
||||
status_code=200,
|
||||
)
|
||||
async def download(
|
||||
request: Request,
|
||||
platform: Platform,
|
||||
arch: Arch,
|
||||
auto_upgrade_host_identity: str = None,
|
||||
installed_version: str = None,
|
||||
group: str = None,
|
||||
auth=Depends(get_current_username),
|
||||
):
|
||||
data = {
|
||||
"action": "download_upgrade",
|
||||
"ip": request.client.host,
|
||||
"auto_upgrade_host_identity": auto_upgrade_host_identity,
|
||||
"installed_version": installed_version,
|
||||
"group": group,
|
||||
"platform": platform.value,
|
||||
"arch": arch.value,
|
||||
}
|
||||
|
||||
try:
|
||||
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)
|
||||
try:
|
||||
result = crud.get_file(file, content=True)
|
||||
|
|
|
@ -7,7 +7,7 @@ __intname__ = "npbackup.upgrade_server.configuration"
|
|||
__author__ = "Orsiris de Jong"
|
||||
__copyright__ = "Copyright (C) 2023 NetInvent"
|
||||
__license__ = "GPL-3.0-only"
|
||||
__build__ = "202303101"
|
||||
__build__ = "2023020301"
|
||||
|
||||
|
||||
import os
|
||||
|
|
|
@ -7,13 +7,14 @@ __intname__ = "npbackup.upgrade_server.crud"
|
|||
__author__ = "Orsiris de Jong"
|
||||
__copyright__ = "Copyright (C) 2023 NetInvent"
|
||||
__license__ = "GPL-3.0-only"
|
||||
__build__ = "202303101"
|
||||
__build__ = "2023020301"
|
||||
|
||||
|
||||
import os
|
||||
from typing import Optional, Union
|
||||
from logging import getLogger
|
||||
import hashlib
|
||||
from datetime import datetime
|
||||
from upgrade_server.models.files import FileGet, FileSend
|
||||
from upgrade_server.models.oper import CurrentVersion
|
||||
import upgrade_server.configuration as configuration
|
||||
|
@ -40,7 +41,7 @@ def is_enabled() -> bool:
|
|||
|
||||
def store_host_info(destination: str, host_id: dict) -> None:
|
||||
try:
|
||||
data = ",".join(host_id.values()) + "\n"
|
||||
data = datetime.utcnow().isoformat() + ',' + ",".join([value if value else '' for value in host_id.values()]) + "\n"
|
||||
with open(destination, "a", encoding="utf-8") as fpw:
|
||||
fpw.write(data)
|
||||
except OSError:
|
||||
|
|
Loading…
Add table
Reference in a new issue