def get_all_by_lp(cls, context, lp): session = sql.SolumBase.get_session() apps = [] with session.begin(): query = session.query(cls).filter_by(languagepack=lp) apps = sql.filter_by_project(context, query).all() return apps
def update_and_save(cls, context, id_or_uuid, data): try: session = sql.SolumBase.get_session() with session.begin(): query = session.query(cls).filter_by(id=id_or_uuid) obj = sql.filter_by_project(context, query).one() if obj._is_updatable(): obj.update(data) session.merge(obj) return obj except orm_exc.NoResultFound: cls._raise_not_found(id_or_uuid)
def get_by_name(cls, context, name, include_operators_lp=False): try: session = Image.get_session() result = session.query(cls).filter_by( artifact_type='language_pack', name=name) if include_operators_lp is True: result = result.filter( Image.project_id.in_([operator_id, context.tenant])) return result.one() else: return sql.filter_by_project(context, result).one() except exc.NoResultFound: cls._raise_not_found(name)
def get_all_languagepacks(cls, context): """Return all images that are languagepacks.""" session = Image.get_session() result = session.query(cls) result = result.filter_by(artifact_type='language_pack') result = sql.filter_by_project(context, result) # Include Languagepacks that have been created by the operator, and # are in the 'READY' state. # The operator LP is identified based on the operator_project_id # config setting in solum.conf oper_result = session.query(cls) oper_result = oper_result.filter_by(artifact_type='language_pack') oper_result = oper_result.filter_by(status='READY') oper_result = oper_result.filter_by(project_id=operator_id) return result.union(oper_result).all()
def get_lp_by_name_or_uuid(cls, context, name_or_uuid, include_operators_lp=False): if uuidutils.is_uuid_like(name_or_uuid): try: session = Image.get_session() result = session.query(cls).filter_by( artifact_type='language_pack', uuid=name_or_uuid) if include_operators_lp is True: result = result.filter( Image.project_id.in_([operator_id, context.tenant])) return result.one() else: return sql.filter_by_project(context, result).one() except exc.NoResultFound: return cls.get_by_name(context, name_or_uuid, include_operators_lp) else: return cls.get_by_name(context, name_or_uuid, include_operators_lp)