diff --git a/kolla/cmd/build.py b/kolla/cmd/build.py index 5a00b1d809..b305ffd7b4 100755 --- a/kolla/cmd/build.py +++ b/kolla/cmd/build.py @@ -13,6 +13,7 @@ # limitations under the License. # TODO(jpeeler): Add clean up handler for SIGINT +from __future__ import print_function import datetime import errno @@ -20,6 +21,7 @@ import graphviz import json import logging import os +import pprint import re import requests import shutil @@ -662,6 +664,38 @@ class KollaWorker(object): with open(to_file, 'w') as f: f.write(dot.source) + def list_images(self): + for count, image in enumerate(self.images): + print(count + 1, ':', image['name']) + + def list_dependencies(self): + match = False + for image in self.images: + if image['status'] in ['matched']: + match = True + if image['parent'] is None: + base = image + if not match: + print('Nothing matched!') + return + + def list_children(images, ancestry): + children = ancestry.values()[0] + for item in images: + if item['status'] not in ['matched']: + continue + + if not item['children']: + children.append(item['name']) + else: + newparent = {item['name']: []} + children.append(newparent) + list_children(item['children'], newparent) + + ancestry = {base['name']: []} + list_children(base['children'], ancestry) + pprint.pprint(ancestry) + def find_parents(self): """Associate all images with parents and children""" sort_images = dict() @@ -723,6 +757,12 @@ def main(): LOG.info('Docker images dependency is saved in %s', conf.save_dependency) return + if conf.list_images: + kolla.list_images() + return + if conf.list_dependencies: + kolla.list_dependencies() + return for x in six.moves.range(conf.threads): worker = WorkerThread(queue, push_queue, conf) diff --git a/kolla/common/config.py b/kolla/common/config.py index 6ccbdf7806..31836c4ba7 100644 --- a/kolla/common/config.py +++ b/kolla/common/config.py @@ -76,6 +76,10 @@ _CLI_OPTS = [ cfg.BoolOpt('keep', default=False, deprecated_group='kolla-build', help='Keep failed intermediate containers'), + cfg.BoolOpt('list-dependencies', short='l', + help='Show image dependencies (filtering supported)'), + cfg.BoolOpt('list-images', + help='Show all available images'), cfg.StrOpt('namespace', short='n', default='kollaglue', deprecated_group='kolla-build', help='The Docker namespace name'),