From e4263822bfbd5fc4cbc413d69513bb332a7a3dc8 Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Sat, 7 Mar 2020 01:27:24 +0100 Subject: [PATCH] Container: Stack name + reorganize --- src/restic_compose_backup/containers.py | 55 ++++++++++++++----------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/src/restic_compose_backup/containers.py b/src/restic_compose_backup/containers.py index 92200fe..fb68e47 100644 --- a/src/restic_compose_backup/containers.py +++ b/src/restic_compose_backup/containers.py @@ -63,6 +63,36 @@ class Container: """Image name""" return self.get_config('Image') + @property + def name(self) -> str: + """Container name""" + return self._data['Name'].replace('/', '') + + @property + def service_name(self) -> str: + """Name of the container/service""" + return self.get_label('com.docker.compose.service', default='') + + @property + def backup_process_label(self) -> str: + """str: The unique backup process label for this project""" + return f"{enums.LABEL_BACKUP_PROCESS}-{self.project_name}" + + @property + def project_name(self) -> str: + """str: Name of the compose setup""" + return self.get_label('com.docker.compose.project', default='') + + @property + def stack_name(self) -> str: + """str: Name of the stack is present""" + return self.get_label("com.docker.stack.namespace") + + @property + def is_oneoff(self) -> bool: + """Was this container started with run command?""" + return self.get_label('com.docker.compose.oneoff', default='False') == 'True' + @property def environment(self) -> list: """All configured env vars for the container as a list""" @@ -150,31 +180,6 @@ class Container: """bool: Is the container running?""" return self._state.get('Running', False) - @property - def name(self) -> str: - """Container name""" - return self._data['Name'].replace('/', '') - - @property - def service_name(self) -> str: - """Name of the container/service""" - return self.get_label('com.docker.compose.service', default='') - - @property - def backup_process_label(self) -> str: - """str: The unique backup process label for this project""" - return f"{enums.LABEL_BACKUP_PROCESS}-{self.project_name}" - - @property - def project_name(self) -> str: - """Name of the compose setup""" - return self.get_label('com.docker.compose.project', default='') - - @property - def is_oneoff(self) -> bool: - """Was this container started with run command?""" - return self.get_label('com.docker.compose.oneoff', default='False') == 'True' - def get_config(self, name, default=None): """Get value from config dict""" return self._config.get(name, default)