Ejemplo n.º 1
0
def tenant_limit_usages(request):
    # TODO(licostan): This method shall be removed from Quota module.
    # ProjectUsage/BaseUsage maybe used instead on volume/image dashboards.
    limits = {}

    try:
        if base.is_service_enabled(request, 'compute'):
            limits.update(nova.tenant_absolute_limits(request, reserved=True))
    except Exception:
        msg = _("Unable to retrieve compute limit information.")
        exceptions.handle(request, msg)

    if cinder.is_volume_service_enabled(request):
        try:
            limits.update(cinder.tenant_absolute_limits(request))
        except cinder.cinder_exception.ClientException:
            msg = _("Unable to retrieve volume limit information.")
            exceptions.handle(request, msg)

    # TODO(amotoki): Support neutron quota details extensions
    # which returns limit/usage/reserved per resource.
    # Note that the data format is different from nova/cinder limit API.
    # https://developer.openstack.org/
    #   api-ref/network/v2/#quotas-details-extension-quota-details

    return limits
Ejemplo n.º 2
0
def tenant_limit_usages(request):
    # TODO(licostan): This method shall be removed from Quota module.
    # ProjectUsage/BaseUsage maybe used instead on volume/image dashboards.
    limits = {}

    try:
        if base.is_service_enabled(request, 'compute'):
            limits.update(nova.tenant_absolute_limits(request, reserved=True))
    except Exception:
        msg = _("Unable to retrieve compute limit information.")
        exceptions.handle(request, msg)

    if cinder.is_volume_service_enabled(request):
        try:
            limits.update(cinder.tenant_absolute_limits(request))
        except cinder.cinder_exception.ClientException:
            msg = _("Unable to retrieve volume limit information.")
            exceptions.handle(request, msg)

    # TODO(amotoki): Support neutron quota details extensions
    # which returns limit/usage/reserved per resource.
    # Note that the data format is different from nova/cinder limit API.
    # https://developer.openstack.org/
    #   api-ref/network/v2/#quotas-details-extension-quota-details

    return limits
Ejemplo n.º 3
0
def tenant_limit_usages(request):
    # TODO(licostan): This method shall be removed from Quota module.
    # ProjectUsage/BaseUsage maybe used instead on volume/image dashboards.
    limits = {}

    try:
        limits.update(nova.tenant_absolute_limits(request))
    except Exception:
        msg = _("Unable to retrieve compute limit information.")
        exceptions.handle(request, msg)

    if base.is_service_enabled(request, 'volume'):
        try:
            limits.update(cinder.tenant_absolute_limits(request))
            volumes = cinder.volume_list(request)
            snapshots = cinder.volume_snapshot_list(request)
            total_size = sum([getattr(volume, 'size', 0) for volume
                              in volumes])
            limits['gigabytesUsed'] = total_size
            limits['volumesUsed'] = len(volumes)
            limits['snapshotsUsed'] = len(snapshots)
        except Exception:
            msg = _("Unable to retrieve volume limit information.")
            exceptions.handle(request, msg)

    return limits
Ejemplo n.º 4
0
def tenant_limit_usages(request):
    # TODO(licostan): This method shall be removed from Quota module.
    # ProjectUsage/BaseUsage maybe used instead on volume/image dashboards.
    limits = {}

    try:
        if base.is_service_enabled(request, 'compute'):
            limits.update(nova.tenant_absolute_limits(request, reserved=True))
    except Exception:
        msg = _("Unable to retrieve compute limit information.")
        exceptions.handle(request, msg)

    if cinder.is_volume_service_enabled(request):
        try:
            limits.update(cinder.tenant_absolute_limits(request))
            volumes = cinder.volume_list(request)
            snapshots = cinder.volume_snapshot_list(request)
            # gigabytesUsed should be a total of volumes and snapshots
            #mj - display the correct amount of volume usage in the volume creation panel
            #vol_size = sum([getattr(volume, 'size', 0) for volume
            #                in volumes])
            #snap_size = sum([getattr(snap, 'size', 0) for snap
            #                 in snapshots])
            #limits['gigabytesUsed'] = vol_size + snap_size

            limits['gigabytesUsed'] = limits.get('totalGigabytesUsed', 0)
            limits['volumesUsed'] = limits.get('totalVolumesUsed', 0)
            limits['snapshotsUsed'] = limits.get('totalSnapshotsUsed', 0)
            #limits['volumesUsed'] = len(volumes)
            #limits['snapshotsUsed'] = len(snapshots)
        except cinder.cinder_exception.ClientException:
            msg = _("Unable to retrieve volume limit information.")
            exceptions.handle(request, msg)

    return limits
Ejemplo n.º 5
0
def tenant_limit_usages(request):
    # TODO(licostan): This method shall be removed from Quota module.
    # ProjectUsage/BaseUsage maybe used instead on volume/image dashboards.
    limits = {}

    try:
        if base.is_service_enabled(request, 'compute'):
            limits.update(nova.tenant_absolute_limits(request, reserved=True))
    except Exception:
        msg = _("Unable to retrieve compute limit information.")
        exceptions.handle(request, msg)

    if cinder.is_volume_service_enabled(request):
        try:
            limits.update(cinder.tenant_absolute_limits(request))
        except cinder.cinder_exception.ClientException:
            msg = _("Unable to retrieve volume limit information.")
            exceptions.handle(request, msg)

    return limits
Ejemplo n.º 6
0
def tenant_limit_usages(request):
    # TODO(licostan): This method shall be removed from Quota module.
    # ProjectUsage/BaseUsage maybe used instead on volume/image dashboards.
    limits = {}

    try:
        if base.is_service_enabled(request, 'compute'):
            limits.update(nova.tenant_absolute_limits(request, reserved=True))
    except Exception:
        msg = _("Unable to retrieve compute limit information.")
        exceptions.handle(request, msg)

    if cinder.is_volume_service_enabled(request):
        try:
            limits.update(cinder.tenant_absolute_limits(request))
        except cinder.cinder_exception.ClientException:
            msg = _("Unable to retrieve volume limit information.")
            exceptions.handle(request, msg)

    return limits
Ejemplo n.º 7
0
def tenant_limit_usages(request):
    # TODO(licostan): This method shall be removed from Quota module.
    # ProjectUsage/BaseUsage maybe used instead on volume/image dashboards.
    limits = {}

    try:
        #limits.update(nova.tenant_absolute_limits(request))
        if is_m1_user_admin(request):
            limits.update(tenant_absolute_limits_nova(request))
        else:
            limits.update(nova.tenant_absolute_limits(request))
    except Exception:
        msg = _("Unable to retrieve compute limit information.")
        exceptions.handle(request, msg)

    if base.is_service_enabled(request, 'volume'):
        try:
            #limits.update(cinder.tenant_absolute_limits(request))
            #volumes = cinder.volume_list(request)
            #snapshots = cinder.volume_snapshot_list(request)
            if is_m1_user_admin(request):
                limits.update(tenant_absolute_limits_cinder(request))
                volumes = get_volume_list(request)
                snapshots = get_volume_snapshot_list(request)
            else:
                limits.update(cinder.tenant_absolute_limits(request))
                volumes = cinder.volume_list(request)
                snapshots = cinder.volume_snapshot_list(request)

            # gigabytesUsed should be a total of volumes and snapshots
            vol_size = sum([getattr(volume, 'size', 0) for volume in volumes])
            snap_size = sum([getattr(snap, 'size', 0) for snap in snapshots])
            limits['gigabytesUsed'] = vol_size + snap_size
            limits['volumesUsed'] = len(volumes)
            limits['snapshotsUsed'] = len(snapshots)
        except cinder.ClientException:
            msg = _("Unable to retrieve volume limit information.")
            exceptions.handle(request, msg)

    return limits
Ejemplo n.º 8
0
def tenant_limit_usages(request):
    limits = {}

    try:
        limits.update(nova.tenant_absolute_limits(request))
    except Exception:
        msg = _("Unable to retrieve compute limit information.")
        exceptions.handle(request, msg)

    if base.is_service_enabled(request, 'volume'):
        try:
            limits.update(cinder.tenant_absolute_limits(request))
            volumes = cinder.volume_list(request)
            total_size = sum([getattr(volume, 'size', 0) for volume
                              in volumes])
            limits['gigabytesUsed'] = total_size
            limits['volumesUsed'] = len(volumes)
        except Exception:
            msg = _("Unable to retrieve volume limit information.")
            exceptions.handle(request, msg)

    return limits
Ejemplo n.º 9
0
def tenant_limit_usages(request):
    limits = {}

    try:
        limits.update(nova.tenant_absolute_limits(request))
    except Exception:
        msg = _("Unable to retrieve compute limit information.")
        exceptions.handle(request, msg)

    if base.is_service_enabled(request, 'volume'):
        try:
            limits.update(cinder.tenant_absolute_limits(request))
            volumes = cinder.volume_list(request)
            total_size = sum(
                [getattr(volume, 'size', 0) for volume in volumes])
            limits['gigabytesUsed'] = total_size
            limits['volumesUsed'] = len(volumes)
        except Exception:
            msg = _("Unable to retrieve volume limit information.")
            exceptions.handle(request, msg)

    return limits
Ejemplo n.º 10
0
def _get_tenant_compute_usages(request, usages, disabled_quotas, tenant_id):
    enabled_compute_quotas = NOVA_COMPUTE_QUOTA_FIELDS - disabled_quotas
    if not enabled_compute_quotas:
        return

    if not base.is_service_enabled(request, 'compute'):
        return

    try:
        limits = nova.tenant_absolute_limits(request,
                                             reserved=True,
                                             tenant_id=tenant_id)
    except nova.nova_exceptions.ClientException:
        msg = _("Unable to retrieve compute limit information.")
        exceptions.handle(request, msg)

    for quota_name, limit_keys in NOVA_QUOTA_LIMIT_MAP.items():
        if limit_keys['usage']:
            usage = limits[limit_keys['usage']]
        else:
            usage = None
        _add_limit_and_usage(usages, quota_name, limits[limit_keys['limit']],
                             usage, disabled_quotas)
Ejemplo n.º 11
0
def _get_tenant_compute_usages(request, usages, disabled_quotas, tenant_id):
    enabled_compute_quotas = NOVA_COMPUTE_QUOTA_FIELDS - disabled_quotas
    if not enabled_compute_quotas:
        return

    if not base.is_service_enabled(request, 'compute'):
        return

    try:
        limits = nova.tenant_absolute_limits(request, reserved=True,
                                             tenant_id=tenant_id)
    except nova.nova_exceptions.ClientException:
        msg = _("Unable to retrieve compute limit information.")
        exceptions.handle(request, msg)

    for quota_name, limit_keys in NOVA_QUOTA_LIMIT_MAP.items():
        if limit_keys['usage']:
            usage = limits[limit_keys['usage']]
        else:
            usage = None
        _add_limit_and_usage(usages, quota_name,
                             limits[limit_keys['limit']],
                             usage,
                             disabled_quotas)