Esempio n. 1
0
    def update_status(self, request, tenant_id, parameters):

        try:
            usages = tenant_quota_usages(request)
            usages_update = False
            if usages is not None:
                if usages_attribute(usages['gigabytes']):
                    usages_update = True
            return usages_update
        except Exception, exc:
            LOG.info('Error is :%s' % exc)
            return False
Esempio n. 2
0
    def update_status(self, request, tenant_id ,parameters):

        try:
            usages = tenant_quota_usages(request)
            usages_update = False
            if usages is not None:
                if usages_attribute(usages['gigabytes']):
                    usages_update = True
            return usages_update
        except Exception, exc:
            LOG.info('Error is :%s' % exc)
            return False
Esempio n. 3
0
 def clean(self):
     data = super(forms.Form, self).clean()
     tenant_id = data.get('tenant_id', None)
     if 'flavor' in data:
         try:
             switch_tenants(self.request, tenant_id)
             usages = quotas.tenant_quota_usages(self.request)
         except Exception, e:
             LOG.error('can not get the usage info of tenant %s,%s' %
                       (tenant_id, e))
             return data
         if usages['instances']['used'] >= usages['instances']['quota']:
             msg = _(
                 "Exceed instances quotas of tenant,can not create instance!")
             raise ValidationError(msg)
Esempio n. 4
0
def fresh_progress_bar(request):
    tenant_id = None
    if request.GET.has_key('tenant_id'):
        tenant_id = request.GET['tenant_id']

    if tenant_id is not None:
        switch_tenants(request, tenant_id)

    try:
        usages = quotas.tenant_quota_usages(request)
    except Unauthorized:
        raise
    except Exception, ex:
        LOG.error("usages not found ,the error is %s" % ex)
        usages = None
Esempio n. 5
0
    def clean(self):
        data = super(forms.Form, self).clean()
        tenant_id = data.get('img_tenant_id', None)
        name = data.get('name', None)
        if len(name) < 2:
            raise ValidationError(_("Image Name value between 2 and 10."))
        elif len(name) >10:
            raise ValidationError(_("Image Name value between 2 and 10."))
        check_data(data)

        try:
            usages = quotas.tenant_quota_usages(self.request)
        except Exception, e:
            LOG.error(
                'can not get the usage info of tenant %s,%s' % (tenant_id, e))
            return data
Esempio n. 6
0
    def clean(self):
        data = super(forms.Form, self).clean()
        tenant_id = data.get('img_tenant_id', None)
        name = data.get('name', None)
        if len(name) < 2:
            raise ValidationError(_("Image Name value between 2 and 10."))
        elif len(name) > 10:
            raise ValidationError(_("Image Name value between 2 and 10."))
        check_data(data)

        try:
            usages = quotas.tenant_quota_usages(self.request)
        except Exception, e:
            LOG.error('can not get the usage info of tenant %s,%s' %
                      (tenant_id, e))
            return data
Esempio n. 7
0
 def clean(self):
     data = super(forms.Form, self).clean()
     tenant_id = data.get('tenant_id', None)
     if 'flavor' in data:
         try:
             switch_tenants(self.request, tenant_id)
             usages = quotas.tenant_quota_usages(self.request)
         except Exception, e:
             LOG.error('can not get the usage info of tenant %s,%s' %
                       (tenant_id, e))
             return data
         if usages['instances']['used'] >= usages['instances']['quota']:
             msg = _(
                 "Exceed instances quotas of tenant,can not create instance!"
             )
             raise ValidationError(msg)
Esempio n. 8
0
 def update_status(self, request, tenant_id ,parameters):
     try:
         usages = tenant_quota_usages(request)
         usages_update = ''
         if usages is not None:
             if usages_attribute(usages['cores']):
                 usages_update += 'cores'
             if usages_attribute(usages['instances']):
                 usages_update += 'instances'
             if usages_attribute(usages['volumes']):
                 usages_update += 'volumes'
             if usages_attribute(usages['gigabytes']):
                 usages_update += 'gigabytes'
             if usages_attribute(usages['ram']):
                 usages_update += 'ram'
             if usages_attribute(usages['floating_ips']):
                 usages_update += 'floating_ips'
         if len(usages_update) > 0:
             return True
     except Exception, exc:
         LOG.info('Error is :%s' % exc)
         return False
Esempio n. 9
0
 def update_status(self, request, tenant_id, parameters):
     try:
         usages = tenant_quota_usages(request)
         usages_update = ''
         if usages is not None:
             if usages_attribute(usages['cores']):
                 usages_update += 'cores'
             if usages_attribute(usages['instances']):
                 usages_update += 'instances'
             if usages_attribute(usages['volumes']):
                 usages_update += 'volumes'
             if usages_attribute(usages['gigabytes']):
                 usages_update += 'gigabytes'
             if usages_attribute(usages['ram']):
                 usages_update += 'ram'
             if usages_attribute(usages['floating_ips']):
                 usages_update += 'floating_ips'
         if len(usages_update) > 0:
             return True
     except Exception, exc:
         LOG.info('Error is :%s' % exc)
         return False
Esempio n. 10
0
                    data['min_disk']):
                    msg = 'Instance flavor disk less-than Image min disk!'
                    raise ValidationError(_(msg))
                if flavor_id is not None and flavor_id.ram < int(
                    data['min_ram']):
                    msg = 'Instance flavor ram less-than Image min ram!'
                    raise ValidationError(_(msg))
            except Unauthorized:
                raise
            except Exception, e:
                LOG.error('can not get the usage info of tenant %s,%s' %
                          (tenant_id, e))
                return data
        try:
            switch_tenants(self.request, tenant_id)
            usages = quotas.tenant_quota_usages(self.request)
        except Exception, e:
            LOG.error(
                'can not get the usage info of tenant %s,%s' % (tenant_id, e))
            return data
        if usages['instances']['used'] >= usages['instances']['quota']:
            msg = _(
                "Exceed instances quotas of tenant,can not create instance!")
            raise ValidationError(msg)

        return data

#class CreateImageAndLaunchForm(forms.Form):
#    name = forms.CharField(max_length=50, label=_("Name"), required=False)
#    u_uid = forms.CharField(max_length=100, label=_("Uuid"))
#    image_file = forms.FileField(label="Image file", required=False)
Esempio n. 11
0
                                  getattr(request.user, 'is_superuser', True))
    except Unauthorized:
        raise
    except Exception, ex:
        LOG.error('tenants not found,the error is %s' % ex)
        tenants = []

    tenants_dic = SortedDict([(tenant.id, getattr(tenant, "name"))
                              for tenant in tenants if tenant.enabled])

    current_tenant = getattr(request.user, 'tenant_id', None)

    try:
        if tenant_id != 'tenant':
            if switch_tenants(request, tenant_id):
                usages = quotas.tenant_quota_usages(request)
        else:
            usages = quotas.tenant_quota_usages(request)
    except Unauthorized:
        raise
    except Exception, ex:
        LOG.error("usages not found ,the error is %s" % ex)
        usages = None

    snapshots = []
    if snapshot_id == vu.uuid:
        snapshot = None
        snapshots = []
        try:
            if switch_tenants(request, current_tenant):
                snapshots = api.volume_snapshot_list(request)
Esempio n. 12
0
                        data['min_disk']):
                    msg = 'Instance flavor disk less-than Image min disk!'
                    raise ValidationError(_(msg))
                if flavor_id is not None and flavor_id.ram < int(
                        data['min_ram']):
                    msg = 'Instance flavor ram less-than Image min ram!'
                    raise ValidationError(_(msg))
            except Unauthorized:
                raise
            except Exception, e:
                LOG.error('can not get the usage info of tenant %s,%s' %
                          (tenant_id, e))
                return data
        try:
            switch_tenants(self.request, tenant_id)
            usages = quotas.tenant_quota_usages(self.request)
        except Exception, e:
            LOG.error('can not get the usage info of tenant %s,%s' %
                      (tenant_id, e))
            return data
        if usages['instances']['used'] >= usages['instances']['quota']:
            msg = _(
                "Exceed instances quotas of tenant,can not create instance!")
            raise ValidationError(msg)

        return data


#class CreateImageAndLaunchForm(forms.Form):
#    name = forms.CharField(max_length=50, label=_("Name"), required=False)
#    u_uid = forms.CharField(max_length=100, label=_("Uuid"))