¡@

Home 

OpenStack Study: quota_utils.py

OpenStack Index

**** CubicPower OpenStack Study ****

def get_volume_type_reservation(ctxt, volume, type_id):

    # Reserve quotas for the given volume type

    try:

        reserve_opts = {'volumes': 1, 'gigabytes': volume['size']}

        QUOTAS.add_volume_type_opts(ctxt,

                                    reserve_opts,

                                    type_id)

        reservations = QUOTAS.reserve(ctxt, **reserve_opts)

    except exception.OverQuota as e:

        overs = e.kwargs['overs']

        usages = e.kwargs['usages']

        quotas = e.kwargs['quotas']

        def _consumed(name):

            return (usages[name]['reserved'] + usages[name]['in_use'])

        for over in overs:

            if 'gigabytes' in over:

                s_size = volume['size']

                d_quota = quotas[over]

                d_consumed = _consumed(over)

                msg = _("Quota exceeded for %(s_pid)s, tried to create "

                        "%(s_size)sG volume - (%(d_consumed)dG of "

                        "%(d_quota)dG already consumed)")

                LOG.warn(msg % {'s_pid': ctxt.project_id,

                                's_size': s_size,

                                'd_consumed': d_consumed,

                                'd_quota': d_quota})

                raise exception.VolumeSizeExceedsAvailableQuota(

                    requested=s_size, quota=d_quota, consumed=d_consumed)

            elif 'volumes' in over:

                msg = _("Quota exceeded for %(s_pid)s, tried to create "

                        "volume (%(d_consumed)d volumes "

                        "already consumed)")

                LOG.warn(msg % {'s_pid': ctxt.project_id,

                                'd_consumed': _consumed(over)})

                raise exception.VolumeLimitExceeded(

                    allowed=quotas[over])

    return reservations