def _pack_write_napd(self, napdr, name="TOSCA-Metadata/NAPD.yaml"): wd = napdr._project_wd data = napdr.to_clean_dict() path = os.path.join(wd, name) # validate if self.args.offline: LOG.warning("Skipping NAPD validation (--offline)") else: if not validate_yaml_online(data): raise NapdNotValidException( "NAPD validation failed. See logs for details.") LOG.debug("Writing NAPD to: {}".format(path)) with open(path, "w") as f: yaml.dump(data, f, default_flow_style=False) return name
def _read_napd(self, wd, tosca_meta): """ Tries to read NAPD file and optionally validates it against its online schema. - try 1: Use block_1 from TOSCA.meta to find NAPD - try 2: Look for **/NAPD.yaml Returns valid NAPD schema formatted dict. and NAPD path """ try: path = None if (tosca_meta is not None and len(tosca_meta) > 1): # try 1: path = search_for_file( os.path.join(wd, tosca_meta[1].get("Name"))) if path is None: LOG.warning("TOSCA block_1 file '{}' not found.".format( tosca_meta[1].get("Name"))) # try 2: path = search_for_file( os.path.join(wd, "**/NAPD.yaml"), recursive=False) if path is None: LOG.warning("Couldn't find NAPD file: {}".format(wd)) return dict(), None # TODO return an empty NAPD skeleton here with open(path, "r") as f: data = yaml.load(f) if self.args.offline: LOG.warning("Skipping NAPD validation (--offline)") return data, path # skip validation step # validate if validate_yaml_online(data): return data, path raise NapdNotValidException( "Validation of {} failed.".format(path)) except NapdNotValidException as e: LOG.error("Validation error: {}".format(e)) raise e except BaseException as e: LOG.error("Cannot read NAPD.yaml file: {}".format(e)) # raise e return dict(), None # TODO return an empty NAPD skeleton here