def _load_service_functions(self, service): """ Loads and stores functions (VNFs) referenced in the specified service :param service: service :return: True if successful, None otherwise """ log.debug("Loading functions of the service.") # get VNFD file list from provided dpath vnfd_files = list_files(self._dpath, self._dext) log.debug("Found {0} descriptors in dpath='{2}': {1}".format( len(vnfd_files), vnfd_files, self._dpath)) # load all VNFDs path_vnfs = read_descriptor_files(vnfd_files) # check for errors if 'network_functions' not in service.content: log.error("Service doesn't have any functions. " "Missing 'network_functions' section.") return functions = service.content['network_functions'] if functions and not path_vnfs: log.error("Service references VNFs but none could be found in " "'{0}'. Please specify another '--dpath'".format( self._dpath)) return # store function descriptors referenced in the service for function in functions: fid = build_descriptor_id(function['vnf_vendor'], function['vnf_name'], function['vnf_version']) if fid not in path_vnfs.keys(): log.error("Referenced function descriptor id='{0}' couldn't " "be loaded".format(fid)) return vnf_id = function['vnf_id'] new_func = self._storage.create_function(path_vnfs[fid]) service.associate_function(new_func, vnf_id) return True
def _load_service_functions(self, service): """ Loads and stores functions (VNFs) referenced in the specified service :param service: service :return: True if successful, None otherwise """ log.debug("Loading functions of the service.") # get VNFD file list from provided dpath vnfd_files = list_files(self._dpath, self._dext) log.debug("Found {0} descriptors in dpath='{2}': {1}" .format(len(vnfd_files), vnfd_files, self._dpath)) # load all VNFDs path_vnfs = read_descriptor_files(vnfd_files) # check for errors if 'network_functions' not in service.content: log.error("Service doesn't have any functions. " "Missing 'network_functions' section.") return functions = service.content['network_functions'] if functions and not path_vnfs: log.error("Service references VNFs but none could be found in " "'{0}'. Please specify another '--dpath'" .format(self._dpath)) return # store function descriptors referenced in the service for function in functions: fid = build_descriptor_id(function['vnf_vendor'], function['vnf_name'], function['vnf_version']) if fid not in path_vnfs.keys(): log.error("Referenced function descriptor id='{0}' couldn't " "be found in path '{1}'".format(fid, self._dpath)) return vnf_id = function['vnf_id'] new_func = self._storage.create_function(path_vnfs[fid]) service.associate_function(new_func, vnf_id) return True
def validate_function(self, vnfd_path): """ Validate one or multiple SONATA functions (VNFs). By default, it performs the following validations: syntax, integrity and network topology. :param vnfd_path: function descriptor (VNFD) filename or a directory to search for VNFDs :return: True if all validations were successful, False otherwise """ self._assert_configuration() # validate multiple VNFs if os.path.isdir(vnfd_path): log.info("Validating functions in path '{0}'".format(vnfd_path)) vnfd_files = list_files(vnfd_path, self._dext) for vnfd_file in vnfd_files: if not self.validate_function(vnfd_file): return return True log.info("Validating function '{0}'".format(vnfd_path)) log.info("... syntax: {0}, integrity: {1}, topology: {2}".format( self._syntax, self._integrity, self._topology)) function = self._storage.create_function(vnfd_path) if not function: evtlog.log("Couldn't store VNF of file '{0}'".format(vnfd_path), 'evt_function_invalid_descriptor') return if self._syntax and not self._validate_function_syntax(function): return if self._integrity and not self._validate_function_integrity(function): return if self._topology and not self._validate_function_topology(function): return return True
def validate_function(self, vnfd_path): """ Validate one or multiple SONATA functions (VNFs). By default, it performs the following validations: syntax, integrity and network topology. :param vnfd_path: function descriptor (VNFD) filename or a directory to search for VNFDs :return: True if all validations were successful, False otherwise """ self._assert_configuration() # validate multiple VNFs if os.path.isdir(vnfd_path): log.info("Validating functions in path '{0}'".format(vnfd_path)) vnfd_files = list_files(vnfd_path, self._dext) for vnfd_file in vnfd_files: if not self.validate_function(vnfd_file): return return True log.info("Validating function '{0}'".format(vnfd_path)) log.info("... syntax: {0}, integrity: {1}, topology: {2}" .format(self._syntax, self._integrity, self._topology)) function = self._storage.create_function(vnfd_path) if not function: log.critical("Couldn't store VNF of file '{0}'".format(vnfd_path)) return if self._syntax and not self._validate_function_syntax(function): return if self._integrity and not self._validate_function_integrity(function): return if self._topology and not self._validate_function_topology(function): return return True