def __init__(self, tosca_parser_template, provider, cluster_name): self.provider = provider self.provider_config = ProviderConfiguration(self.provider) self.cluster_name = cluster_name ExceptionCollector.start() for sec in self.REQUIRED_CONFIG_PARAMS: if not self.provider_config.config[self.provider_config.MAIN_SECTION].get(sec): ExceptionCollector.appendException(ProviderConfigurationParameterError( what=sec )) ExceptionCollector.stop() if ExceptionCollector.exceptionsCaught(): raise ValidationError( message='\nTranslating to provider failed: ' .join(ExceptionCollector.getExceptionsReport()) ) # toscaparser.tosca_template:ToscaTemplate self.tosca_parser_template = tosca_parser_template # toscaparser.topology_template:TopologyTemplate self.tosca_topology_template = self.full_type_definitions(self.tosca_parser_template.topology_template) import_definition_file = ImportsLoader([self.definition_file()], None, list(SERVICE_TEMPLATE_KEYS), self.tosca_topology_template.tpl) self.full_provider_defs = copy.copy(self.tosca_topology_template.custom_defs) self.provider_defs = import_definition_file.get_custom_defs() self.full_provider_defs.update(self.provider_defs) self.artifacts = [] self.used_conditions_set = set() self.extra_configuration_tool_params = dict() self.inputs = self.tosca_topology_template.inputs self.outputs = self.tosca_topology_template.outputs node_templates = self.resolve_get_property_functions(self.tosca_topology_template.nodetemplates) self.topology_template = self.translate_to_provider() self.node_templates = self.topology_template.nodetemplates self.relationship_templates = self.topology_template.relationship_templates self.template_dependencies = dict() # list of lists # After this step self.node_templates has requirements with node_filter parameter self.resolve_in_template_dependencies() self.resolve_in_template_get_functions() self.configuration_content = None self.configuration_ready = None # Create the list of ProviderResource instances self.software_component_names = [] for node in self.node_templates: if self._is_software_component(node): self.software_component_names.append(node.name) self.provider_nodes = self._provider_nodes() self.provider_nodes_by_name = self._provider_nodes_by_name() self.relationship_templates_by_name = self._relationship_templates_by_name() self.provider_node_names_by_priority = self._sort_nodes_by_priority() self.provider_nodes_queue = self.sort_nodes_by_dependency()
def _validate_external_artifact_imports(self, main_tpl, tpl_filename): """validate the imports and artifacts""" self._validate_template(main_tpl, tpl_filename) if main_tpl: if 'imports' in main_tpl: custom_service = ImportsLoader( main_tpl['imports'], os.path.join(self.temp_dir, tpl_filename)) # Get list of nested templates nested_tosca_tpls = custom_service.get_nested_tosca_tpls() # Validate external references of each nested template. if nested_tosca_tpls: for tosca_tpl in nested_tosca_tpls: for filename, tpl in tosca_tpl.items(): self._validate_external_artifact_imports( tpl, filename)
def _validate_external_references(self): """Extracts files referenced in the main template These references are currently supported: * imports * interface implementations * artifacts """ try: self.decompress() main_tpl_file = self.get_main_template() if not main_tpl_file: return main_tpl = self.get_main_template_yaml() if 'imports' in main_tpl: ImportsLoader(main_tpl['imports'], os.path.join(self.temp_dir, main_tpl_file)) if 'topology_template' in main_tpl: topology_template = main_tpl['topology_template'] if 'node_templates' in topology_template: node_templates = topology_template['node_templates'] for node_template_key in node_templates: node_template = node_templates[node_template_key] if 'artifacts' in node_template: artifacts = node_template['artifacts'] for artifact_key in artifacts: artifact = artifacts[artifact_key] if isinstance(artifact, six.string_types): self._validate_external_reference( main_tpl_file, artifact) elif isinstance(artifact, dict): if 'file' in artifact: self._validate_external_reference( main_tpl_file, artifact['file']) else: ExceptionCollector.appendException( ValueError(_('Unexpected artifact ' 'definition for "%s".') % artifact_key)) self.error_caught = True if 'interfaces' in node_template: interfaces = node_template['interfaces'] for interface_key in interfaces: interface = interfaces[interface_key] for opertation_key in interface: operation = interface[opertation_key] if isinstance(operation, six.string_types): self._validate_external_reference( main_tpl_file, operation, False) elif isinstance(operation, dict): if 'implementation' in operation: self._validate_external_reference( main_tpl_file, operation['implementation']) finally: if self.temp_dir: shutil.rmtree(self.temp_dir)
def _imports_content_test(self, tpl_snippet, path, custom_type_def): imports = (toscaparser.utils.yamlparser. simple_parse(tpl_snippet)['imports']) loader = ImportsLoader(imports, path, custom_type_def) return loader.get_custom_defs()
def _imports_content_test(self, tpl_snippet, path, custom_type_def): imports = ( toscaparser.utils.yamlparser.simple_parse(tpl_snippet)['imports']) loader = ImportsLoader(imports, path, custom_type_def) return loader.get_custom_defs()
def __init__(self, tosca_parser_template_object, provider, configuration_tool, cluster_name, host_ip_parameter, public_key_path, is_delete, common_map_files=[]): self.provider = provider self.is_delete = is_delete self.host_ip_parameter = host_ip_parameter self.public_key_path = public_key_path self.configuration_tool = configuration_tool self.provider_config = ProviderConfiguration(self.provider) self.cluster_name = cluster_name for sec in self.REQUIRED_CONFIG_PARAMS: if not self.provider_config.config[self.provider_config.MAIN_SECTION].get(sec): logging.error("Provider configuration parameter \'%s\' has missing value" % sec) logging.error("Translating failed") sys.exit(1) map_files = self.provider_config.get_section(self.provider_config.MAIN_SECTION) \ .get(TOSCA_ELEMENTS_MAP_FILE) if isinstance(map_files, six.string_types): map_files = [map_files] tosca_elements_map_files = [] for file in map_files: map_file = file if not os.path.isabs(file): map_file = os.path.join(self.provider_config.config_directory, file) tosca_elements_map_files.append(map_file) self.map_files = common_map_files self.map_files.extend(tosca_elements_map_files) for file in self.map_files: if not os.path.isfile(file): logging.error("Mapping file for provider %s not found: %s" % (self.provider, file)) sys.exit(1) topology_template = tosca_parser_template_object.topology_template self.inputs = topology_template.tpl.get(INPUTS, {}) self.outputs = topology_template.tpl.get(OUTPUTS, {}) self.definitions = topology_template.custom_defs self.node_templates = {} self.relationship_templates = {} self.template_mapping = {} for tmpl in topology_template.nodetemplates: self.node_templates[tmpl.name] = tmpl.entity_tpl for tmpl in topology_template.relationship_templates: self.relationship_templates[tmpl.name] = tmpl.entity_tpl import_definition_file = ImportsLoader([self.definition_file()], None, list(SERVICE_TEMPLATE_KEYS), topology_template.tpl) self.definitions.update(import_definition_file.get_custom_defs()) self.software_types = set() self.fulfil_definitions_with_parents() self.artifacts = [] self.used_conditions_set = set() self.extra_configuration_tool_params = dict() self.make_extended_notations() self.node_templates = self.resolve_get_property_functions(self.node_templates) self.relationship_templates = self.resolve_get_property_functions(self.relationship_templates) # resolving template dependencies fo normative templates self.template_dependencies = dict() self._relation_target_source = dict() self.resolve_in_template_dependencies() self.normative_nodes_graph = self.normative_nodes_graph_dependency() self.translate_to_provider() self.make_extended_notations() self.configuration_content = None self.configuration_ready = None self.template_dependencies = dict() self._relation_target_source = dict() self.resolve_in_template_dependencies() # After this step self.node_templates has requirements with node_filter parameter self.replace_requirements_with_node_filter() self.provider_nodes = self._provider_nodes() self.provider_relations = self._provider_relations() self.normative_nodes_graph = self.translate_normative_graph() # self.provider_node_names_by_priority = self._sort_nodes_by_priority() self.provider_operations, self.reversed_provider_operations = self.sort_nodes_and_operations_by_graph_dependency()