Exemple #1
0
def get_tenant_quota_data(request, disabled_quotas=None, tenant_id=None):
    quotasets = []
    if not tenant_id:
        tenant_id = request.user.tenant_id
    if disabled_quotas is None:
        disabled_quotas = get_disabled_quotas(request)

    if NOVA_QUOTA_FIELDS - disabled_quotas:
        quotasets.append(nova.tenant_quota_get(request, tenant_id))

    if CINDER_QUOTA_FIELDS - disabled_quotas:
        try:
            quotasets.append(cinder.tenant_quota_get(request, tenant_id))
        except cinder.cinder_exception.ClientException:
            disabled_quotas.update(CINDER_QUOTA_FIELDS)
            msg = _("Unable to retrieve volume limit information.")
            exceptions.handle(request, msg)

    if NEUTRON_QUOTA_FIELDS - disabled_quotas:
        quotasets.append(neutron.tenant_quota_get(request, tenant_id))

    qs = base.QuotaSet()
    for quota in itertools.chain(*quotasets):
        if quota.name not in disabled_quotas and quota.name in QUOTA_FIELDS:
            qs[quota.name] = quota.limit
    return qs
Exemple #2
0
def get_default_quota_data(request, disabled_quotas=None, tenant_id=None):
    quotasets = []
    if not tenant_id:
        tenant_id = request.user.tenant_id
    if disabled_quotas is None:
        disabled_quotas = get_disabled_quotas(request)

    if NOVA_QUOTA_FIELDS - disabled_quotas:
        quotasets.append(nova.default_quota_get(request, tenant_id))

    if CINDER_QUOTA_FIELDS - disabled_quotas:
        try:
            quotasets.append(cinder.default_quota_get(request, tenant_id))
        except cinder.cinder_exception.ClientException:
            disabled_quotas.update(CINDER_QUOTA_FIELDS)
            msg = _("Unable to retrieve volume quota information.")
            exceptions.handle(request, msg)

    if NEUTRON_QUOTA_FIELDS - disabled_quotas:
        # TODO(jpichon): There is no API to access the Neutron default quotas
        # (LP#1204956). For now, use the values from the current project.
        try:
            quotasets.append(
                neutron.tenant_quota_get(request, tenant_id=tenant_id))
        except Exception:
            disabled_quotas.update(NEUTRON_QUOTA_FIELDS)
            msg = _('Unable to retrieve Neutron quota information.')
            exceptions.handle(request, msg)

    qs = base.QuotaSet()
    for quota in itertools.chain(*quotasets):
        if quota.name not in disabled_quotas and quota.name in QUOTA_FIELDS:
            qs[quota.name] = quota.limit
    return qs
Exemple #3
0
def get_tenant_quota_data(request, disabled_quotas=None, tenant_id=None):
    qs = _get_quota_data(request,
                         tenant_mode=True,
                         disabled_quotas=disabled_quotas,
                         tenant_id=tenant_id)

    if not disabled_quotas:
        return qs

    # Check if neutron is enabled by looking for network
    if 'network' not in disabled_quotas:
        # mj - another quota hack. This is fixed properly in Queens.
        #tenant_id = tenant_id or request.user.tenant_id
        neutron_quotas = neutron.tenant_quota_get(request, tenant_id)
    if 'floating_ips' in disabled_quotas:
        # Neutron with quota extension disabled
        if 'floatingip' in disabled_quotas:
            qs.add(base.QuotaSet({'floating_ips': -1}))
        # Neutron with quota extension enabled
        else:
            # Rename floatingip to floating_ips since that's how it's
            # expected in some places (e.g. Security & Access' Floating IPs)
            fips_quota = neutron_quotas.get('floatingip').limit
            qs.add(base.QuotaSet({'floating_ips': fips_quota}))
    if 'security_groups' in disabled_quotas:
        if 'security_group' in disabled_quotas:
            qs.add(base.QuotaSet({'security_groups': -1}))
        # Neutron with quota extension enabled
        else:
            # Rename security_group to security_groups since that's how it's
            # expected in some places (e.g. Security & Access' Security Groups)
            sec_quota = neutron_quotas.get('security_group').limit
            qs.add(base.QuotaSet({'security_groups': sec_quota}))
    if 'network' in disabled_quotas:
        for item in qs.items:
            if item.name == 'networks':
                qs.items.remove(item)
                break
    else:
        net_quota = neutron_quotas.get('network').limit
        qs.add(base.QuotaSet({'networks': net_quota}))
    if 'subnet' in disabled_quotas:
        for item in qs.items:
            if item.name == 'subnets':
                qs.items.remove(item)
                break
    else:
        net_quota = neutron_quotas.get('subnet').limit
        qs.add(base.QuotaSet({'subnets': net_quota}))
    if 'router' in disabled_quotas:
        for item in qs.items:
            if item.name == 'routers':
                qs.items.remove(item)
                break
    else:
        router_quota = neutron_quotas.get('router').limit
        qs.add(base.QuotaSet({'routers': router_quota}))

    return qs
Exemple #4
0
def _get_neutron_quota_data(request, qs, disabled_quotas, tenant_id):
    tenant_id = tenant_id or request.user.tenant_id
    neutron_quotas = neutron.tenant_quota_get(request, tenant_id)

    for quota_name in NEUTRON_QUOTA_FIELDS:
        if quota_name not in disabled_quotas:
            quota_data = neutron_quotas.get(quota_name).limit
            qs.add(base.QuotaSet({quota_name: quota_data}))

    return qs
Exemple #5
0
def _get_neutron_quota_data(request, qs, disabled_quotas, tenant_id):
    tenant_id = tenant_id or request.user.tenant_id
    neutron_quotas = neutron.tenant_quota_get(request, tenant_id)

    for quota_name in NEUTRON_QUOTA_FIELDS:
        if quota_name not in disabled_quotas:
            quota_data = neutron_quotas.get(quota_name).limit
            qs.add(base.QuotaSet({quota_name: quota_data}))

    return qs
Exemple #6
0
def get_tenant_quota_data(request, disabled_quotas=None, tenant_id=None):
    qs = _get_quota_data(request,
                         tenant_mode=True,
                         disabled_quotas=disabled_quotas,
                         tenant_id=tenant_id)

    # TODO(jpichon): There is no API to get the default system quotas
    # in Neutron (cf. LP#1204956), so for now handle tenant quotas here.
    # This should be handled in _get_quota_data() eventually.

    # TODO(amotoki): Purge this tricky usage.
    # openstack_dashboard/dashboards/identity/projects/views.py
    # calls get_tenant_quota_data directly and it expects
    # neutron data is not returned.
    if not disabled_quotas:
        return qs

    # Check if neutron is enabled by looking for network
    if not (NEUTRON_QUOTA_FIELDS - disabled_quotas):
        return qs

    tenant_id = tenant_id or request.user.tenant_id
    neutron_quotas = neutron.tenant_quota_get(request, tenant_id)

    if 'floating_ips' in disabled_quotas:
        if 'floatingip' not in disabled_quotas:
            # Rename floatingip to floating_ips since that's how it's
            # expected in some places (e.g. Security & Access' Floating IPs)
            fips_quota = neutron_quotas.get('floatingip').limit
            qs.add(base.QuotaSet({'floating_ips': fips_quota}))

    if 'security_groups' in disabled_quotas:
        if 'security_group' not in disabled_quotas:
            # Rename security_group to security_groups since that's how it's
            # expected in some places (e.g. Security & Access' Security Groups)
            sec_quota = neutron_quotas.get('security_group').limit
            qs.add(base.QuotaSet({'security_groups': sec_quota}))

    if 'network' not in disabled_quotas:
        net_quota = neutron_quotas.get('network').limit
        qs.add(base.QuotaSet({'networks': net_quota}))

    if 'subnet' not in disabled_quotas:
        net_quota = neutron_quotas.get('subnet').limit
        qs.add(base.QuotaSet({'subnets': net_quota}))

    if 'port' not in disabled_quotas:
        net_quota = neutron_quotas.get('port').limit
        qs.add(base.QuotaSet({'ports': net_quota}))

    if 'router' not in disabled_quotas:
        router_quota = neutron_quotas.get('router').limit
        qs.add(base.QuotaSet({'routers': router_quota}))

    return qs
Exemple #7
0
def get_tenant_quota_data(request, disabled_quotas=None, tenant_id=None):
    qs = _get_quota_data(request,
                         "tenant_quota_get",
                         disabled_quotas=disabled_quotas,
                         tenant_id=tenant_id)

    # TODO(jpichon): There is no API to get the default system quotas
    # in Neutron (cf. LP#1204956), so for now handle tenant quotas here.
    # This should be handled in _get_quota_data() eventually.
    if not disabled_quotas:
        return qs

    # Check if neutron is enabled by looking for network and router
    if 'network' and 'router' not in disabled_quotas:
        tenant_id = tenant_id or request.user.tenant_id
        neutron_quotas = neutron.tenant_quota_get(request, tenant_id)
    if 'floating_ips' in disabled_quotas:
        # Neutron with quota extension disabled
        if 'floatingip' in disabled_quotas:
            qs.add(base.QuotaSet({'floating_ips': -1}))
        # Neutron with quota extension enabled
        else:
            # Rename floatingip to floating_ips since that's how it's
            # expected in some places (e.g. Security & Access' Floating IPs)
            fips_quota = neutron_quotas.get('floatingip').limit
            qs.add(base.QuotaSet({'floating_ips': fips_quota}))
    if 'security_groups' in disabled_quotas:
        if 'security_group' in disabled_quotas:
            qs.add(base.QuotaSet({'security_groups': -1}))
        # Neutron with quota extension enabled
        else:
            # Rename security_group to security_groups since that's how it's
            # expected in some places (e.g. Security & Access' Security Groups)
            sec_quota = neutron_quotas.get('security_group').limit
            qs.add(base.QuotaSet({'security_groups': sec_quota}))
    if 'network' in disabled_quotas:
        for item in qs.items:
            if item.name == 'networks':
                qs.items.remove(item)
                break
    else:
        net_quota = neutron_quotas.get('network').limit
        qs.add(base.QuotaSet({'networks': net_quota}))
    if 'router' in disabled_quotas:
        for item in qs.items:
            if item.name == 'routers':
                qs.items.remove(item)
                break
    else:
        router_quota = neutron_quotas.get('router').limit
        qs.add(base.QuotaSet({'routers': router_quota}))

    return qs
Exemple #8
0
def get_tenant_quota_data(request, disabled_quotas=None, tenant_id=None):
    qs = _get_quota_data(request,
                         "tenant_quota_get",
                         disabled_quotas=disabled_quotas,
                         tenant_id=tenant_id)

    # TODO(jpichon): There is no API to get the default system quotas
    # in Neutron (cf. LP#1204956), so for now handle tenant quotas here.
    # This should be handled in _get_quota_data() eventually.
    if not disabled_quotas:
        return qs

    # Check if neutron is enabled by looking for network and router
    if 'network' and 'router' not in disabled_quotas:
        tenant_id = tenant_id or request.user.tenant_id
        neutron_quotas = neutron.tenant_quota_get(request, tenant_id)
    if 'floating_ips' in disabled_quotas:
        # Neutron with quota extension disabled
        if 'floatingip' in disabled_quotas:
            qs.add(base.QuotaSet({'floating_ips': -1}))
        # Neutron with quota extension enabled
        else:
            # Rename floatingip to floating_ips since that's how it's
            # expected in some places (e.g. Security & Access' Floating IPs)
            fips_quota = neutron_quotas.get('floatingip').limit
            qs.add(base.QuotaSet({'floating_ips': fips_quota}))
    if 'security_groups' in disabled_quotas:
        if 'security_group' in disabled_quotas:
            qs.add(base.QuotaSet({'security_groups': -1}))
        # Neutron with quota extension enabled
        else:
            # Rename security_group to security_groups since that's how it's
            # expected in some places (e.g. Security & Access' Security Groups)
            sec_quota = neutron_quotas.get('security_group').limit
            qs.add(base.QuotaSet({'security_groups': sec_quota}))
    if 'network' in disabled_quotas:
        for item in qs.items:
            if item.name == 'networks':
                qs.items.remove(item)
                break
    else:
        net_quota = neutron_quotas.get('network').limit
        qs.add(base.QuotaSet({'networks': net_quota}))
    if 'router' in disabled_quotas:
        for item in qs.items:
            if item.name == 'routers':
                qs.items.remove(item)
                break
    else:
        router_quota = neutron_quotas.get('router').limit
        qs.add(base.QuotaSet({'routers': router_quota}))

    return qs
Exemple #9
0
def _get_quota_data(request,
                    tenant_mode=True,
                    disabled_quotas=None,
                    tenant_id=None):
    quotasets = []
    if not tenant_id:
        tenant_id = request.user.tenant_id
    if disabled_quotas is None:
        disabled_quotas = get_disabled_quotas(request)

    qs = base.QuotaSet()

    if 'instances' not in disabled_quotas:
        if tenant_mode:
            quotasets.append(nova.tenant_quota_get(request, tenant_id))
        else:
            quotasets.append(nova.default_quota_get(request, tenant_id))

    if 'volumes' not in disabled_quotas:
        try:
            if tenant_mode:
                quotasets.append(cinder.tenant_quota_get(request, tenant_id))
            else:
                quotasets.append(cinder.default_quota_get(request, tenant_id))
        except cinder.cinder_exception.ClientException:
            disabled_quotas.update(CINDER_QUOTA_FIELDS)
            msg = _("Unable to retrieve volume limit information.")
            exceptions.handle(request, msg)

    #mj - add the tenant_quota info from neutron - this is replaced in Queens
    if 'network' not in disabled_quotas:
        try:
            if tenant_mode:
                quotasets.append(
                    neutron.tenant_quota_get(request, tenant_id=tenant_id))
            else:
                quotasets.append(neutron.default_quota_get(request, tenant_id))

        except Exception:
            disabled_quotas.update(NEUTRON_QUOTA_FIELDS)
            msg = _('Unable to retrieve Neutron quota information.')

    for quota in itertools.chain(*quotasets):
        if quota.name not in disabled_quotas:
            qs[quota.name] = quota.limit
    return qs
Exemple #10
0
def get_tenant_quota_data(request, disabled_quotas=None, tenant_id=None):
    qs = _get_quota_data(request, "tenant_quota_get", disabled_quotas=disabled_quotas, tenant_id=tenant_id)

    # TODO(jpichon): There is no API to get the default system quotas
    # in Neutron (cf. LP#1204956), so for now handle tenant quotas here.
    # This should be handled in _get_quota_data() eventually.
    if disabled_quotas and "floating_ips" in disabled_quotas:
        # Neutron with quota extension disabled
        if "floatingip" in disabled_quotas:
            qs.add(base.QuotaSet({"floating_ips": -1}))
        # Neutron with quota extension enabled
        else:
            tenant_id = tenant_id or request.user.tenant_id
            neutron_quotas = neutron.tenant_quota_get(request, tenant_id)
            # Rename floatingip to floating_ips since that's how it's
            # expected in some places (e.g. Security & Access' Floating IPs)
            fips_quota = neutron_quotas.get("floatingip").limit
            qs.add(base.QuotaSet({"floating_ips": fips_quota}))

    return qs
Exemple #11
0
def get_limits(request):
    """return the user's limits/quota. This includes nova, cinder and if neutron is available the number of attached
    IP addresses
    :param request: The request
    :returns nova, cinder & neutron limits
    """

    cinder_limits = None
    neutron_limits = {}

    # get nova & cinder limits
    reserved = request.GET.get('reserved') == 'true'
    nova_limits = nova_tenant_absolute_limits(request, reserved)

    try:
        cinder_limits = cinder_tenant_absolute_limits(request)
    except:
        pass

    # if neturon is enabled, get the number of floating and attached IP addresses
    if is_enabled_by_config("network"):
        neutron_max = tenant_quota_get(request, request.user.tenant_id)

        for limit in neutron_max:

            # check if the used ips are really attached to an instance
            used_ips = []
            if limit.name == 'floatingip':
                neutron_limits['maxTotalFloatingIps'] = limit.limit
                floating_ip_manager = FloatingIpManager(request)
                floating_ips = floating_ip_manager.list()
                neutron_limits['totalFloatingIps'] = len(floating_ips)
                for ip in floating_ips:
                    if ip.instance_id:
                        used_ips.append(ip)

                neutron_limits['totalFloatingIpsUsed'] = len(used_ips)
    return clean_limts(nova_limits), clean_limts(cinder_limits), clean_limts(
        neutron_limits)
Exemple #12
0
def get_tenant_quota_data(request, disabled_quotas=None, tenant_id=None):
    qs = _get_quota_data(request,
                         "tenant_quota_get",
                         disabled_quotas=disabled_quotas,
                         tenant_id=tenant_id)

    # TODO(jpichon): There is no API to get the default system quotas
    # in Neutron (cf. LP#1204956), so for now handle tenant quotas here.
    # This should be handled in _get_quota_data() eventually.
    if disabled_quotas and 'floating_ips' in disabled_quotas:
        # Neutron with quota extension disabled
        if 'floatingip' in disabled_quotas:
            qs.add(base.QuotaSet({'floating_ips': -1}))
        # Neutron with quota extension enabled
        else:
            tenant_id = tenant_id or request.user.tenant_id
            neutron_quotas = neutron.tenant_quota_get(request, tenant_id)
            # Rename floatingip to floating_ips since that's how it's
            # expected in some places (e.g. Security & Access' Floating IPs)
            fips_quota = neutron_quotas.get('floatingip').limit
            qs.add(base.QuotaSet({'floating_ips': fips_quota}))

    return qs
Exemple #13
0
def get_tenant_quota_data(request, disabled_quotas=None, tenant_id=None):
    qs = _get_quota_data(request,
                         tenant_mode=True,
                         disabled_quotas=disabled_quotas,
                         tenant_id=tenant_id)

    # TODO(jpichon): There is no API to get the default system quotas
    # in Neutron (cf. LP#1204956), so for now handle tenant quotas here.
    # This should be handled in _get_quota_data() eventually.

    # TODO(amotoki): Purge this tricky usage.
    # openstack_dashboard/dashboards/identity/projects/views.py
    # calls get_tenant_quota_data directly and it expects
    # neutron data is not returned.
    if not disabled_quotas:
        return qs

    # Check if neutron is enabled by looking for network
    if not (NEUTRON_QUOTA_FIELDS - disabled_quotas):
        return qs

    tenant_id = tenant_id or request.user.tenant_id
    neutron_quotas = neutron.tenant_quota_get(request, tenant_id)

    if 'floating_ips' in disabled_quotas:
        if 'floatingip' not in disabled_quotas:
            # Rename floatingip to floating_ips since that's how it's
            # expected in some places (e.g. Security & Access' Floating IPs)
            fips_quota = neutron_quotas.get('floatingip').limit
            qs.add(base.QuotaSet({'floating_ips': fips_quota}))

    if 'security_groups' in disabled_quotas:
        if 'security_group' not in disabled_quotas:
            # Rename security_group to security_groups since that's how it's
            # expected in some places (e.g. Security & Access' Security Groups)
            sec_quota = neutron_quotas.get('security_group').limit
            qs.add(base.QuotaSet({'security_groups': sec_quota}))

    if 'network' in disabled_quotas:
        for item in qs.items:
            if item.name == 'networks':
                qs.items.remove(item)
                break
    else:
        net_quota = neutron_quotas.get('network').limit
        qs.add(base.QuotaSet({'networks': net_quota}))

    if 'subnet' in disabled_quotas:
        for item in qs.items:
            if item.name == 'subnets':
                qs.items.remove(item)
                break
    else:
        net_quota = neutron_quotas.get('subnet').limit
        qs.add(base.QuotaSet({'subnets': net_quota}))

    if 'router' in disabled_quotas:
        for item in qs.items:
            if item.name == 'routers':
                qs.items.remove(item)
                break
    else:
        router_quota = neutron_quotas.get('router').limit
        qs.add(base.QuotaSet({'routers': router_quota}))

    return qs