Exemple #1
0
    def group(self, mapping_id):
        """Get the group attached to the mapping.

        :param mapping_id: UUID of the mapping to filter on.
        """
        hashmap = db_api.get_instance()
        try:
            group_db = hashmap.get_group_from_mapping(uuid=mapping_id)
            return group_models.Group(**group_db.export_model())
        except db_api.MappingHasNoGroup as e:
            pecan.abort(404, six.text_type(e))
Exemple #2
0
    def group(self, threshold_id):
        """Get the group attached to the threshold.

        :param threshold_id: UUID of the threshold to filter on.
        """
        hashmap = db_api.get_instance()
        try:
            group_db = hashmap.get_group_from_threshold(uuid=threshold_id)
            return group_models.Group(**group_db.export_model())
        except db_api.ThresholdHasNoGroup as e:
            pecan.abort(404, six.text_type(e))
Exemple #3
0
    def get_one(self, group_id):
        """Return a group.

        :param group_id: UUID of the group to filter on.
        """
        hashmap = db_api.get_instance()
        try:
            group_db = hashmap.get_group(uuid=group_id)
            return group_models.Group(**group_db.export_model())
        except db_api.NoSuchGroup as e:
            pecan.abort(404, six.text_type(e))
Exemple #4
0
    def get_all(self):
        """Get the group list

        :return: List of every group.
        """
        hashmap = db_api.get_instance()
        group_list = []
        groups_uuid_list = hashmap.list_groups()
        for group_uuid in groups_uuid_list:
            group_db = hashmap.get_group(uuid=group_uuid)
            group_list.append(group_models.Group(**group_db.export_model()))
        res = group_models.GroupCollection(groups=group_list)
        return res
Exemple #5
0
    def post(self, group_data):
        """Create a group.

        :param group_data: Informations about the group to create.
        """
        hashmap = db_api.get_instance()
        try:
            group_db = hashmap.create_group(group_data.name)
            pecan.response.location = pecan.request.path_url
            if pecan.response.location[-1] != '/':
                pecan.response.location += '/'
            pecan.response.location += group_db.group_id
            return group_models.Group(**group_db.export_model())
        except db_api.GroupAlreadyExists as e:
            pecan.abort(409, six.text_type(e))