2019-04-15 17:06:48 +00:00
|
|
|
import docker
|
2019-04-15 17:49:57 +00:00
|
|
|
|
|
|
|
from restic_volume_backup.config import Config
|
2019-04-15 17:06:48 +00:00
|
|
|
|
2019-04-19 15:14:29 +00:00
|
|
|
TRUE_VALUES = ['1', 'true', 'True', True, 1]
|
|
|
|
|
2019-04-15 17:06:48 +00:00
|
|
|
|
|
|
|
def list_containers():
|
2019-04-18 01:49:47 +00:00
|
|
|
"""
|
|
|
|
List all containers.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
List of raw container json data from the api
|
|
|
|
"""
|
2019-04-16 16:22:03 +00:00
|
|
|
config = Config()
|
2019-04-18 01:49:47 +00:00
|
|
|
client = docker.DockerClient(base_url=config.docker_base_url)
|
|
|
|
all_containers = client.containers.list()
|
2019-04-15 17:06:48 +00:00
|
|
|
client.close()
|
2019-04-18 01:49:47 +00:00
|
|
|
return [c.attrs for c in all_containers]
|
2019-04-19 15:14:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
def is_true(self, value):
|
|
|
|
"""
|
|
|
|
Evaluates the truthfullness of a bool value in container labels
|
|
|
|
"""
|
|
|
|
return value in TRUE_VALUES
|