Add `ccp images list` command

It lists images that match all components or ones listed in command
line.

Change-Id: I6fa9700e562b7ca0ecafd58521ede47dc84b71d8
This commit is contained in:
Yuriy Taraday 2016-10-25 10:20:26 +02:00
parent 6cff14568f
commit dbf1b45c4a
3 changed files with 30 additions and 5 deletions

View File

@ -147,15 +147,19 @@ def connect_children(dockerfiles):
dockerfile['parent'] = dockerfiles[parent]
def get_dockerfiles_tree(match=False, config=None):
if config is None:
config = _get_config()
def get_dockerfiles(match=False):
dockerfiles = {}
for repository_def in CONF.repositories.repos:
dockerfiles.update(
find_dockerfiles(repository_def['name'], match=match))
return dockerfiles
def get_dockerfiles_tree(match=False, config=None):
if config is None:
config = _get_config()
dockerfiles = get_dockerfiles(match)
render_dockerfiles(dockerfiles, config)
connect_children(dockerfiles)
@ -285,7 +289,7 @@ def get_ready_image_names():
return ready_images
def match_dockerfiles_by_component(dockerfiles, component, ready_images):
def match_dockerfiles_by_component(dockerfiles, component, ready_images=()):
pattern = re.compile(re.escape(component))
matched_dockerfiles = list(filter(pattern.match, dockerfiles.keys()))
if matched_dockerfiles:

View File

@ -205,6 +205,26 @@ class ShowStatus(lister.Lister):
return status.show_long_status(parsed_args.components)
class ImagesList(BaseCommand, lister.Lister):
"""Get images mathcing list of components"""
def get_parser(self, *args, **kwargs):
parser = super(ImagesList, self).get_parser(*args, **kwargs)
parser.add_argument('components',
nargs='*',
help='CCP components to get images for')
return parser
def take_action(self, parsed_args):
dockerfiles = build.get_dockerfiles(match=not parsed_args.components)
for component in parsed_args.components:
build.match_dockerfiles_by_component(dockerfiles, component)
return (
('Name',),
((d['name'],) for d in dockerfiles.values() if d['match']),
)
def signal_handler(signo, frame):
sys.exit(-signo)

View File

@ -35,6 +35,7 @@ ccp.cli =
status = fuel_ccp.cli:ShowStatus
validate = fuel_ccp.cli:Validate
config_dump = fuel_ccp.cli:ConfigDump
images_list = fuel_ccp.cli:ImagesList
[build_sphinx]
source-dir = doc/source