Example #1
0
class HashMapConfigController(rating.RatingRestControllerBase):
    """Controller exposing all management sub controllers."""

    _custom_actions = {'types': ['GET']}

    services = service_api.HashMapServicesController()
    fields = field_api.HashMapFieldsController()
    groups = group_api.HashMapGroupsController()
    mappings = mapping_api.HashMapMappingsController()
    thresholds = threshold_api.HashMapThresholdsController()

    @wsme_pecan.wsexpose([wtypes.text])
    def get_types(self):
        """Return the list of every mapping type available.

        """
        return mapping_models.MAP_TYPE.values
Example #2
0
class HashMapServicesController(rating.RatingRestControllerBase):
    """Controller responsible of services management.

    """

    fields = field_api.HashMapFieldsController()
    mappings = mapping_api.HashMapMappingsController()

    @wsme_pecan.wsexpose(service_models.ServiceCollection)
    def get_all(self):
        """Get the service list

        :return: List of every services.
        """
        hashmap = db_api.get_instance()
        service_list = []
        services_uuid_list = hashmap.list_services()
        for service_uuid in services_uuid_list:
            service_db = hashmap.get_service(uuid=service_uuid)
            service_list.append(service_models.Service(
                **service_db.export_model()))
        res = service_models.ServiceCollection(services=service_list)
        return res

    @wsme_pecan.wsexpose(service_models.Service, ck_types.UuidType())
    def get_one(self, service_id):
        """Return a service.

        :param service_id: UUID of the service to filter on.
        """
        hashmap = db_api.get_instance()
        try:
            service_db = hashmap.get_service(uuid=service_id)
            return service_models.Service(**service_db.export_model())
        except db_api.NoSuchService as e:
            pecan.abort(404, e.args[0])

    @wsme_pecan.wsexpose(service_models.Service,
                         body=service_models.Service,
                         status_code=201)
    def post(self, service_data):
        """Create hashmap service.

        :param service_data: Informations about the service to create.
        """
        hashmap = db_api.get_instance()
        try:
            service_db = hashmap.create_service(service_data.name)
            pecan.response.location = pecan.request.path_url
            if pecan.response.location[-1] != '/':
                pecan.response.location += '/'
            pecan.response.location += service_db.service_id
            return service_models.Service(
                **service_db.export_model())
        except db_api.ServiceAlreadyExists as e:
            pecan.abort(409, e.args[0])

    @wsme_pecan.wsexpose(None, ck_types.UuidType(), status_code=204)
    def delete(self, service_id):
        """Delete the service and all the sub keys recursively.

        :param service_id: UUID of the service to delete.
        """
        hashmap = db_api.get_instance()
        try:
            hashmap.delete_service(uuid=service_id)
        except db_api.NoSuchService as e:
            pecan.abort(404, e.args[0])