Exemplo n.º 1
0
    def post(self, collector, service):
        """Create a service to collector mapping.

        :param collector: Name of the collector to apply mapping on.
        :param service: Name of the service to apply mapping on.
        """
        policy.authorize(pecan.request.context, 'collector:manage_mapping', {})
        new_mapping = self._db.set_mapping(service, collector)
        return collector_models.ServiceToCollectorMapping(
            service=new_mapping.service, collector=new_mapping.collector)
Exemplo n.º 2
0
    def get_one(self, service):
        """Return a service to collector mapping.

        :param service: Name of the service to filter on.
        """
        policy.authorize(pecan.request.context, 'collector:get_mapping', {})
        try:
            mapping = self._db.get_mapping(service)
            return collector_models.ServiceToCollectorMapping(
                **mapping.as_dict())
        except db_api.NoSuchMapping as e:
            pecan.abort(404, six.text_type(e))
Exemplo n.º 3
0
    def get_all(self, collector=None):
        """Return the list of every services mapped to a collector.

        :param collector: Filter on the collector name.
        :return: Service to collector mappings collection.
        """
        policy.enforce(pecan.request.context, 'collector:list_mappings', {})
        mappings = [collector_models.ServiceToCollectorMapping(
            **mapping.as_dict())
            for mapping in self._db.list_mappings(collector)]
        return collector_models.ServiceToCollectorMappingCollection(
            mappings=mappings)
Exemplo n.º 4
0
    def get_one(self, service):
        """Return a service to collector mapping.

        :param service: Name of the service to filter on.
        """
        LOG.warning("Collector mappings are deprecated and shouldn't be used.")
        policy.authorize(pecan.request.context, 'collector:get_mapping', {})
        try:
            mapping = self._db.get_mapping(service)
            return collector_models.ServiceToCollectorMapping(
                **mapping.as_dict())
        except db_api.NoSuchMapping as e:
            pecan.abort(404, e.args[0])
Exemplo n.º 5
0
    def get_all(self, collector=None):
        """Return the list of every services mapped to a collector.

        :param collector: Filter on the collector name.
        :return: Service to collector mappings collection.
        """
        LOG.warning("Collector mappings are deprecated and shouldn't be used.")
        policy.authorize(pecan.request.context, 'collector:list_mappings', {})
        mappings = [collector_models.ServiceToCollectorMapping(
            **mapping.as_dict())
            for mapping in self._db.list_mappings(collector)]
        return collector_models.ServiceToCollectorMappingCollection(
            mappings=mappings)