From 031da1aa5be5d4d025fe8727ed7fca1d2f9f853d Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Tue, 3 Dec 2019 01:41:03 +0100 Subject: [PATCH] container instance property creating subclass --- restic_volume_backup/containers.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/restic_volume_backup/containers.py b/restic_volume_backup/containers.py index a7191bd..fc470f8 100644 --- a/restic_volume_backup/containers.py +++ b/restic_volume_backup/containers.py @@ -30,6 +30,20 @@ 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 instance(self) -> 'Container': + """Container: Get a service specific subclass instance""" + if self.database_backup_enabled: + from restic_volume_backup import containers_db + if self.mariadb_backup_enabled: + return containers_db.MariadbContainer(self._data) + if self.mysql_backup_enabled: + return containers_db.MysqlContainer(self._data) + if self.postgresql_backup_enabled: + return containers_db.PostgresContainer(self._data) + else: + return self + @property def id(self) -> str: """str: The id of the container""" @@ -102,7 +116,7 @@ class Container: @property def postgresql_backup_enabled(self) -> bool: - return utils.is_true(self.get_label('restic-volume-backup.postgresql')) + return utils.is_true(self.get_label('restic-volume-backup.postgres')) @property def is_backup_process_container(self) -> bool: