container instance property creating subclass

This commit is contained in:
Einar Forselv 2019-12-03 01:41:03 +01:00
parent ea1f2be4bc
commit 031da1aa5b
1 changed files with 15 additions and 1 deletions

View File

@ -30,6 +30,20 @@ class Container:
self._include = self._parse_pattern(self.get_label('restic-volume-backup.include')) self._include = self._parse_pattern(self.get_label('restic-volume-backup.include'))
self._exclude = self._parse_pattern(self.get_label('restic-volume-backup.exclude')) 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 @property
def id(self) -> str: def id(self) -> str:
"""str: The id of the container""" """str: The id of the container"""
@ -102,7 +116,7 @@ class Container:
@property @property
def postgresql_backup_enabled(self) -> bool: 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 @property
def is_backup_process_container(self) -> bool: def is_backup_process_container(self) -> bool: