示例#1
0
def add_fields_in_template_files(version_id, req_template_files):
    """
    add id and content fields in template_files
    """
    try:
        ventity = models.VersionedEntity.objects.get(id=version_id)
    except models.VersionedEntity.DoesNotExist:
        raise serializers.ValidationError(
            f"template version(id:{version_id}) does not exist")

    entity = ventity.get_entity()
    template_files = []
    for res_file in req_template_files:
        res_name = res_file["resource_name"]
        res_file_ids = entity[res_name].split(",")
        resource_file = get_resource_file(res_name, res_file_ids, "id", "name",
                                          "content")

        if "files" not in res_file:
            template_files.append(resource_file)
            continue

        if not res_file["files"]:
            raise serializers.ValidationError(
                f"empty parameter files in template_files({res_name})")

        resource_file_map = {f["name"]: f for f in resource_file["files"]}
        files = [resource_file_map[f["name"]] for f in res_file["files"]]
        template_files.append({"resource_name": res_name, "files": files})

    return template_files
示例#2
0
 def _get_raw_manifests(self) -> List[str]:
     """基于资源kind和表id,生成原始的manifest列表"""
     raw_manifests = []
     # instance_entity like {"Deployment": [1, 2]}
     for res_kind, res_file_ids in self.res_ctx.instance_entity.items():
         res_file = res2files.get_resource_file(res_kind, res_file_ids,
                                                'content')
         raw_manifests.extend([f['content'] for f in res_file['files']])
     return raw_manifests