示例#1
0
    def get(self, request, *args, **kwargs):
        """Return server pools by ids or dict"""

        if not kwargs.get('obj_ids'):
            obj_model = facade.get_pool_by_search(self.search)
            pools = obj_model['query_set']
            only_main_property = False
        else:
            pool_ids = kwargs['obj_ids'].split(';')
            pools = facade.get_pool_by_ids(pool_ids)
            only_main_property = True
            obj_model = None

        # serializer pools
        pool_serializer = serializers.PoolV3Serializer(pools,
                                                       many=True,
                                                       fields=self.fields,
                                                       include=self.include,
                                                       exclude=self.exclude,
                                                       kind=self.kind)

        # prepare serializer with customized properties
        response = render_to_json(pool_serializer,
                                  main_property='server_pools',
                                  obj_model=obj_model,
                                  request=request,
                                  only_main_property=only_main_property)

        return Response(response, status=status.HTTP_200_OK)
示例#2
0
    def get(self, request, *args, **kwargs):
        """Return server pools by ids or dict"""

        if not kwargs.get('obj_ids'):
            obj_model = facade.get_pool_by_search(self.search)
            pools = obj_model['query_set']
            only_main_property = False
        else:
            pool_ids = kwargs['obj_ids'].split(';')
            pools = facade.get_pool_by_ids(pool_ids)
            only_main_property = True
            obj_model = None

        # serializer pools
        pool_serializer = serializers.PoolV3Serializer(
            pools,
            many=True,
            fields=self.fields,
            include=self.include,
            exclude=self.exclude,
            kind=self.kind
        )

        # prepare serializer with customized properties
        response = render_to_json(
            pool_serializer,
            main_property='server_pools',
            obj_model=obj_model,
            request=request,
            only_main_property=only_main_property
        )

        return Response(response, status=status.HTTP_200_OK)
示例#3
0
    def get(self, request, *args, **kwargs):
        """
        Return server pools by ids or dict
        """
        try:
            if not kwargs.get('pool_ids'):
                obj_model = facade.get_pool_by_search(self.search)
                pools = obj_model['query_set']
                only_main_property = False
            else:
                pool_ids = kwargs['pool_ids'].split(';')
                pools = facade.get_pool_by_ids(pool_ids)
                only_main_property = True
                obj_model = None

            self.include = (
                'servicedownaction__details',
                'environment__details',
                'groups_permissions__details',
            )

            # serializer pools
            pool_serializer = serializers.PoolV3Serializer(
                pools,
                many=True,
                fields=self.fields,
                include=self.include,
                exclude=self.exclude,
                kind=self.kind)

            # prepare serializer with customized properties
            response = render_to_json(pool_serializer,
                                      main_property='server_pools',
                                      obj_model=obj_model,
                                      request=request,
                                      only_main_property=only_main_property)

            return CustomResponse(response,
                                  status=status.HTTP_200_OK,
                                  request=request)

        except Exception, exception:
            log.exception(exception)
            raise rest_exceptions.NetworkAPIException(exception)