Exemplo n.º 1
0
    def items_history(self, request, uuid):
        """ Get host items historical values.

        Request should specify datetime points and items.
        There are two ways to define datetime points for historical data.

        1. Send *?point=<timestamp>* parameter that can list.
           Response will contain historical data for each given point in the same order.
        2. Send *?start=<timestamp>*, *?end=<timestamp>*, *?points_count=<integer>* parameters.
           Result will contain <points_count> points from <start> to <end>.

        Also you should specify one or more name of host template items, for example 'openstack.instance.cpu_util'

        Response is list of datapoints, each of which is dictionary with following fields:
         - 'point' - timestamp;
         - 'value' - values are converted from bytes to megabytes, if possible;
         - 'item' - key of host template item;
         - 'item_name' - name of host template item.
        """
        host = self.get_object()
        if host.state != models.Host.States.OK:
            raise IncorrectStateException(
                'Host has to be OK to get items history.')
        stats = self._get_stats(request, [host])
        return Response(stats, status=status.HTTP_200_OK)
Exemplo n.º 2
0
def exception_handler(exc, context):
    if isinstance(exc, ProtectedError):
        dependent_meta = exc.protected_objects.model._meta

        try:
            # This exception should be raised from a viewset
            instance_meta = context['view'].get_queryset().model._meta
        except (AttributeError, KeyError):
            # Fallback, when instance being deleted cannot be inferred
            instance_name = 'object'
        else:
            instance_name = force_text(instance_meta.verbose_name)

        detail = _(
            'Cannot delete {instance_name} with existing {dependant_objects}'
        ).format(
            instance_name=instance_name,
            dependant_objects=force_text(dependent_meta.verbose_name_plural),
        )

        # We substitute exception here to get consistent representation
        # for both ProtectError and manually raised IncorrectStateException
        exc = IncorrectStateException(detail=detail)

    return rf_exception_handler(exc, context)
Exemplo n.º 3
0
    def set_created(self):
        """
        Change state from pending to billed
        """
        if self.state != self.States.PENDING:
            raise IncorrectStateException(_('Invoice must be in pending state.'))

        self.state = self.States.CREATED
        self.invoice_date = timezone.now().date()
        self.save(update_fields=['state', 'invoice_date'])
Exemplo n.º 4
0
    def set_created(self):
        """
        Change state from pending to billed
        """
        if self.state != self.States.PENDING:
            raise IncorrectStateException(
                _('Invoice must be in pending state.'))

        if self.customer.paymentprofile_set.filter(
                is_active=True, payment_type=PaymentType.FIXED_PRICE).count():
            self.state = self.States.PAID
        else:
            self.state = self.States.CREATED

        self.invoice_date = timezone.now().date()
        self.save(update_fields=['state', 'invoice_date'])