def write_role_manifest_vars(self, ansible_dir, role, kind): enabled_kinds = { "configuration/haproxy", "configuration/node-exporter" } if kind not in enabled_kinds: return # skip try: cluster_model = select_single( self.manifest_docs, lambda x: x.kind == 'epiphany-cluster') except ExpectedSingleResultException: return # skip document = select_first(self.manifest_docs, lambda x: x.kind == kind) if document is None: # If there is no document provided by the user, then fallback to defaults document = load_yaml_obj(types.DEFAULT, 'common', kind) # Inject the required "version" attribute document['version'] = VERSION # Copy the "provider" value from the cluster model document['provider'] = cluster_model['provider'] # Merge the document with defaults with DefaultMerger([document]) as doc_merger: document = doc_merger.run()[0] self.write_role_vars(ansible_dir, role, document, vars_file_name='manifest.yml')
def _process_input_docs(self): """Load, validate and merge (with defaults) input yaml documents.""" # Get existing manifest config documents self.manifest_docs = load_manifest_docs(self.build_directory) self.cluster_model = select_single(self.manifest_docs, lambda x: x.kind == 'epiphany-cluster') # Load backup / recovery configuration documents self.input_docs = load_yamls_file(self.file) # Validate input documents with SchemaValidator(self.cluster_model, self.input_docs) as schema_validator: schema_validator.run_for_individual_documents() # Merge the input docs with defaults with DefaultMerger(self.input_docs) as doc_merger: self.input_docs = doc_merger.run()
def get_shared_config_from_manifest(self): # Reuse shared config from existing manifest # Shared config contains the use_ha_control_plane flag which is required during upgrades cluster_model = select_single(self.manifest_docs, lambda x: x.kind == 'epiphany-cluster') try: shared_config_doc = select_single(self.manifest_docs, lambda x: x.kind == 'configuration/shared-config') shared_config_doc['provider'] = cluster_model['provider'] except ExpectedSingleResultException: # If there is no shared-config doc inside the manifest file, this is probably a v0.3 cluster # Returning None here (there is nothing to merge at this point) and # hoping that the shared-config doc from defaults will be enough return None # Merge the shared config doc with defaults with DefaultMerger([shared_config_doc]) as doc_merger: shared_config_doc = doc_merger.run()[0] del shared_config_doc['provider'] return shared_config_doc
def _process_input_docs(self): """Load, validate and merge (with defaults) input yaml documents.""" path_to_manifest = os.path.join(self.build_directory, MANIFEST_FILE_NAME) if not os.path.isfile(path_to_manifest): raise Exception('No manifest.yml inside the build folder') # Get existing manifest config documents self.manifest_docs = load_yamls_file(path_to_manifest) self.cluster_model = select_single(self.manifest_docs, lambda x: x.kind == 'epiphany-cluster') # Load backup / recovery configuration documents self.input_docs = load_yamls_file(self.file) # Validate input documents with SchemaValidator(self.cluster_model, self.input_docs) as schema_validator: schema_validator.run_for_individual_documents() # Merge the input docs with defaults with DefaultMerger(self.input_docs) as doc_merger: self.input_docs = doc_merger.run()
def process_input_docs(self): # Load the user input YAML docs from the input file. if os.path.isabs(self.file): path_to_load = self.file else: path_to_load = os.path.join(os.getcwd(), self.file) user_file_stream = open(path_to_load, 'r') self.input_docs = safe_load_all(user_file_stream) # Merge the input docs with defaults with DefaultMerger(self.input_docs) as doc_merger: self.input_docs = doc_merger.run() # Get the cluster model. self.cluster_model = select_single( self.input_docs, lambda x: x.kind == 'epiphany-cluster') if self.cluster_model is None: raise Exception('No cluster model defined in input YAML file') # Validate input documents with SchemaValidator(self.cluster_model, self.input_docs) as schema_validator: schema_validator.run()
def get_shared_config_from_manifest(self): # Reuse shared config from existing manifest # Shared config contains the use_ha_control_plane flag which is required during upgrades path_to_manifest = os.path.join(self.inventory_upgrade.build_dir, MANIFEST_FILE_NAME) if not os.path.isfile(path_to_manifest): raise Exception('No manifest.yml inside the build folder') manifest_docs = load_yamls_file(path_to_manifest) cluster_model = select_single(manifest_docs, lambda x: x.kind == 'epiphany-cluster') shared_config_doc = select_single( manifest_docs, lambda x: x.kind == 'configuration/shared-config') shared_config_doc['provider'] = cluster_model['provider'] # Merge the shared config doc with defaults with DefaultMerger([shared_config_doc]) as doc_merger: shared_config_doc = doc_merger.run()[0] del shared_config_doc['provider'] return shared_config_doc