Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sonicaj committed Dec 24, 2024
1 parent 03bfebc commit abbac30
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
8 changes: 7 additions & 1 deletion src/middlewared/middlewared/api/v25_04_0/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,15 @@ class DockerListBackupArgs(BaseModel):
pass


class AppInfo(BaseModel):
id: NonEmptyString
name: NonEmptyString
state: NonEmptyString


class BackupInfo(BaseModel):
name: NonEmptyString
apps: list[NonEmptyString]
apps: list[AppInfo]
snapshot_name: NonEmptyString
created_on: NonEmptyString
backup_path: NonEmptyString
Expand Down
16 changes: 8 additions & 8 deletions src/middlewared/middlewared/plugins/docker/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

from middlewared.api import api_method
from middlewared.api.current import (
DockerBackupResult, DockerUpdateArgs, DockerListBackupArgs, DockerListBackupResult, DockerDeleteBackupArgs,
DockerDeleteBackupResult,
DockerBackupArgs, DockerBackupResult, DockerListBackupArgs, DockerListBackupResult,
DockerDeleteBackupArgs, DockerDeleteBackupResult,
)
from middlewared.plugins.apps.ix_apps.path import get_collective_config_path, get_collective_metadata_path
from middlewared.plugins.zfs_.validation_utils import validate_snapshot_name
Expand All @@ -26,7 +26,7 @@ class DockerService(Service):
class Config:
cli_namespace = 'app.docker'

@api_method(DockerUpdateArgs, DockerBackupResult, roles=['DOCKER_WRITE'])
@api_method(DockerBackupArgs, DockerBackupResult, roles=['DOCKER_WRITE'])
@job(lock='docker_backup')
def backup(self, job, backup_name):
"""
Expand Down Expand Up @@ -57,7 +57,7 @@ def backup(self, job, backup_name):
shutil.copy(get_collective_metadata_path(), os.path.join(backup_dir, 'collective_metadata.yaml'))
shutil.copy(get_collective_config_path(), os.path.join(backup_dir, 'collective_config.yaml'))

with open(backup_apps_state_file_path(), 'w') as f:
with open(backup_apps_state_file_path(name), 'w') as f:
f.write(yaml.safe_dump({app['name']: app for app in self.middleware.call_sync('app.query')}))

with open(os.path.join(backup_dir, 'docker_config.yaml'), 'w') as f:
Expand Down Expand Up @@ -97,18 +97,18 @@ def list_backups(self):
continue

try:
with open(backup_apps_state_file_path(), 'r') as f:
with open(backup_apps_state_file_path(backup_name), 'r') as f:
apps = yaml.safe_load(f.read())
except (FileNotFoundError, yaml.YAMLError):
continue

backups[backup_name] = {
'name': backup_name,
'apps': list(apps),
'apps': [{k: app[k] for k in ('id', 'name', 'state')} for app in apps.values()],
'snapshot_name': snapshot['name'],
'created_on': self.middleware.call_sync(
'created_on': str(self.middleware.call_sync(
'zfs.snapshot.get_instance', snapshot['name']
)['properties']['creation']['parsed'],
)['properties']['creation']['parsed']),
'backup_path': backup_path,
}

Expand Down
10 changes: 5 additions & 5 deletions src/middlewared/middlewared/plugins/docker/restore_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ def restore_backup(self, job, backup_name):
self.middleware.call_sync('docker.fs_manage.mount')

apps_to_start = []
for app_name, app_state in backup['apps']:
if os.path.exists(get_installed_app_path(app_name)) is False:
logger.debug('App %r path not found, skipping restoring', app_name)
for app_info in backup['apps']:
if os.path.exists(get_installed_app_path(app_info['id'])) is False:
logger.debug('App %r path not found, skipping restoring', app_info['id'])
continue

if app_state['state'] is AppState.RUNNING.name:
apps_to_start.append(app_name)
if app_info['state'] == AppState.RUNNING.name:
apps_to_start.append(app_info['id'])

metadata_job = self.middleware.call_sync('app.metadata.generate')
metadata_job.wait_sync()
Expand Down
4 changes: 2 additions & 2 deletions src/middlewared/middlewared/plugins/docker/state_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def catalog_ds_path() -> str:
return os.path.join(IX_APPS_MOUNT_PATH, CATALOG_DATASET_NAME)


def backup_apps_state_file_path() -> str:
return os.path.join(backup_ds_path(), 'apps_state.json')
def backup_apps_state_file_path(backup_name: str) -> str:
return os.path.join(backup_ds_path(), backup_name, 'apps_state.json')


def backup_ds_path() -> str:
Expand Down

0 comments on commit abbac30

Please sign in to comment.