def __init__(self, name, canonical_name, path, parent_name='', status=STATUS_UNPROCESSED, parent=None, source=None, logger=None, docker_client=None): self.name = name self.canonical_name = canonical_name self.path = path self.status = status self.parent = parent self.source = source self.parent_name = parent_name if logger is None: logger = utils.make_a_logger(image_name=name) self.logger = logger self.children = [] self.plugins = [] self.additions = [] self.dc = docker_client
def build_image_list(self): def process_source_installation(image, section): installation = dict() # NOTE(jeffrey4l): source is not needed when the type is None if self.conf._get('type', self.conf._get_group(section)) is None: if image.parent_name is None: LOG.debug('No source location found in section %s', section) else: installation['type'] = self.conf[section]['type'] installation['source'] = self.conf[section]['location'] installation['name'] = section if installation['type'] == 'git': installation['reference'] = self.conf[section]['reference'] return installation all_sections = (set(six.iterkeys(self.conf._groups)) | set(self.conf.list_all_sections())) for path in self.docker_build_paths: # Reading parent image name with open(os.path.join(path, 'Dockerfile')) as f: content = f.read() image_name = os.path.basename(path) canonical_name = (self.namespace + '/' + self.image_prefix + image_name + ':' + self.tag) parent_search_pattern = re.compile(r'^FROM.*$', re.MULTILINE) match = re.search(parent_search_pattern, content) if match: parent_name = match.group(0).split(' ')[1] else: parent_name = '' del match image = Image(image_name, canonical_name, path, parent_name=parent_name, logger=utils.make_a_logger(self.conf, image_name), docker_client=self.dc) if self.install_type == 'source': # NOTE(jeffrey4l): register the opts if the section didn't # register in the kolla/common/config.py file if image.name not in self.conf._groups: self.conf.register_opts(common_config.get_source_opts(), image.name) image.source = process_source_installation(image, image.name) for plugin in [match.group(0) for match in (re.search('^{}-plugin-.+'.format(image.name), section) for section in all_sections) if match]: try: self.conf.register_opts( common_config.get_source_opts(), plugin ) except cfg.DuplicateOptError: LOG.debug('Plugin %s already registered in config', plugin) image.plugins.append( process_source_installation(image, plugin)) for addition in [ match.group(0) for match in (re.search('^{}-additions-.+'.format(image.name), section) for section in all_sections) if match]: try: self.conf.register_opts( common_config.get_source_opts(), addition ) except cfg.DuplicateOptError: LOG.debug('Addition %s already registered in config', addition) image.additions.append( process_source_installation(image, addition)) self.images.append(image)
# pip installed kolla tools PROJECT_ROOT = os.path.abspath(os.path.join( os.path.dirname(os.path.realpath(__file__)), '../..')) if PROJECT_ROOT not in sys.path: sys.path.insert(0, PROJECT_ROOT) from kolla.common import config as common_config from kolla.common import task from kolla.common import utils from kolla import exception from kolla.template import filters as jinja_filters from kolla.template import methods as jinja_methods from kolla import version LOG = utils.make_a_logger() # Image status constants. # # TODO(harlowja): use enum lib in the future?? STATUS_CONNECTION_ERROR = 'connection_error' STATUS_PUSH_ERROR = 'push_error' STATUS_ERROR = 'error' STATUS_PARENT_ERROR = 'parent_error' STATUS_BUILT = 'built' STATUS_BUILDING = 'building' STATUS_UNMATCHED = 'unmatched' STATUS_MATCHED = 'matched' STATUS_UNPROCESSED = 'unprocessed' STATUS_SKIPPED = 'skipped'