+ def translate(self, base_directory, recursive=True, dryrun=False):
+ """
+ **Translate OSM Packages given a path**
+
+ :params:
+ - base_directory is the root path for all packages
+
+ :return: List of dict of translated packages. keys: current type, new type, path, valid, translated, error
+ """
+ self._logger.debug("")
+ table = []
+ if recursive:
+ descriptors_paths = [
+ f for f in glob.glob(base_directory + "/**/*.yaml", recursive=recursive)
+ ]
+ else:
+ descriptors_paths = [
+ f for f in glob.glob(base_directory + "/*.yaml", recursive=recursive)
+ ]
+ print("Base directory: {}".format(base_directory))
+ print("{} Descriptors found to validate".format(len(descriptors_paths)))
+ for desc_path in descriptors_paths:
+ with open(desc_path) as descriptor_file:
+ descriptor_data = descriptor_file.read()
+ desc_type = "-"
+ try:
+ desc_type, descriptor_data = validation_im.yaml_validation(
+ self, descriptor_data
+ )
+ self._logger.debug("desc_type: {}".format(desc_type))
+ self._logger.debug("descriptor_data:\n{}".format(descriptor_data))
+ self._validator.pyangbind_validation(desc_type, descriptor_data)
+ if not (desc_type == "vnfd" or desc_type == "nsd"):
+ table.append(
+ {
+ "current type": desc_type,
+ "new type": desc_type,
+ "path": desc_path,
+ "valid": "OK",
+ "translated": "N/A",
+ "error": "-",
+ }
+ )
+ else:
+ new_desc_type = desc_type
+ try:
+ sol006_model = yaml.safe_dump(
+ im_translation.translate_im_model_to_sol006(
+ descriptor_data
+ ),
+ indent=4,
+ default_flow_style=False,
+ )
+ (
+ new_desc_type,
+ new_descriptor_data,
+ ) = self._validator.yaml_validation(sol006_model)
+ self._validator.pyangbind_validation(
+ new_desc_type, new_descriptor_data
+ )
+ if not dryrun:
+ with open(desc_path, "w") as descriptor_file:
+ descriptor_file.write(sol006_model)
+ table.append(
+ {
+ "current type": desc_type,
+ "new type": new_desc_type,
+ "path": desc_path,
+ "valid": "OK",
+ "translated": "OK",
+ "error": "-",
+ }
+ )
+ except ValidationException as ve2:
+ table.append(
+ {
+ "current type": desc_type,
+ "new type": new_desc_type,
+ "path": desc_path,
+ "valid": "OK",
+ "translated": "ERROR",
+ "error": "Error in the post-validation: {}".format(
+ str(ve2)
+ ),
+ }
+ )
+ except Exception as e2:
+ table.append(
+ {
+ "current type": desc_type,
+ "new type": new_desc_type,
+ "path": desc_path,
+ "valid": "OK",
+ "translated": "ERROR",
+ "error": "Error in the translation: {}".format(str(e2)),
+ }
+ )
+ except ValidationException as ve:
+ table.append(
+ {
+ "current type": desc_type,
+ "new type": "N/A",
+ "path": desc_path,
+ "valid": "ERROR",
+ "translated": "N/A",
+ "error": "Error in the pre-validation: {}".format(str(ve)),
+ }
+ )
+ except Exception as e:
+ table.append(
+ {
+ "current type": desc_type,
+ "new type": "N/A",
+ "path": desc_path,
+ "valid": "ERROR",
+ "translated": "N/A",
+ "error": str(e),
+ }
+ )
+ return table
+
+ def descriptor_translate(self, descriptor_file):
+ """
+ **Translate input descriptor file from Rel EIGHT OSM to SOL006**
+
+ :params:
+ - base_directory is the root path for all packages
+
+ :return: YAML descriptor in the new format
+ """
+ self._logger.debug("")
+ with open(descriptor_file, "r") as df:
+ im_model = yaml.safe_load(df.read())
+ sol006_model = im_translation.translate_im_model_to_sol006(im_model)
+ return yaml.safe_dump(sol006_model, indent=4, default_flow_style=False)
+