From d4c301a8312a6ef00fe29e1934d1ad7d22d9beaf Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Fri, 29 Nov 2019 01:31:53 +0100 Subject: [PATCH] Add id and hostname property --- restic_volume_backup/containers.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/restic_volume_backup/containers.py b/restic_volume_backup/containers.py index 90c1dac..610bc76 100644 --- a/restic_volume_backup/containers.py +++ b/restic_volume_backup/containers.py @@ -12,7 +12,6 @@ class Container: def __init__(self, data: dict): self._data = data - self.id = data['Id'] self._state = data.get('State') self._config = data.get('Config') @@ -30,6 +29,16 @@ class Container: self._include = self._parse_pattern(self.get_label('restic-volume-backup.include')) self._exclude = self._parse_pattern(self.get_label('restic-volume-backup.exclude')) + @property + def id(self) -> str: + """str: The id of the container""" + return self._data.get('Id') + + @property + def hostname(self) -> str: + """12 character hostname based on id""" + return self.id[:12] + @property def image(self) -> str: """Image name""" @@ -268,6 +277,7 @@ class RunningContainers: return [container for container in self.containers if container.backup_enabled] def generate_backup_mounts(self, dest_prefix='/backup') -> dict: + """Generate mounts for backup for the entire compose setup""" mounts = {} for container in self.containers_for_backup(): if container.volume_backup_enabled: