Skip to content

Commit fa563fe

Browse files
committed
Add get-service-images command on kolla-images.py
This command print list of images used by Kolla services
1 parent a8e8a01 commit fa563fe

1 file changed

Lines changed: 36 additions & 2 deletions

File tree

tools/kolla-images.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ def parse_args() -> argparse.Namespace:
116116
subparser = subparsers.add_parser("check-hierarchy", help="Check tag variable hierarchy against kolla-ansible")
117117
subparser.add_argument("--kolla-ansible-path", required=True, help="Path to kolla-ansible repostory checked out to correct branch")
118118

119+
subparser = subparsers.add_parser("get-service-images", help="Get space separated list of images used by services in kolla-ansible")
120+
subparser.add_argument("--kolla-ansible-path", required=True, help="Path to kolla-ansible repostory checked out to correct branch")
121+
subparser.add_argument("--services", default=None, required=False, help="Space separated list of services to get a list of images")
122+
119123
subparser = subparsers.add_parser("check-tags", help="Check specified tags for each image exist in the Ark registry")
120124
subparser.add_argument("--registry", required=True, help="Hostname of container image registry")
121125
subparser.add_argument("--namespace", required=True, help="Namespace in container image registry")
@@ -335,13 +339,19 @@ def check_image_map(kolla_ansible_path: str):
335339
sys.exit(1)
336340

337341

338-
def check_hierarchy(kolla_ansible_path: str):
339-
"""Check the tag variable hierarchy against Kolla Ansible variables."""
342+
def get_hierarchy(kolla_ansible_path: str) -> yaml:
343+
"""Return the tag variable hierarchy against Kolla Ansible variables"""
340344
cmd = """git grep -h '^[a-z0-9_]*_tag:' ansible/roles/*/defaults/main.yml"""
341345
hierarchy_str = subprocess.check_output(cmd, shell=True, cwd=os.path.realpath(kolla_ansible_path))
342346
hierarchy = yaml.safe_load(hierarchy_str)
343347
# This one is not a container:
344348
hierarchy.pop("octavia_amp_image_tag")
349+
return hierarchy
350+
351+
352+
def check_hierarchy(kolla_ansible_path: str):
353+
"""Check the tag variable hierarchy against Kolla Ansible variables."""
354+
hierarchy = get_hierarchy(kolla_ansible_path)
345355
tag_var_re = re.compile(r"^([a-z0-9_]+)_tag$")
346356
parent_re = re.compile(r"{{[\s]*([a-z0-9_]+)_tag[\s]*}}")
347357
hierarchy = {
@@ -363,6 +373,28 @@ def check_hierarchy(kolla_ansible_path: str):
363373
sys.exit(1)
364374

365375

376+
def get_service_images(kolla_ansible_path: str, services: str):
377+
"""Get space separated list of images used by selected services in Kolla Ansible"""
378+
hierarchy = get_hierarchy(kolla_ansible_path)
379+
services_list = []
380+
if services:
381+
services_list = services.split(" ")
382+
reversed_hierarchy = []
383+
child_re = re.compile(r"^([a-z0-9_]+)_tag$")
384+
parent_re = re.compile(r"{{[\s]*([a-z0-9_]+)_tag[\s]*}}")
385+
for child, parent in hierarchy.items():
386+
child_name = child_re.match(child).group(1)
387+
parent_name = parent_re.match(parent).group(1)
388+
if(
389+
parent_name == "openstack" or
390+
(len(services_list) > 0 and parent_name not in services_list)
391+
):
392+
continue
393+
reversed_hierarchy.append(child_name)
394+
images_str = " ".join(reversed_hierarchy).replace("_", "-")
395+
print(images_str)
396+
397+
366398
def list_containers(base_distros: List[str]):
367399
"""List supported containers."""
368400
images = read_images("etc/kayobe/pulp.yml")
@@ -414,6 +446,8 @@ def main():
414446
check_image_map(args.kolla_ansible_path)
415447
elif args.command == "check-hierarchy":
416448
check_hierarchy(args.kolla_ansible_path)
449+
elif args.command == "get-service-images":
450+
get_service_images(args.kolla_ansible_path, args.services)
417451
elif args.command == "check-tags":
418452
check_tags(base_distros, kolla_image_tags, args.registry, args.namespace)
419453
elif args.command == "list-containers":

0 commit comments

Comments
 (0)