Пример #1
0
    def clean(self):
        cleaned_data = super(ResizeForm, self).clean()
        new_size = cleaned_data.get('new_size')
        orig_size = self.initial['orig_size']

        if new_size == orig_size:
            message = _("New size must be different than the existing size")
            self._errors["new_size"] = self.error_class([message])
            return cleaned_data

        if new_size <= 0:
            message = _("New size should not be less than or equal to zero")
            self._errors["new_size"] = self.error_class([message])
            return cleaned_data

        usages = manila.tenant_absolute_limits(self.request)
        availableGB = (usages['maxTotalShareGigabytes'] -
                       usages['totalShareGigabytesUsed'])
        if availableGB < (new_size - orig_size):
            message = _('Share cannot be extended to %(req)iGiB as '
                        'you only have %(avail)iGiB of your quota '
                        'available.')
            params = {'req': new_size, 'avail': availableGB + orig_size}
            self._errors["new_size"] = self.error_class([message % params])
        return cleaned_data
Пример #2
0
 def get_context_data(self, **kwargs):
     context = super(CreateView, self).get_context_data(**kwargs)
     try:
         context['usages'] = manila.tenant_absolute_limits(self.request)
     except Exception:
         exceptions.handle(self.request)
     return context
Пример #3
0
    def allowed(self, request, share=None):
        usages = manila.tenant_absolute_limits(request)
        snapshots_allowed = (usages['maxTotalShareSnapshots'] >
                             usages['totalShareSnapshotsUsed']
                             and usages['maxTotalSnapshotGigabytes'] >
                             usages['totalSnapshotGigabytesUsed'])

        if not snapshots_allowed:
            if "disabled" not in self.classes:
                self.classes = [c for c in self.classes] + ['disabled']
                self.verbose_name = format_lazy(
                    '{verbose_name} {quota_exceeded}',
                    verbose_name=self.verbose_name,
                    quota_exceeded=_("(Quota exceeded)"))
        else:
            self.verbose_name = _("Create Share Snapshot")
            classes = [c for c in self.classes if c != "disabled"]
            self.classes = classes

        # NOTE(vponomaryov): Disable form with creation of a snapshot for
        # shares that has attr 'snapshot_support' equal to False.
        if hasattr(share, 'snapshot_support'):
            snapshot_support = share.snapshot_support
        else:
            # NOTE(vponomaryov): Allow creation of a snapshot for shares that
            # do not have such attr for backward compatibility.
            snapshot_support = True
        return share.status in ("available", "in-use") and snapshot_support
Пример #4
0
    def allowed(self, request, share=None):
        usages = manila.tenant_absolute_limits(request)
        snapshots_allowed = (usages['maxTotalShareSnapshots'] >
                             usages['totalShareSnapshotsUsed'] and
                             usages['maxTotalSnapshotGigabytes'] >
                             usages['totalSnapshotGigabytesUsed'])

        if not snapshots_allowed:
            if "disabled" not in self.classes:
                self.classes = [c for c in self.classes] + ['disabled']
                self.verbose_name = string_concat(
                    self.verbose_name, ' ', _("(Quota exceeded)"))
        else:
            self.verbose_name = _("Create Share Snapshot")
            classes = [c for c in self.classes if c != "disabled"]
            self.classes = classes

        # NOTE(vponomaryov): Disable form with creation of a snapshot for
        # shares that has attr 'snapshot_support' equal to False.
        if hasattr(share, 'snapshot_support'):
            snapshot_support = share.snapshot_support
        else:
            # NOTE(vponomaryov): Allow creation of a snapshot for shares that
            # do not have such attr for backward compatibility.
            snapshot_support = True
        return share.status in ("available", "in-use") and snapshot_support
Пример #5
0
 def get_context_data(self, **kwargs):
     context = super(CreateView, self).get_context_data(**kwargs)
     try:
         context['usages'] = manila.tenant_absolute_limits(self.request)
     except Exception:
         exceptions.handle(self.request)
     return context
Пример #6
0
 def get_context_data(self, **kwargs):
     context = super(self.__class__, self).get_context_data(**kwargs)
     context['share_id'] = self.kwargs['share_id']
     try:
         context['usages'] = manila.tenant_absolute_limits(self.request)
     except Exception:
         exceptions.handle(self.request, _('Unable to retrieve quotas.'))
     return context
Пример #7
0
 def get_context_data(self, **kwargs):
     context = super(self.__class__, self).get_context_data(**kwargs)
     context['share_id'] = self.kwargs['share_id']
     try:
         context['usages'] = manila.tenant_absolute_limits(self.request)
     except Exception:
         exceptions.handle(self.request, _('Unable to retrieve quotas.'))
     return context
Пример #8
0
 def get_manila_limits(self):
     """Get share limits if manila is enabled."""
     if not base.is_service_enabled(self.request, 'share'):
         return
     try:
         self.limits.update(manila.tenant_absolute_limits(self.request))
     except Exception:
         msg = _("Unable to retrieve share limit information.")
         horizon.exceptions.handle(self.request, msg)
     return
Пример #9
0
 def get_manila_limits(self):
     """Get share limits if manila is enabled."""
     if not base.is_service_enabled(self.request, 'share'):
         return
     try:
         self.limits.update(manila.tenant_absolute_limits(self.request))
     except Exception:
         msg = _("Unable to retrieve share limit information.")
         horizon.exceptions.handle(self.request, msg)
     return
Пример #10
0
    def get_context_data(self, **kwargs):
        context = super(ExtendView, self).get_context_data(**kwargs)
        args = (self.get_object().id, )
        context['submit_url'] = reverse(self.submit_url, args=args)
        try:
            context['usages'] = manila.tenant_absolute_limits(self.request)
            context['usages']['totalShareGigabytesUsed'] -= int(
                self.get_object().size)
        except Exception:
            exceptions.handle(self.request)

        return context
Пример #11
0
    def get_context_data(self, **kwargs):
        context = super(ExtendView, self).get_context_data(**kwargs)
        args = (self.get_object().id,)
        context['submit_url'] = reverse(self.submit_url, args=args)
        try:
            context['usages'] = manila.tenant_absolute_limits(self.request)
            context['usages']['totalShareGigabytesUsed'] -= int(
                self.get_object().size)
        except Exception:
            exceptions.handle(self.request)

        return context
Пример #12
0
    def allowed(self, request, share=None):
        usages = manila.tenant_absolute_limits(request)
        shares_allowed = (usages['maxTotalShares'] >
                          usages['totalSharesUsed'] and
                          usages['maxTotalShareGigabytes'] >
                          usages['totalShareGigabytesUsed'])

        if not shares_allowed:
            if "disabled" not in self.classes:
                self.classes = [c for c in self.classes] + ['disabled']
                self.verbose_name = string_concat(self.verbose_name, ' ',
                                                  _("(Quota exceeded)"))
        else:
            self.verbose_name = _("Create Share")
            classes = [c for c in self.classes if c != "disabled"]
            self.classes = classes

        return True
Пример #13
0
def tenant_limit_usages(f, request):

    limits = f(request)

    if base.is_service_enabled(request, 'share'):
        try:
            limits.update(manila.tenant_absolute_limits(request))
            shares = manila.share_list(request)
            snapshots = manila.share_snapshot_list(request)
            total_s_size = sum([getattr(share, 'size', 0) for share in shares])
            total_ss_size = sum([getattr(ss, 'size', 0) for ss in snapshots])
            limits['totalGigabytesUsed'] = total_s_size + total_ss_size
            limits['totalSharesUsed'] = len(shares)
            limits['totalSnapshotsUsed'] = len(snapshots)
        except Exception:
            msg = _("Unable to retrieve share limit information.")
            horizon.exceptions.handle(request, msg)

    return limits
Пример #14
0
    def allowed(self, request, share=None):
        usages = manila.tenant_absolute_limits(request)
        shares_allowed = (usages['maxTotalShares'] > usages['totalSharesUsed']
                          and usages['maxTotalShareGigabytes'] >
                          usages['totalShareGigabytesUsed'])

        if not shares_allowed:
            if "disabled" not in self.classes:
                self.classes = [c for c in self.classes] + ['disabled']
                self.verbose_name = format_lazy(
                    '{verbose_name} {quota_exceeded}',
                    verbose_name=self.verbose_name,
                    quota_exceeded=_("(Quota exceeded)"))
        else:
            self.verbose_name = _("Create Share")
            classes = [c for c in self.classes if c != "disabled"]
            self.classes = classes

        return True
Пример #15
0
def tenant_limit_usages(f, request):

    limits = f(request)

    if base.is_service_enabled(request, 'share'):
        try:
            limits.update(manila.tenant_absolute_limits(request))
            shares = manila.share_list(request)
            snapshots = manila.share_snapshot_list(request)
            total_s_size = sum([getattr(share, 'size', 0) for share in shares])
            total_ss_size = sum([getattr(ss, 'size', 0) for ss in snapshots])
            limits['totalGigabytesUsed'] = total_s_size + total_ss_size
            limits['totalSharesUsed'] = len(shares)
            limits['totalSnapshotsUsed'] = len(snapshots)
        except Exception:
            msg = _("Unable to retrieve share limit information.")
            horizon.exceptions.handle(request, msg)

    return limits
Пример #16
0
    def clean(self):
        cleaned_data = super(ExtendForm, self).clean()
        new_size = cleaned_data.get('new_size')
        orig_size = self.initial['orig_size']

        if new_size <= orig_size:
            message = _("New size must be greater than current size.")
            self._errors["new_size"] = self.error_class([message])
            return cleaned_data

        usages = manila.tenant_absolute_limits(self.request)
        availableGB = (usages['maxTotalShareGigabytes'] -
                       usages['totalShareGigabytesUsed'])
        if availableGB < (new_size - orig_size):
            message = _('Share cannot be extended to %(req)iGiB as '
                        'you only have %(avail)iGiB of your quota '
                        'available.')
            params = {'req': new_size, 'avail': availableGB + orig_size}
            self._errors["new_size"] = self.error_class([message % params])
        return cleaned_data