Split out fetching of legacy names so we can test it

Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
Aanand Prasad 2015-05-21 12:12:02 +01:00
commit b5ce23885b
2 changed files with 51 additions and 19 deletions

View file

@ -26,19 +26,34 @@ def check_for_legacy_containers(
and warn the user that those containers may need to be migrated to
using labels, so that compose can find them.
"""
names = get_legacy_container_names(
client,
project,
services,
stopped=stopped,
one_off=one_off)
for name in names:
log.warn(
"Compose found a found a container named %s without any "
"labels. As of compose 1.3.0 containers are identified with "
"labels instead of naming convention. If you'd like compose "
"to use this container, please run "
"`docker-compose migrate-to-labels`" % (name,))
def get_legacy_container_names(
client,
project,
services,
stopped=False,
one_off=False):
for container in client.containers(all=stopped):
name = get_container_name(container)
for service in services:
prefix = '%s_%s_%s' % (project, service, 'run_' if one_off else '')
if not name.startswith(prefix):
continue
log.warn(
"Compose found a found a container named %s without any "
"labels. As of compose 1.3.0 containers are identified with "
"labels instead of naming convention. If you'd like compose "
"to use this container, please run "
"`docker-compose migrate-to-labels`" % (name,))
if name.startswith(prefix):
yield name
def add_labels(project, container, name):