Example #1
0
 def _build_filter(self, visible_tenants, profile_uuid):
     filter_ = Profile.uuid == profile_uuid
     if visible_tenants is not None:
         if not visible_tenants:
             raise exception.NoSuchProfileAPIException(profile_uuid)
         filter_ = and_(filter_, Profile.tenant_uuid.in_(visible_tenants))
     return filter_
Example #2
0
    def edit(self, visible_tenants, profile_uuid, body):
        filter_ = self._build_filter(visible_tenants, profile_uuid)
        with self.new_session() as s:
            self._dissociate_all_services(s, profile_uuid)

            profile = s.query(Profile).filter(filter_).first()
            if not profile:
                raise exception.NoSuchProfileAPIException(profile_uuid)

            profile.name = body['name']
            profile.display_uuid = body['display']['uuid']
            profile.display_tenant_uuid = profile.tenant_uuid
            try:
                s.flush()
            except exc.IntegrityError as e:
                constraint_name = extract_constraint_name(e)
                if constraint_name == 'dird_profile_display_uuid_tenant_fkey':
                    raise exception.NoSuchDisplay(body['display']['uuid'])
                elif constraint_name == 'dird_profile_tenant_name':
                    raise exception.DuplicatedProfileException(body['name'])
                raise

            self._associate_all_services(
                s, profile.tenant_uuid, profile_uuid, body['services']
            )
Example #3
0
    def get(self, visible_tenants, profile_uuid):
        filter_ = self._build_filter(visible_tenants, profile_uuid)
        with self.new_session() as s:
            profile = s.query(Profile).filter(filter_).first()
            if not profile:
                raise exception.NoSuchProfileAPIException(profile_uuid)

            return self._profile_schema.dump(profile)
Example #4
0
    def delete(self, visible_tenants, profile_uuid):
        filter_ = self._build_filter(visible_tenants, profile_uuid)
        with self.new_session() as s:
            nb_deleted = s.query(Profile).filter(filter_).delete(
                synchronize_session=False)

        if not nb_deleted:
            raise exception.NoSuchProfileAPIException(profile_uuid)
Example #5
0
    def get_sources_from_profile_name(self, tenant_uuid, profile_name, **list_params):
        try:
            profile = self.get_by_name(tenant_uuid, profile_name)
        except exception.NoSuchProfile as e:
            raise exception.NoSuchProfileAPIException(e.profile)
        sources = {}
        for service in profile.get('services', {}).values():
            for source in service.get('sources', []):
                sources[source['uuid']] = source
        sources = list(sources.values())

        total = len(sources)
        sources = self._filter_sources(sources, **list_params)
        filtered = len(sources)
        sources = self._paginate(sources, **list_params)

        return total, filtered, sources