Ejemplo n.º 1
0
    def get(self, name, namespace):
        with create_session(self.sess_maker) as sess:
            try:
                deployment_obj = (sess.query(Deployment).filter_by(
                    name=name, namespace=namespace).one())
                labels = get_labels(sess, RESOURCE_TYPE.deployment,
                                    deployment_obj.id)
            except NoResultFound:
                return None

            return _deployment_orm_obj_to_pb(deployment_obj, labels)
Ejemplo n.º 2
0
    def _get_latest(self, bento_name):
        with create_session(self.sess_maker) as sess:
            query = (sess.query(Bento).filter_by(
                name=bento_name,
                deleted=False).order_by(desc(Bento.created_at)).limit(1))

            query_result = query.all()
            if len(query_result) == 1:
                labels = get_labels(sess, RESOURCE_TYPE.bento,
                                    query_result[0].id)
                return _bento_orm_obj_to_pb(query_result[0], labels)
            else:
                return None
Ejemplo n.º 3
0
    def get(self, bento_name, bento_version="latest"):
        if bento_version.lower() == "latest":
            return self._get_latest(bento_name)

        with create_session(self.sess_maker) as sess:
            try:
                bento_obj = (sess.query(Bento).filter_by(name=bento_name,
                                                         version=bento_version,
                                                         deleted=False).one())
                if bento_obj.deleted:
                    # bento has been marked as deleted
                    return None
                labels = get_labels(sess, RESOURCE_TYPE.bento, bento_obj.id)
                return _bento_orm_obj_to_pb(bento_obj, labels)
            except NoResultFound:
                return None