예제 #1
0
파일: cud.py 프로젝트: taftsanders/pulp
    def create_repo_group(group_id, display_name=None, description=None, repo_ids=None, notes=None):
        """
        Create a new repo group.
        :param group_id: unique id of the repo group
        :param display_name: display name of the repo group
        :type  display_name: str or None
        :param description: description of the repo group
        :type  description: str or None
        :param repo_ids: list of ids for repos initially belonging to the repo group
        :type  repo_ids: list or None
        :param notes: notes for the repo group
        :type  notes: dict or None
        :return: SON representation of the repo group
        :rtype: bson.SON
        """
        # Check if ids in repo_ids belong to existing repositories
        existing_repos = model.Repository.objects(repo_id__in=repo_ids)
        if repo_ids and existing_repos.count() != len(repo_ids):
            existing_repo_ids = set([repo.repo_id for repo in existing_repos])
            non_existing_repo_ids = list(set(repo_ids) - existing_repo_ids)
            raise pulp_exceptions.MissingResource(repositories=non_existing_repo_ids)

        # Create repo group
        collection = RepoGroup.get_collection()
        repo_group = RepoGroup(group_id, display_name, description, repo_ids, notes)
        try:
            collection.insert(repo_group)
        except DuplicateKeyError:
            raise pulp_exceptions.DuplicateResource(group_id), None, sys.exc_info()[2]
        group = collection.find_one({'id': group_id})
        return group
예제 #2
0
 def create_repo_group(group_id,
                       display_name=None,
                       description=None,
                       repo_ids=None,
                       notes=None):
     """
     Create a new repo group.
     :param group_id: unique id of the repo group
     :param display_name: display name of the repo group
     :type  display_name: str or None
     :param description: description of the repo group
     :type  description: str or None
     :param repo_ids: list of ids for repos initially belonging to the repo group
     :type  repo_ids: list or None
     :param notes: notes for the repo group
     :type  notes: dict or None
     :return: SON representation of the repo group
     :rtype: bson.SON
     """
     if repo_ids:
         # Check if ids in repo_ids belong to existing repositories
         repo_query_manager = manager_factory.repo_query_manager()
         for repo_id in repo_ids:
             repo_query_manager.get_repository(repo_id)
     # Create repo group
     collection = RepoGroup.get_collection()
     repo_group = RepoGroup(group_id, display_name, description, repo_ids,
                            notes)
     try:
         collection.insert(repo_group, safe=True)
     except DuplicateKeyError:
         raise pulp_exceptions.DuplicateResource(
             group_id), None, sys.exc_info()[2]
     group = collection.find_one({'id': group_id})
     return group
예제 #3
0
    def find_with_distributor_type(self, distributor_type_id):
        """
        Returns a list of repository groups, including a list of distributor
        instances, for all groups that have a configured distributor of the
        given type. The distributor list will be stored in the group under
        the key "distributors"

        @return: list of group objects from the database with an extra key
                 added holding the distributor instances
        """

        group_coll = RepoGroup.get_collection()
        group_distributor_coll = RepoGroupDistributor.get_collection()

        groups_by_id = {}

        spec = {'distributor_type_id' : distributor_type_id}
        group_distributors = list(group_distributor_coll.find(spec))
        for gd in group_distributors:
            group = groups_by_id.get(gd['repo_group_id'], None)
            if group is None:
                group = group_coll.find_one({'id' : gd['repo_group_id']})
                groups_by_id[gd['repo_group_id']] = group

            dists = group.setdefault('distributors', [])
            dists.append(gd)

        return groups_by_id.values()
예제 #4
0
파일: cud.py 프로젝트: nbetm/pulp
    def create_repo_group(group_id, display_name=None, description=None, repo_ids=None, notes=None):
        """
        Create a new repo group.
        :param group_id: unique id of the repo group
        :param display_name: display name of the repo group
        :type  display_name: str or None
        :param description: description of the repo group
        :type  description: str or None
        :param repo_ids: list of ids for repos initially belonging to the repo group
        :type  repo_ids: list or None
        :param notes: notes for the repo group
        :type  notes: dict or None
        :return: SON representation of the repo group
        :rtype: bson.SON
        """
        # Check if ids in repo_ids belong to existing repositories
        existing_repos = model.Repository.objects(repo_id__in=repo_ids)
        if repo_ids and existing_repos.count() != len(repo_ids):
            existing_repo_ids = set([repo.repo_id for repo in existing_repos])
            non_existing_repo_ids = list(set(repo_ids) - existing_repo_ids)
            raise pulp_exceptions.MissingResource(repositories=non_existing_repo_ids)

        # Create repo group
        collection = RepoGroup.get_collection()
        repo_group = RepoGroup(group_id, display_name, description, repo_ids, notes)
        try:
            collection.insert(repo_group, safe=True)
        except DuplicateKeyError:
            raise pulp_exceptions.DuplicateResource(group_id), None, sys.exc_info()[2]
        group = collection.find_one({"id": group_id})
        return group
예제 #5
0
 def GET(self, repo_group_id):
     collection = RepoGroup.get_collection()
     group = collection.find_one({'id': repo_group_id})
     if group is None:
         raise pulp_exceptions.MissingResource(repo_group=repo_group_id)
     group.update(serialization.link.current_link_obj())
     return self.ok(group)
예제 #6
0
파일: repo_groups.py 프로젝트: omps/pulp
 def GET(self, repo_group_id):
     collection = RepoGroup.get_collection()
     group = collection.find_one({'id': repo_group_id})
     if group is None:
         raise pulp_exceptions.MissingResource(repo_group=repo_group_id)
     group.update(serialization.link.current_link_obj())
     return self.ok(group)
예제 #7
0
파일: cud.py 프로젝트: beav/pulp
 def create_repo_group(group_id, display_name=None, description=None, repo_ids=None, notes=None):
     """
     Create a new repo group.
     :param group_id: unique id of the repo group
     :param display_name: display name of the repo group
     :type  display_name: str or None
     :param description: description of the repo group
     :type  description: str or None
     :param repo_ids: list of ids for repos initially belonging to the repo group
     :type  repo_ids: list or None
     :param notes: notes for the repo group
     :type  notes: dict or None
     :return: SON representation of the repo group
     :rtype: bson.SON
     """
     if repo_ids:
         # Check if ids in repo_ids belong to existing repositories
         repo_query_manager = manager_factory.repo_query_manager()
         for repo_id in repo_ids:
             repo_query_manager.get_repository(repo_id)
     # Create repo group
     collection = RepoGroup.get_collection()
     repo_group = RepoGroup(group_id, display_name, description, repo_ids, notes)
     try:
         collection.insert(repo_group, safe=True)
     except DuplicateKeyError:
         raise pulp_exceptions.DuplicateResource(group_id), None, sys.exc_info()[2]
     group = collection.find_one({'id': group_id})
     return group
예제 #8
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)
예제 #9
0
파일: repo_groups.py 프로젝트: omps/pulp
 def POST(self, repo_group_id):
     criteria = Criteria.from_client_input(self.params().get('criteria', {}))
     manager = managers_factory.repo_group_manager()
     manager.unassociate(repo_group_id, criteria)
     collection = RepoGroup.get_collection()
     group = collection.find_one({'id': repo_group_id})
     return self.ok(group['repo_ids'])
예제 #10
0
파일: query.py 프로젝트: taftsanders/pulp
    def find_with_distributor_type(self, distributor_type_id):
        """
        Returns a list of repository groups, including a list of distributor
        instances, for all groups that have a configured distributor of the
        given type. The distributor list will be stored in the group under
        the key "distributors"

        @return: list of group objects from the database with an extra key
                 added holding the distributor instances
        """

        group_coll = RepoGroup.get_collection()
        group_distributor_coll = RepoGroupDistributor.get_collection()

        groups_by_id = {}

        spec = {'distributor_type_id': distributor_type_id}
        group_distributors = list(group_distributor_coll.find(spec))
        for gd in group_distributors:
            group = groups_by_id.get(gd['repo_group_id'], None)
            if group is None:
                group = group_coll.find_one({'id': gd['repo_group_id']})
                groups_by_id[gd['repo_group_id']] = group

            dists = group.setdefault('distributors', [])
            dists.append(gd)

        return groups_by_id.values()
예제 #11
0
파일: repo_groups.py 프로젝트: omps/pulp
 def GET(self):
     collection = RepoGroup.get_collection()
     cursor = collection.find({})
     groups = []
     for group in cursor:
         group.update(serialization.link.child_link_obj(group['id']))
         groups.append(group)
     return self.ok(groups)
예제 #12
0
 def GET(self):
     collection = RepoGroup.get_collection()
     cursor = collection.find({})
     groups = []
     for group in cursor:
         group.update(serialization.link.child_link_obj(group['id']))
         groups.append(group)
     return self.ok(groups)
예제 #13
0
    def find_all(self):
        """
        Returns all repository groups in the database or an empty list if
        none exist.

        @return: list of database representations of all repository groups
        @rtype:  list
        """
        groups = list(RepoGroup.get_collection().find())
        return groups
예제 #14
0
파일: query.py 프로젝트: taftsanders/pulp
    def find_all(self):
        """
        Returns all repository groups in the database or an empty list if
        none exist.

        @return: list of database representations of all repository groups
        @rtype:  list
        """
        groups = list(RepoGroup.get_collection().find())
        return groups
예제 #15
0
파일: query.py 프로젝트: taftsanders/pulp
    def find_by_criteria(criteria):
        """
        Return a list of repository groups that match the provided criteria.

        @param criteria:    A Criteria object representing a search you want
                            to perform
        @type  criteria:    pulp.server.db.model.criteria.Criteria

        @return:    list of repo group instances
        @rtype:     list
        """
        return RepoGroup.get_collection().query(criteria)
예제 #16
0
    def find_by_criteria(criteria):
        """
        Return a list of repository groups that match the provided criteria.

        @param criteria:    A Criteria object representing a search you want
                            to perform
        @type  criteria:    pulp.server.db.model.criteria.Criteria

        @return:    list of repo group instances
        @rtype:     list
        """
        return RepoGroup.get_collection().query(criteria)
예제 #17
0
 def POST(self, repo_group_id):
     criteria = Criteria.from_client_input(self.params().get('criteria', {}))
     manager = managers_factory.repo_group_manager()
     tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id),
             action_tag('repo_group_unassociate')]
     call_request = CallRequest(manager.unassociate,
                                [repo_group_id, criteria],
                                tags=tags)
     call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id)
     execution.execute(call_request)
     collection = RepoGroup.get_collection()
     group = collection.find_one({'id': repo_group_id})
     return self.ok(group['repo_ids'])
예제 #18
0
 def POST(self, repo_group_id):
     criteria = Criteria.from_client_input(self.params().get('criteria', {}))
     manager = managers_factory.repo_group_manager()
     tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id),
             action_tag('repo_group_unassociate')]
     call_request = CallRequest(manager.unassociate,
                                [repo_group_id, criteria],
                                tags=tags)
     call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id)
     execution.execute(call_request)
     collection = RepoGroup.get_collection()
     group = collection.find_one({'id': repo_group_id})
     return self.ok(group['repo_ids'])
예제 #19
0
파일: cud.py 프로젝트: tomlanyon/pulp
 def create_repo_group(self, group_id, display_name=None, description=None, repo_ids=None, notes=None):
     """
     Create a new repo group.
     @param group_id: unique id of the repo group
     @param display_name: display name of the repo group
     @type  display_name: str or None
     @param description: description of the repo group
     @type  description: str or None
     @param repo_ids: list of ids for repos initially belonging to the repo group
     @type  repo_ids: list or None
     @param notes: notes for the repo group
     @type  notes: dict or None
     @return: SON representation of the repo group
     @rtype:  L{bson.SON}
     """
     collection = RepoGroup.get_collection()
     repo_group = RepoGroup(group_id, display_name, description, repo_ids, notes)
     try:
         collection.insert(repo_group, safe=True)
     except DuplicateKeyError:
         raise pulp_exceptions.DuplicateResource(group_id), None, sys.exc_info()[2]
     group = collection.find_one({'id': group_id})
     return group
    def test_post_with_repos(self):
        # Setup
        manager_factory.repo_manager().create_repo("add-me")

        data = {"id": "with-repos", "repo_ids": ["add-me"]}

        # Test
        status, body = self.post("/v2/repo_groups/", data)

        # Verify
        self.assertEqual(201, status)

        found = RepoGroup.get_collection().find_one({"id": data["id"]})
        self.assertEqual(found["repo_ids"], data["repo_ids"])
예제 #21
0
    def test_post_with_repos(self):
        # Setup
        manager_factory.repo_manager().create_repo('add-me')

        data = {'id': 'with-repos', 'repo_ids': ['add-me']}

        # Test
        status, body = self.post('/v2/repo_groups/', data)

        # Verify
        self.assertEqual(201, status)

        found = RepoGroup.get_collection().find_one({'id': data['id']})
        self.assertEqual(found['repo_ids'], data['repo_ids'])
    def test_update_notes(self):
        group_id = "update-me"
        self.manager.create_repo_group(group_id, display_name="Original", notes={"a": "A", "b": "B"})

        # Test
        changed = {"notes": {"b": ""}}
        status, body = self.put("/v2/repo_groups/%s/" % group_id, changed)

        # Verify
        self.assertEqual(200, status)

        found = RepoGroup.get_collection().find_one({"id": group_id})
        self.assertTrue("a" in found["notes"])
        self.assertTrue("b" not in found["notes"])
예제 #23
0
    def test_delete(self):
        # Setup
        group_id = 'doomed'
        self.manager.create_repo_group(group_id)

        # Test
        status, body = self.delete('/v2/repo_groups/%s/' % group_id)

        # Verify
        self.assertEqual(200, status)

        found = RepoGroup.get_collection().find_one({'id' : group_id})
        self.assertTrue(found is None)
        self.assertEqual(body, None)
예제 #24
0
    def test_update(self):
        # Setup
        group_id = 'update-me'
        self.manager.create_repo_group(group_id, display_name='Original')

        # Test
        changed = {'display_name' : 'Updated'}
        status, body = self.put('/v2/repo_groups/%s/' % group_id, changed)

        # Verify
        self.assertEqual(200, status)

        found = RepoGroup.get_collection().find_one({'id' : group_id})
        self.assertEqual(changed['display_name'], found['display_name'])
    def test_post(self):
        # Setup
        data = {"id": "post-group", "display_name": "Post Group", "description": "Post Description"}

        # Test
        status, body = self.post("/v2/repo_groups/", data)

        # Verify
        self.assertEqual(201, status)

        found = RepoGroup.get_collection().find_one({"id": data["id"]})
        self.assertTrue(found is not None)
        for k, v in data.items():
            self.assertEqual(found[k], v)
    def test_update(self):
        # Setup
        group_id = "update-me"
        self.manager.create_repo_group(group_id, display_name="Original")

        # Test
        changed = {"display_name": "Updated"}
        status, body = self.put("/v2/repo_groups/%s/" % group_id, changed)

        # Verify
        self.assertEqual(200, status)

        found = RepoGroup.get_collection().find_one({"id": group_id})
        self.assertEqual(changed["display_name"], found["display_name"])
    def test_delete(self):
        # Setup
        group_id = "doomed"
        self.manager.create_repo_group(group_id)

        # Test
        status, body = self.delete("/v2/repo_groups/%s/" % group_id)

        # Verify
        self.assertEqual(200, status)

        found = RepoGroup.get_collection().find_one({"id": group_id})
        self.assertTrue(found is None)
        self.assertEqual(body, None)
예제 #28
0
    def test_update(self):
        # Setup
        group_id = 'update-me'
        self.manager.create_repo_group(group_id, display_name='Original')

        # Test
        changed = {'display_name' : 'Updated'}
        status, body = self.put('/v2/repo_groups/%s/' % group_id, changed)

        # Verify
        self.assertEqual(200, status)

        found = RepoGroup.get_collection().find_one({'id' : group_id})
        self.assertEqual(changed['display_name'], found['display_name'])
예제 #29
0
    def test_update_notes(self):
        group_id = 'update-me'
        self.manager.create_repo_group(group_id, display_name='Original',
            notes={'a':'A', 'b':'B'})

        # Test
        changed = {'notes' : {'b':''}}
        status, body = self.put('/v2/repo_groups/%s/' % group_id, changed)

        # Verify
        self.assertEqual(200, status)

        found = RepoGroup.get_collection().find_one({'id' : group_id})
        self.assertTrue('a' in found['notes'])
        self.assertTrue('b' not in found['notes'])
예제 #30
0
    def test_update_notes(self):
        group_id = 'update-me'
        self.manager.create_repo_group(group_id, display_name='Original',
            notes={'a':'A', 'b':'B'})

        # Test
        changed = {'notes' : {'b':''}}
        status, body = self.put('/v2/repo_groups/%s/' % group_id, changed)

        # Verify
        self.assertEqual(200, status)

        found = RepoGroup.get_collection().find_one({'id' : group_id})
        self.assertTrue('a' in found['notes'])
        self.assertTrue('b' not in found['notes'])
예제 #31
0
    def get(self, request):
        """
        Return a serialized response containing a list of repo groups.

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

        :return: Response containing a serialized list of dicts, one for each repo group
        :rtype: django.http.HttpResponse
        """

        collection = RepoGroupModel.get_collection()
        cursor = collection.find({})
        groups = [_add_group_link(group) for group in cursor]
        return generate_json_response_with_pulp_encoder(groups)
예제 #32
0
    def get(self, request):
        """
        Return a serialized response containing a list of repo groups.

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

        :return: Response containing a serialized list of dicts, one for each repo group
        :rtype: django.http.HttpResponse
        """

        collection = RepoGroupModel.get_collection()
        cursor = collection.find({})
        groups = [_add_group_link(group) for group in cursor]
        return generate_json_response_with_pulp_encoder(groups)
예제 #33
0
파일: cud.py 프로젝트: ashcrow/pulp
def validate_existing_repo_group(group_id):
    """
    Validate the existence of a repo group, given its id.
    Returns the repo group db collection upon successful validation,
    raises an exception upon failure
    @param group_id: unique id of the repo group to validate
    @type  group_id: str
    @return: repo group db collection
    @rtype:  L{pulp.server.db.connection.PulpCollection}
    @raise:  L{pulp.server.exceptions.MissingResource}
    """
    collection = RepoGroup.get_collection()
    repo_group = collection.find_one({'id': group_id})
    if repo_group is not None:
        return collection
    raise pulp_exceptions.MissingResource(repo_group=group_id)
예제 #34
0
파일: cud.py 프로젝트: ashcrow/pulp
 def remove_repo_from_groups(self, repo_id, group_ids=None):
     """
     Remove a repo from the list of repo groups provided.
     If no repo groups are specified, remove the repo from all repo groups
     its currently in.
     (idempotent: useful when deleting repositories)
     @param repo_id: unique id of the repo to remove from repo groups
     @type  repo_id: str
     @param group_ids: list of repo group ids to remove the repo from
     @type  group_ids: list of None
     """
     spec = {}
     if group_ids is not None:
         spec = {'id': {'$in': group_ids}}
     collection = RepoGroup.get_collection()
     collection.update(spec, {'$pull': {'repo_ids': repo_id}}, multi=True, safe=True)
예제 #35
0
    def get_group(self, repo_group_id):
        """
        Returns the repository group with the given ID, raising an exception
        if one does not exist.

        @param repo_group_id: identifies the group
        @type  repo_group_id: str

        @return: database representation of the repo group

        @raise MissingResource: if there is no group with the given ID
        """
        group = RepoGroup.get_collection().find_one({'id' : repo_group_id})
        if group is None:
            raise MissingResource(repo_group=repo_group_id)
        return group
예제 #36
0
파일: query.py 프로젝트: taftsanders/pulp
    def get_group(self, repo_group_id):
        """
        Returns the repository group with the given ID, raising an exception
        if one does not exist.

        @param repo_group_id: identifies the group
        @type  repo_group_id: str

        @return: database representation of the repo group

        @raise MissingResource: if there is no group with the given ID
        """
        group = RepoGroup.get_collection().find_one({'id': repo_group_id})
        if group is None:
            raise MissingResource(repo_group=repo_group_id)
        return group
예제 #37
0
파일: cud.py 프로젝트: taftsanders/pulp
def validate_existing_repo_group(group_id):
    """
    Validate the existence of a repo group, given its id.
    Returns the repo group db collection upon successful validation,
    raises an exception upon failure
    @param group_id: unique id of the repo group to validate
    @type  group_id: str
    @return: repo group db collection
    @rtype:  L{pulp.server.db.connection.PulpCollection}
    @raise:  L{pulp.server.exceptions.MissingResource}
    """
    collection = RepoGroup.get_collection()
    repo_group = collection.find_one({'id': group_id})
    if repo_group is not None:
        return collection
    raise pulp_exceptions.MissingResource(repo_group=group_id)
예제 #38
0
파일: cud.py 프로젝트: taftsanders/pulp
 def remove_repo_from_groups(self, repo_id, group_ids=None):
     """
     Remove a repo from the list of repo groups provided.
     If no repo groups are specified, remove the repo from all repo groups
     its currently in.
     (idempotent: useful when deleting repositories)
     @param repo_id: unique id of the repo to remove from repo groups
     @type  repo_id: str
     @param group_ids: list of repo group ids to remove the repo from
     @type  group_ids: list of None
     """
     spec = {}
     if group_ids is not None:
         spec = {'id': {'$in': group_ids}}
     collection = RepoGroup.get_collection()
     collection.update(spec, {'$pull': {'repo_ids': repo_id}}, multi=True)
예제 #39
0
    def test_post_with_repos(self):
        # Setup
        manager_factory.repo_manager().create_repo('add-me')

        data = {
            'id' : 'with-repos',
            'repo_ids' : ['add-me']
        }

        # Test
        status, body = self.post('/v2/repo_groups/', data)

        # Verify
        self.assertEqual(201, status)

        found = RepoGroup.get_collection().find_one({'id' : data['id']})
        self.assertEqual(found['repo_ids'], data['repo_ids'])
예제 #40
0
    def test_post(self):
        # Setup
        data = {
            'id' : 'post-group',
            'display_name' : 'Post Group',
            'description' : 'Post Description',
        }

        # Test
        status, body = self.post('/v2/repo_groups/', data)

        # Verify
        self.assertEqual(201, status)

        found = RepoGroup.get_collection().find_one({'id' : data['id']})
        self.assertTrue(found is not None)
        for k, v in data.items():
            self.assertEqual(found[k], v)
예제 #41
0
    def get(self, request):
        """
        Return a serialized response containing a list of repo groups.

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

        :return: Response containing a serialized list of dicts, one for each repo group
        :rtype: django.http.HttpResponse
        """

        collection = RepoGroupModel.get_collection()
        cursor = collection.find({})
        groups = []
        for group in cursor:
            group['_href'] = reverse('repo_group_resource', kwargs={'repo_group_id': group['id']})
            groups.append(group)
        return generate_json_response_with_pulp_encoder(groups)
예제 #42
0
    def test_post(self):
        # Setup
        data = {
            'id' : 'post-group',
            'display_name' : 'Post Group',
            'description' : 'Post Description',
        }

        # Test
        status, body = self.post('/v2/repo_groups/', data)

        # Verify
        self.assertEqual(201, status)

        found = RepoGroup.get_collection().find_one({'id' : data['id']})
        self.assertTrue(found is not None)
        for k, v in data.items():
            self.assertEqual(found[k], v)
예제 #43
0
    def get(self, request, repo_group_id):
        """
        Retrieve the specified repo group.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_group_id: id of repo group to return
        :type  repo_group_id: str

        :return: Response containing serialized dict of the specified group
        :rtype: django.http.HttpResponse
        :raises pulp_exceptions.MissingResource: if repo_group_id is not found
        """
        collection = RepoGroupModel.get_collection()
        group = collection.find_one({'id': repo_group_id})
        if group is None:
            raise pulp_exceptions.MissingResource(repo_group=repo_group_id)
        group = _add_group_link(group)
        return generate_json_response_with_pulp_encoder(group)
예제 #44
0
    def post(self, request, repo_group_id):
        """
        Unassociate repos that match criteria specified in the body to the specified repo group.
        Call is idempotent.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_group_id: matching repos are unassociated with this repo group
        :type  repo_group_id: str

        :return: Response containing a serialized list of unassociated repository names
        :rtype: django.http.HttpResponse
        """
        criteria = Criteria.from_client_input(request.body_as_json.get('criteria', {}))
        manager = managers_factory.repo_group_manager()
        manager.unassociate(repo_group_id, criteria)
        collection = RepoGroupModel.get_collection()
        group = collection.find_one({'id': repo_group_id})
        return generate_json_response(group['repo_ids'])
예제 #45
0
    def get(self, request, repo_group_id):
        """
        Retrieve the specified repo group.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_group_id: id of repo group to return
        :type  repo_group_id: str

        :return: Response containing serialized dict of the specified group
        :rtype: django.http.HttpResponse
        :raises pulp_exceptions.MissingResource: if repo_group_id is not found
        """
        collection = RepoGroupModel.get_collection()
        group = collection.find_one({'id': repo_group_id})
        if group is None:
            raise pulp_exceptions.MissingResource(repo_group=repo_group_id)
        group = _add_group_link(group)
        return generate_json_response_with_pulp_encoder(group)
예제 #46
0
    def get(self, request):
        """
        Return a serialized response containing a list of repo groups.

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

        :return: Response containing a serialized list of dicts, one for each repo group
        :rtype: django.http.HttpResponse
        """

        collection = RepoGroupModel.get_collection()
        cursor = collection.find({})
        groups = []
        for group in cursor:
            group['_href'] = reverse('repo_group_resource',
                                     kwargs={'repo_group_id': group['id']})
            groups.append(group)
        return generate_json_response_with_pulp_encoder(groups)
예제 #47
0
    def post(self, request, repo_group_id):
        """
        Unassociate repos that match criteria specified in the body to the specified repo group.
        Call is idempotent.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_group_id: matching repos are unassociated with this repo group
        :type  repo_group_id: str

        :return: Response containing a serialized list of unassociated repository names
        :rtype: django.http.HttpResponse
        """
        criteria = Criteria.from_client_input(
            request.body_as_json.get('criteria', {}))
        manager = managers_factory.repo_group_manager()
        manager.unassociate(repo_group_id, criteria)
        collection = RepoGroupModel.get_collection()
        group = collection.find_one({'id': repo_group_id})
        return generate_json_response(group['repo_ids'])
예제 #48
0
    def find_distributors(repo_group_id):
        """
        Returns all distributors on the given repo group, returning an empty
        list if none exist.

        @param repo_group_id: identifies the repo group
        @type  repo_group_id: str

        @return: list of SON representations of the group's distributors
        @rtype:  list

        @raise MissingResource: if the group does not exist
        """
        group = RepoGroup.get_collection().find_one({'id': repo_group_id})
        if group is None:
            raise MissingResource(repo_group=repo_group_id)

        spec = {'repo_group_id': repo_group_id}
        distributors = list(RepoGroupDistributor.get_collection().find(spec))
        return distributors
예제 #49
0
파일: distributor.py 프로젝트: bartwo/pulp
    def find_distributors(self, repo_group_id):
        """
        Returns all distributors on the given repo group, returning an empty
        list if none exist.

        @param repo_group_id: identifies the repo group
        @type  repo_group_id: str

        @return: list of SON representations of the group's distributors
        @rtype:  list

        @raise MissingResource: if the group does not exist
        """
        group = RepoGroup.get_collection().find_one({'id' : repo_group_id})
        if group is None:
            raise MissingResource(repo_group=repo_group_id)

        spec = {'repo_group_id' : repo_group_id}
        distributors = list(RepoGroupDistributor.get_collection().find(spec))
        return distributors
예제 #50
0
    def clean(self):
        super(RepoGroupPublishConduitTests, self).clean()

        RepoGroup.get_collection().remove()
        RepoGroupDistributor.get_collection().remove()
예제 #51
0
    def clean(self):
        super(RepoGroupPublishManagerTests, self).clean()

        RepoGroup.get_collection().remove()
        RepoGroupDistributor.get_collection().remove()
        RepoGroupPublishResult.get_collection().remove()
예제 #52
0
파일: test_cud.py 프로젝트: zjhuntin/pulp
 def tearDown(self):
     super(RepoGroupTests, self).tearDown()
     self.manager = None
     model.Repository.drop_collection()
     RepoGroup.get_collection().remove(safe=True)
     RepoGroupDistributor.get_collection().remove(safe=True)
예제 #53
0
파일: test_cud.py 프로젝트: zjhuntin/pulp
 def setUp(self):
     super(RepoGroupTests, self).setUp()
     self.collection = RepoGroup.get_collection()
     self.manager = cud.RepoGroupManager()
예제 #54
0
파일: test_cud.py 프로젝트: zjhuntin/pulp
 def test_constructor(self):
     try:
         RepoGroup('contructor_group')
     except:
         self.fail(traceback.format_exc())
 def clean(self):
     super(RepoGroupAssociationTests, self).clean()
     RepoGroup.get_collection().remove()
    def clean(self):
        super(PublishActionTests, self).clean()

        RepoGroup.get_collection().remove()
        RepoGroupDistributor.get_collection().remove()
예제 #57
0
 def tearDown(self):
     super(RepoGroupTests, self).tearDown()
     self.manager = None
     model.Repository.objects.delete()
     RepoGroup.get_collection().remove()
     RepoGroupDistributor.get_collection().remove()