Пример #1
0
    def post(self, request):
        """
        Create a new repo. `id` field in body is required. `display_name` will default to `id`.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest

        :return: Response containing a serialized dict for the created repo.
        :rtype : django.http.HttpResponse
        """
        repo_data = request.body_as_json
        repo_id = repo_data.get('id')

        repo_obj = repo_controller.create_repo(
            repo_id,
            display_name=repo_data.get('display_name', repo_id),
            description=repo_data.get('description'),
            notes=repo_data.get('notes'),
            importer_type_id=repo_data.get('importer_type_id'),
            importer_repo_plugin_config=repo_data.get('importer_config'),
            distributor_list=repo_data.get('distributors')
        )

        repo = serializers.Repository(repo_obj).data
        response = generate_json_response_with_pulp_encoder(repo)
        return generate_redirect_response(response, repo['_href'])
Пример #2
0
    def post(self, request):
        """
        Create a new repo. `id` field in body is required. `display_name` will default to `id`.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest

        :return: Response containing a serialized dict for the created repo.
        :rtype : django.http.HttpResponse
        """
        repo_data = request.body_as_json
        repo_id = repo_data.get('id')

        repo_obj = repo_controller.create_repo(
            repo_id,
            display_name=repo_data.get('display_name', repo_id),
            description=repo_data.get('description'),
            notes=repo_data.get('notes'),
            importer_type_id=repo_data.get('importer_type_id'),
            importer_repo_plugin_config=repo_data.get('importer_config'),
            distributor_list=repo_data.get('distributors')
        )

        repo = serializers.Repository(repo_obj).data
        response = generate_json_response_with_pulp_encoder(repo)
        return generate_redirect_response(response, repo['_href'])
Пример #3
0
    def process_main(self, item=None):
        repo = self.get_repo()

        units_coll = RepoContentUnit.get_collection()
        units = self._get_units(units_coll, repo.id)

        snapshot_name = repo.notes.get(REPO_SNAPSHOT_NAME)
        if snapshot_name:
            old_units = self._get_units(units_coll, snapshot_name)
        else:
            old_units = []
        units = self._units_to_set(units)
        old_units = self._units_to_set(old_units)
        # Create a snapshot if one did not exist before (snapshot_name is
        # None) and the repo is not empty, or if the unit contents are
        # different
        if units == old_units and (snapshot_name or not units):
            return self._build_report(snapshot_name)

        now = time.time()
        suffix = time.strftime("%Y%m%d%H%M%S", time.gmtime(now))
        suffix = "__%s.%04dZ" % (suffix, 10000 * (now - int(now)))
        new_name = "%s%s" % (repo.id, suffix)
        notes = {}
        notes[REPO_SNAPSHOT_TIMESTAMP] = now
        if '_repo-type' in repo.notes:
            notes['_repo-type'] = repo.notes['_repo-type']
        notes[REPO_SNAPSHOT_NAME] = new_name
        notes[REPO_SNAPSHOT_TIMESTAMP] = now
        distributors = []
        # Fetch the repo's existing importers

        repo_importer = RepoImporter.objects.filter(repo_id=repo.id).first()
        if repo_importer is not None:
            importer_type_id = repo_importer['importer_type_id']
        else:
            importer_type_id = None

        repo_obj = repo_controller.create_repo(
            new_name,
            notes=notes,
            importer_type_id=importer_type_id,
            importer_repo_plugin_config={},
            distributor_list=distributors)
        copied = []
        for unit in sorted(units):
            copied.append(
                RepoContentUnit(
                    repo_id=new_name,
                    unit_id=unit.unit_id,
                    unit_type_id=unit.unit_type_id,
                ))
        if copied:
            units_coll.insert(copied)
        repo_controller.rebuild_content_unit_counts(repo_obj)

        group_coll = RepoGroup.get_collection()
        group_coll.update(dict(repo_ids=repo.id),
                          {'$addToSet': dict(repo_ids=new_name)})
        return self._build_report(new_name)
Пример #4
0
 def _create_repo(self, repo_id):
     return repo_controller.create_repo(repo_id)
Пример #5
0
 def _create_repo(self, repo_id):
     return repo_controller.create_repo(repo_id)