From 97ed56feb9eff62cb01deb2b404b03b7449458e0 Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Mon, 15 Apr 2019 19:06:48 +0200 Subject: [PATCH] Move container listing to utils module for each mocking --- restic_volume_backup/containers.py | 7 +++---- restic_volume_backup/utils.py | 8 ++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 restic_volume_backup/utils.py diff --git a/restic_volume_backup/containers.py b/restic_volume_backup/containers.py index c9258d0..4886a34 100644 --- a/restic_volume_backup/containers.py +++ b/restic_volume_backup/containers.py @@ -3,6 +3,8 @@ import docker import json import pprint +from restic_volume_backup import utils + DOCKER_BASE_URL = os.environ.get('DOCKER_BASE_URL') or "unix://tmp/docker.sock" VOLUME_TYPE_BIND = "bind" VOLUME_TYPE_VOLUME = "volume" @@ -121,10 +123,7 @@ class Mount: class RunningContainers: def __init__(self): - client = docker.Client(base_url=DOCKER_BASE_URL) - all_containers = client.containers() - client.close() - + all_containers = utils.list_containers() self.containers = [] self.this_container = None diff --git a/restic_volume_backup/utils.py b/restic_volume_backup/utils.py new file mode 100644 index 0000000..e100f13 --- /dev/null +++ b/restic_volume_backup/utils.py @@ -0,0 +1,8 @@ +import docker + + +def list_containers(): + client = docker.Client(base_url=DOCKER_BASE_URL) + all_containers = client.containers() + client.close() + return all_containers