Only obtain containers with backup enabled

This commit is contained in:
Einar Forselv 2019-04-19 00:00:28 +02:00
parent 01f7cef709
commit ba642eeb4b
2 changed files with 14 additions and 5 deletions

View File

@ -34,10 +34,15 @@ def status(config, containers):
print()
for container in containers.containers:
print('service: {}'.format(container.service_name))
for mount in container.filter_mounts():
print(' - {}'.format(mount.source))
backup_containers = containers.containers_for_backup()
for container in backup_containers:
if container.backup_enabled:
print('service: {}'.format(container.service_name))
for mount in container.filter_mounts():
print(' - {}'.format(mount.source))
if len(backup_containers) == 0:
print("No containers in the project has 'restic-volume-backup.enabled' label")
print()

View File

@ -58,7 +58,7 @@ class Container:
@property
def backup_enabled(self) -> bool:
"""Is backup enabled for this container?"""
return self.get_label('restic-volume-backup.enabled') == 'True'
return self.get_label('restic-volume-backup.enabled') is not None
@property
def is_backup_process_container(self) -> bool:
@ -225,6 +225,10 @@ class RunningContainers:
"""Is the backup process container running?"""
return self.backup_process_container is not None
def containers_for_backup(self):
"""Obtain all containers with backup enabled"""
return [container for container in self.containers if container.backup_enabled]
def get_service(self, name) -> Container:
for container in self.containers:
if container.service_name == name: