コード例 #1
0
    def search_content(self, criteria=None):
        self._ensure_alive()

        criteria = criteria or Criteria.true()
        out = []

        # Pass the criteria through the code used by the real client to build
        # up the Pulp query. We don't actually *use* the resulting query since
        # we're not accessing a real Pulp server. The point is to ensure the
        # same validation and error behavior as used by the real client also
        # applies to the fake.
        prepared_search = search_for_criteria(criteria, Unit)

        available_type_ids = set(self._type_ids)
        missing_type_ids = set(prepared_search.type_ids
                               or []) - available_type_ids
        if missing_type_ids:
            return f_return_error(
                PulpException(
                    "following type ids are not supported on the server: %s" %
                    ",".join(missing_type_ids)))

        for unit in self._all_units:
            if (prepared_search.type_ids
                    and unit.content_type_id not in prepared_search.type_ids):
                continue
            if match_object(criteria, unit):
                out.append(unit)

        # callers should not make any assumption about the order of returned
        # values. Encourage that by returning output in unpredictable order
        random.shuffle(out)
        return self._prepare_pages(out)
コード例 #2
0
    def update_content(self, unit):
        self._ensure_alive()

        if not unit.unit_id:
            raise ValueError("unit_id missing on call to update_content()")

        # The unit has to exist.
        existing_unit = None
        for candidate in self._all_units:
            if (candidate.content_type_id == unit.content_type_id
                    and candidate.unit_id == unit.unit_id):
                existing_unit = candidate
                break
        else:
            return f_return_error(
                PulpException("unit not found: %s" % unit.unit_id))

        # OK, we have a unit to update. Figure out which fields we can update.
        update = {}
        for fld in unit._usermeta_fields():
            update[fld.name] = getattr(unit, fld.name)

        updated_unit = attr.evolve(existing_unit, **update)

        unit_key = units.make_unit_key(updated_unit)
        self._units_by_key[unit_key] = updated_unit

        return f_return()
コード例 #3
0
    def update_repository(self, repository):
        self._ensure_alive()

        with self._state.lock:
            existing_repo = None
            for candidate in self._state.repositories:
                if candidate.id == repository.id:
                    existing_repo = candidate
                    break
            else:
                return f_return_error(
                    PulpException("repository not found: %s" % repository.id)
                )

            # We've got a repo, now update it.
            update = {}
            for fld in existing_repo._mutable_note_fields():
                update[fld.name] = getattr(repository, fld.name)

            updated_repo = attr.evolve(existing_repo, **update)

            self._state.repositories = [
                repo for repo in self._state.repositories if repo.id != updated_repo.id
            ] + [updated_repo]

        return f_return()
コード例 #4
0
ファイル: client.py プロジェクト: rajulkumar/pubtools-pulplib
    def get_repository(self, repository_id):
        if not isinstance(repository_id, six.string_types):
            raise TypeError("Invalid argument: id=%s" % id)

        data = self.search_repository(
            Criteria.with_id(repository_id)).result().data
        if len(data) != 1:
            return f_return_error(
                PulpException("Repository id=%s not found" % repository_id))

        return f_return(data[0])