def load_node_definition(self, aws_node_yaml): env_values = yaml.load(aws_node_yaml) node_definition = env_values['nodes'][0] node_type_class = node_definition['type'] node_definition.pop('type') node_definition_object = get_class_from_fully_qualified_string(node_type_class)(**node_definition) return node_definition, node_definition_object
def _validate_service_definitions(definition_data, abs_path_to_config): error_list = [] for service_name, definitions in definition_data.items(): if not 'service_configurator' in definitions: raise Exception( "Key 'service_configurator' is not found in services configuration of service: '%s'" % (service_name)) configurator_name = definitions['service_configurator'] try: service_configurator = get_class_from_fully_qualified_string(configurator_name)() except StandardError as e: error_list.append("Invalid Service Configurator: '%s' in services configuration of service: '%s'. Underlying error %s" % ( configurator_name, service_name, e)) continue service_configurator.validate(service_name, definitions, abs_path_to_config, error_list) if not len(error_list): return not_first_errors = False error_string = "" for error in error_list: if not_first_errors: error_string += ",\n" not_first_errors = True error_string = error_string + error raise Exception(error_string)
def node_definition_from_map(node_definition, all_credentials): node_class_name = node_definition['type'] fq_class = get_class_from_fully_qualified_string(node_class_name) #We don't need the 'type' in the definition map... node_definition.pop('type') node_def_object = fq_class(**node_definition) if 'credentials_name' in node_definition.keys(): node_def_object.add_credentials(all_credentials) return node_def_object
def get_service_lifecycle_hooks(env_values): service_lifecycle_hooks = {} if 'service_hooks' in env_values.keys(): for service_name, hook_definitions in env_values['service_hooks'].items(): hooks = [] for hook_definition in hook_definitions : class_name = get_class_from_fully_qualified_string(hook_definition['class_name']) hook_definition.pop('class_name') hooks.append(class_name(**hook_definition)) service_lifecycle_hooks.update({service_name: hooks}) return service_lifecycle_hooks
def service_definitions_from_yaml(yaml_string, abs_path_to_config): definition_data = yaml.load(yaml_string) _validate_service_definitions(definition_data, abs_path_to_config) definition_map = {} for service_name, definitions in definition_data.items(): configurator_name = definitions['service_configurator'] service_configurator = get_class_from_fully_qualified_string(configurator_name)() definition_map[service_name] = ServiceDefinition(service_name, definitions, service_configurator, abs_path_to_config) return definition_map
def _validate_node_definition(env_name, error_list, node_definition, node_number, all_credentials, service_definitions): if not 'services' in node_definition: error_list.append("Key 'services' is not set for node number %s in '%s' environment" % (node_number, env_name)) else : for service_name in node_definition['services']: if not service_name in service_definitions.keys(): error_list.append("Service definitions is missing for '%s' in node number %s for '%s' environment" % (service_name, node_number, env_name)) if not 'type' in node_definition: error_list.append("Node type is missing for node number %s in '%s' environment" % (node_number, env_name)) else: node_type_class = node_definition['type'] try: node_definition_object = get_class_from_fully_qualified_string(node_type_class)() node_definition_object.validate(error_list, node_number, env_name, node_definition, all_credentials) except StandardError: error_list.append("Node type '%s' is invalid for node number %s in '%s' environment" % ( node_type_class, node_number, env_name))