def build_chart_group(self, chart_group): """Builds the chart dependencies for`charts`chart group``. :param dict chart_group: The chart_group whose dependencies will be built. :returns: The chart_group with all dependencies. :rtype: dict :raises ManifestException: If a chart for a dependency name listed under ``chart_group['data']['chart_group']`` could not be found. """ try: chart = None for iter, chart in enumerate( chart_group.get('data', {}).get('chart_group', [])): if isinstance(chart, dict): continue chart_dep = self.find_chart_document(chart) chart_group['data']['chart_group'][iter] = { 'chart': chart_dep.get('data', {}) } except Exception: raise exceptions.ManifestException( details="Could not find chart {} in {}".format( chart, const.DOCUMENT_GROUP)) else: return chart_group
def build_armada_manifest(self): """Builds the Armada manifest while pulling out data from the chart_group. :returns: The Armada manifest with the data of the chart groups. :rtype: dict :raises ManifestException: If a chart group's data listed under ``chart_group['data']`` could not be found. """ try: group = None for iter, group in enumerate( self.manifest.get('data', {}).get('chart_groups', [])): if isinstance(group, dict): continue chart_grp = self.find_chart_group_document(group) # Add name to chart group ch_grp_data = chart_grp.get('data', {}) ch_grp_data['name'] = chart_grp.get('metadata', {}).get('name') self.manifest['data']['chart_groups'][iter] = ch_grp_data except Exception: raise exceptions.ManifestException( "Could not find chart group {} in {}".format( group, const.DOCUMENT_MANIFEST)) else: return self.manifest
def find_chart_group_document(self, name): for group in self.groups: if group.get('metadata', {}).get('name') == name: return group raise exceptions.ManifestException( details='Could not find a {} named "{}"'.format( const.DOCUMENT_GROUP, name))
def build_chart_deps(self, chart): """Recursively build chart dependencies for ``chart``. :param dict chart: The chart whose dependencies will be recursively built. :returns: The chart with all dependencies. :rtype: dict :raises ManifestException: If a chart for a dependency name listed under ``chart['data']['dependencies']`` could not be found. """ try: dep = None chart_dependencies = chart.get('data', {}).get('dependencies', []) for iter, dep in enumerate(chart_dependencies): if isinstance(dep, dict): continue chart_dep = self.find_chart_document(dep) self.build_chart_deps(chart_dep) chart['data']['dependencies'][iter] = { 'chart': chart_dep.get('data', {}) } except Exception: raise exceptions.ManifestException( details="Could not find dependency chart {} in {}".format( dep, const.DOCUMENT_CHART)) else: return chart
def find_chart_document(self, name): for chart in self.charts: if chart.get('metadata', {}).get('name') == name: return chart raise exceptions.ManifestException( details='Could not find a {} named "{}"'.format( const.DOCUMENT_CHART, name))
def __init__(self, documents, target_manifest=None): """Instantiates a Manifest object. An Armada Manifest expects that at least one of each of the following be included in ``documents``: * A document with schema "armada/Chart/v1" * A document with schema "armada/ChartGroup/v1" And only one document of the following is allowed: * A document with schema "armada/Manifest/v1" If multiple documents with schema "armada/Manifest/v1" are provided, specify ``target_manifest`` to select the target one. :param List[dict] documents: Documents out of which to build the Armada Manifest. :param str target_manifest: The target manifest to use when multiple documents with "armada/Manifest/v1" are contained in ``documents``. Default is None. :raises ManifestException: If the expected number of document types are not found or if the document types are missing required properties. """ self.documents = deepcopy(documents) self.charts, self.groups, manifests = self._find_documents( target_manifest) if len(manifests) > 1: error = ( 'Multiple manifests are not supported. Ensure that the ' '`target_manifest` option is set to specify the target ' 'manifest') LOG.error(error) raise exceptions.ManifestException(details=error) else: self.manifest = manifests[0] if manifests else None if not all([self.charts, self.groups, self.manifest]): expected_schemas = [schema.TYPE_CHART, schema.TYPE_CHARTGROUP] error = ( 'Documents must include at least one of each of {} ' 'and only one {}').format( expected_schemas, schema.TYPE_MANIFEST) LOG.error(error) raise exceptions.ManifestException(details=error)
def find_chart_group_document(self, name): """Returns a chart group document with the specified name :param str name: name of the desired chart group document :returns: The requested chart group document :rtype: dict :raises ManifestException: If a chart group document with the specified name is not found """ for group in self.groups: if group.get('metadata', {}).get('name') == name: return group raise exceptions.ManifestException( details='Could not find a {} named "{}"'.format( const.DOCUMENT_GROUP, name))
def build_chart_group(self, chart_group): try: chart = None for iter, chart in enumerate( chart_group.get('data').get('chart_group', [])): if isinstance(chart, dict): continue chart_dep = self.find_chart_document(chart) chart_group['data']['chart_group'][iter] = { 'chart': chart_dep.get('data') } except Exception: raise exceptions.ManifestException( details="Could not find chart {} in {}".format( chart, const.DOCUMENT_GROUP))
def build_chart_deps(self, chart): try: dep = None for iter, dep in enumerate(chart.get('data').get('dependencies')): if isinstance(dep, dict): continue chart_dep = self.find_chart_document(dep) self.build_chart_deps(chart_dep) chart['data']['dependencies'][iter] = { 'chart': chart_dep.get('data') } except Exception: raise exceptions.ManifestException( details="Could not find dependency chart {} in {}".format( dep, const.DOCUMENT_CHART))
def build_armada_manifest(self): try: group = None for iter, group in enumerate( self.manifest.get('data').get('chart_groups', [])): if isinstance(group, dict): continue chart_grp = self.find_chart_group_document(group) # Add name to chart group ch_grp_data = chart_grp.get('data') ch_grp_data['name'] = chart_grp.get('metadata').get('name') self.manifest['data']['chart_groups'][iter] = ch_grp_data except Exception: raise exceptions.ManifestException( "Could not find chart group {} in {}".format( group, const.DOCUMENT_MANIFEST))