def validate(self): self.process_input_docs() self.process_configuration_docs() self.process_infrastructure_docs() save_manifest([ *self.input_docs, *self.configuration_docs, *self.infrastructure_docs ], self.cluster_model.specification.name) return 0
def init(self): defaults = load_all_yaml_objs(types.DEFAULT, self.provider, 'configuration/minimal-cluster-config') defaults[0].specification.name = self.name for i in range(len(defaults)): defaults[i]['version'] = VERSION if self.is_full_config: defaults = self.get_full_config(defaults) save_manifest(defaults, self.name, self.name + '.yml') self.logger.info('Initialized user configuration and saved it to "' + os.path.join(get_build_path(self.name), self.name + '.yml') + '"') return 0
def get_config_docs(self, input_docs): cluster_config_path = save_manifest(input_docs, self.name, self.name + '.yml') args = type('obj', (object, ), {'file': cluster_config_path})() # generate the config documents with ApplyEngine(args) as build: config = build.dry_run() return config
def apply(self): self.process_input_docs() self.assert_no_master_downscale() self.process_infrastructure_docs() save_manifest([*self.input_docs, *self.infrastructure_docs], self.cluster_model.specification.name) self.assert_consistent_os_family() if not (self.skip_infrastructure or self.is_provider_any(self.cluster_model)): # Generate terraform templates with TerraformTemplateGenerator( self.cluster_model, self.infrastructure_docs) as template_generator: template_generator.run() # Run Terraform to create infrastructure with TerraformRunner(self.cluster_model, self.configuration_docs) as tf_runner: tf_runner.build() self.process_configuration_docs() self.collect_infrastructure_config() # Merge all the docs docs = [*self.configuration_docs, *self.infrastructure_docs] # Save docs to manifest file save_manifest(docs, self.cluster_model.specification.name) # Run Ansible to provision infrastructure if not (self.skip_config): with AnsibleRunner( self.cluster_model, docs, ansible_options=self.ansible_options) as ansible_runner: ansible_runner.apply() return 0
def verify(self): try: self.process_input_docs() self.process_configuration_docs() self.process_infrastructure_docs() save_manifest([ *self.input_docs, *self.configuration_docs, *self.infrastructure_docs ], self.cluster_model.specification.name) return 0 except Exception as e: self.logger.error( e, exc_info=True ) #TODO extensive debug output might not always be wanted. Make this configurable with input flag? return 1
def run(self): try: defaults = load_all_yaml_objs( types.DEFAULT, self.provider, 'configuration/minimal-cluster-config') defaults[0].specification.name = self.name if self.is_full_config: defaults = self.get_full_config(defaults) save_manifest(defaults, self.name, self.name + '.yml') self.logger.info( 'Initialized user configuration and saved it to "' + os.path.join(get_build_path(self.name), self.name + '.yml') + '"') return 0 except Exception as e: self.logger.error( e, exc_info=True ) # TODO extensive debug output might not always be wanted. Make this configurable with input flag? return 1
def get_full_config(self, config_docs): cluster_config_path = save_manifest(config_docs, self.name, self.name + '.yml') args = type('obj', (object, ), {'file': cluster_config_path})() with BuildEngine(args) as build: docs = build.dry_run() # set the provider for all docs for doc in docs: if 'provider' not in doc.keys(): doc['provider'] = self.provider return docs
def apply(self): try: self.process_input_docs() self.process_infrastructure_docs() if not self.skip_infrastructure: # Generate terraform templates with TerraformTemplateGenerator( self.cluster_model, self.infrastructure_docs) as template_generator: template_generator.run() # Run Terraform to create infrastructure with TerraformRunner( self.cluster_model.specification.name) as tf_runner: tf_runner.run() self.process_configuration_docs() self.collect_infrastructure_config() # Run Ansible to provision infrastructure docs = [ *self.input_docs, *self.configuration_docs, *self.infrastructure_docs ] with AnsibleRunner(self.cluster_model, docs) as ansible_runner: ansible_runner.run() # Save docs to manifest file save_manifest(docs, self.cluster_model.specification.name) return 0 except Exception as e: self.logger.error( e, exc_info=True ) # TODO extensive debug output might not always be wanted. Make this configurable with input flag? return 1
def init(self): input = load_all_yaml_objs(types.DEFAULT, self.provider, 'configuration/minimal-cluster-config') input[0].specification.name = self.name if self.is_full_config: config = self.get_config_docs(input) config_only = select_all( config, lambda x: not (x.kind.startswith('epiphany-cluster'))) if self.provider == 'any': # for any provider we want to use the default config from minimal-cluster-config cluster_model = select_single( input, lambda x: x.kind == 'epiphany-cluster') else: # for azure|aws provider we want to use the extended defaults cluster-config after dry run. # TODO: We probably wants this comming from seperate documents since Azure and AWS overlap now... cluster_model = select_single( config, lambda x: x.kind == 'epiphany-cluster') infra = self.get_infra_docs(input) docs = [cluster_model, *config_only, *infra] else: docs = [*input] # set the provider and version for all docs for doc in docs: doc['provider'] = self.provider doc['version'] = VERSION # remove SET_BY_AUTOMATION fields remove_value(docs, 'SET_BY_AUTOMATION') # save document save_manifest(docs, self.name, self.name + '.yml') self.logger.info('Initialized new configuration and saved it to "' + os.path.join(get_build_path(self.name), self.name + '.yml') + '"') return 0
def get_full_config(self, config_docs): cluster_config_path = save_manifest(config_docs, self.name, self.name + '.yml') args = type('obj', (object, ), {'file': cluster_config_path})() with EpiphanyEngine(args) as engine: config_docs = engine.dry_run() infra_docs = load_all_documents_from_folder(self.provider, 'defaults/infrastructure') merged_docs = [*config_docs, *infra_docs] # set the provider for all docs for doc in merged_docs: if 'provider' not in doc.keys(): doc['provider'] = self.provider return merged_docs