예제 #1
0
    def restore_records(self, manifest: ArchiveManifest):
        """
        Re-create the catalog_image and catalog_image_docker records.

        :return:
        """
        with session_scope() as session:
            img_record_str = manifest.metadata.get('image_record')
            if not img_record_str:
                raise Exception('Cannot restore missing image record')
            else:
                img_record = json.loads(img_record_str)

            details = img_record.pop('image_detail')
            if not details:
                details = []

            c = CatalogImage()
            img_record['userId'] = self.account
            c.update(img_record)
            session.add(c)

            for detail in details:
                detail['userId'] = self.account
                tr = CatalogImageDocker()
                tr.update(detail)
                session.add(tr)

        return True
예제 #2
0
def add_record(input_image_record, session=None):
    if not session:
        session = db.Session

    image_record = {}
    image_record.update(input_image_record)

    #image_record.pop('created_at', None)
    image_record.pop('last_updated', None)

    our_result = session.query(CatalogImage).filter_by(
        imageDigest=image_record['imageDigest'],
        userId=image_record['userId'],
        image_type=image_record['image_type']).first()
    if not our_result:
        # add the image detail
        image_detail = image_record.pop('image_detail')
        if image_record['image_type'] == 'docker':
            # add the detail records
            for tag_record in image_detail:
                if image_record['created_at']:
                    tag_record['created_at'] = image_record['created_at']
                rc = db.db_catalog_image_docker.add_record(tag_record,
                                                           session=session)

        our_result = CatalogImage(**image_record)
        session.add(our_result)

    return True
예제 #3
0
def add_record(input_image_record, session=None):
    if not session:
        session = db.Session

    image_record = {}
    image_record.update(input_image_record)

    # image_record.pop('created_at', None)
    image_record.pop("last_updated", None)

    our_result = (session.query(CatalogImage).filter_by(
        imageDigest=image_record["imageDigest"],
        userId=image_record["userId"],
        image_type=image_record["image_type"],
    ).first())
    if not our_result:
        # add the image detail
        image_detail = image_record.pop("image_detail")
        if image_record["image_type"] == "docker":
            # add the detail records
            for tag_record in image_detail:
                if image_record["created_at"]:
                    tag_record["created_at"] = image_record["created_at"]
                rc = db.db_catalog_image_docker.add_record(tag_record,
                                                           session=session)

        our_result = CatalogImage(**image_record)
        session.add(our_result)

    return True
예제 #4
0
    def add(imageDigest,
            userId,
            image_type,
            dbobj={},
            image_data={},
            session=None):
        if not session:
            session = db.Session

        dbobj.pop('created_at', None)
        dbobj.pop('last_updated', None)

        our_result = session.query(CatalogImage).filter_by(
            imageDigest=imageDigest, userId=userId,
            image_type=image_type).first()
        if not our_result:
            if image_type == 'docker' and image_data:
                rc = db.db_catalog_image_docker.add(
                    imageDigest,
                    userId,
                    image_data['tag'],
                    registry=image_data['registry'],
                    user=image_data['user'],
                    repo=image_data['repo'],
                    digest=image_data['digest'],
                    imageId=image_data['imageId'],
                    dockerfile=image_data['dockerfile'],
                    session=session)

            our_result = CatalogImage(imageDigest=imageDigest,
                                      userId=userId,
                                      image_type=image_type)

            our_result.update(dbobj)
            session.add(our_result)
        else:
            our_result.update(dbobj)
            if image_type == 'docker' and image_data:
                rc = db.db_catalog_image_docker.update(
                    imageDigest,
                    userId,
                    image_data['tag'],
                    registry=image_data['registry'],
                    user=image_data['user'],
                    repo=image_data['repo'],
                    digest=image_data['digest'],
                    imageId=image_data['imageId'],
                    dockerfile=image_data['dockerfile'],
                    session=session)

        return (True)