test/config/docker/objects/docker_config.py
croy 82d417b9e6 New StarlingX Automation Framework
Fresh start for the StarlingX automation framework.

Change-Id: Ie265e0791024f45f71faad6315c2b91b022934d1
2024-11-29 16:01:57 -05:00

33 lines
1.2 KiB
Python

import json5
from config.docker.objects.registry import Registry
class DockerConfig:
"""
Class to hold configuration of the Cloud Platform's Docker Registries
"""
def __init__(self, config):
self.registry_list: [Registry] = []
try:
json_data = open(config)
except FileNotFoundError:
print(f"Could not find the docker config file: {config}")
raise
docker_dict = json5.load(json_data)
for registry in docker_dict['registries']:
registry_dict = docker_dict['registries'][registry]
reg = Registry(registry_dict['registry_name'], registry_dict['registry_url'], registry_dict['user_name'], registry_dict['password'])
self.registry_list.append(reg)
def get_registry(self, registry_name) -> Registry:
"""
Getter for the KUBECONFIG environment variable on the lab where we want to run.
"""
registries = list(filter(lambda registry: registry.get_registry_name() == registry_name, self.registry_list))
if not registries:
raise ValueError(f"No registry with the name {registry_name} was found")
return registries[0]