Exemple #1
0
def usage(request, tenant_id=None):
    tenant_id = tenant_id or request.user.tenant_id
    today = test.today()
    date_start = datetime.date(today.year, today.month, 1)
    datetime_start = datetime.datetime.combine(date_start, test.time())
    datetime_end = test.utcnow()

    show_terminated = request.GET.get('show_terminated', False)

    try:
        usage = api.usage_get(request, tenant_id, datetime_start, datetime_end)
    except:
        usage = api.nova.Usage(None)
        redirect = reverse("horizon:nova:overview:index")
        exceptions.handle(request,
                          _('Unable to retrieve usage information.'))

    total_ram = 0
    ram_unit = "MB"

    instances = []
    terminated = []
    if hasattr(usage, 'server_usages'):
        total_ram = usage.total_active_memory_mb
        now = datetime.datetime.now()
        for i in usage.server_usages:
            i['uptime_at'] = now - datetime.timedelta(seconds=i['uptime'])
            if i['ended_at'] and not show_terminated:
                terminated.append(i)
            else:
                instances.append(i)

    if total_ram >= 1024:
        ram_unit = "GB"
        total_ram /= 1024

    if request.GET.get('format', 'html') == 'csv':
        template = 'nova/overview/usage.csv'
        mimetype = "text/csv"
    else:
        template = 'nova/overview/usage.html'
        mimetype = "text/html"

    dash_url = horizon.get_dashboard('nova').get_absolute_url()

    return shortcuts.render(request, template, {
                                'usage': usage,
                                'ram_unit': ram_unit,
                                'total_ram': total_ram,
                                'csv_link': '?format=csv',
                                'show_terminated': show_terminated,
                                'datetime_start': datetime_start,
                                'datetime_end': datetime_end,
                                'instances': instances,
                                'dash_url': dash_url},
                            content_type=mimetype)
Exemple #2
0
def usage(request, tenant_id=None):
    tenant_id = tenant_id or request.user.tenant_id
    today = test.today()
    date_start = datetime.date(today.year, today.month, 1)
    datetime_start = datetime.datetime.combine(date_start, test.time())
    datetime_end = test.utcnow()

    show_terminated = request.GET.get('show_terminated', False)

    usage = {}
    if not tenant_id:
        tenant_id = request.user.tenant_id

    try:
        usage = api.usage_get(request, tenant_id, datetime_start, datetime_end)
    except api_exceptions.ApiException, e:
        LOG.exception(_('ApiException in instance usage'))

        messages.error(request, _('Unable to get usage info: %s') % e.message)
Exemple #3
0
def usage(request, tenant_id=None):
    tenant_id = tenant_id or request.user.tenant_id
    today = test.today()
    date_start = datetime.date(today.year, today.month, 1)
    datetime_start = datetime.datetime.combine(date_start, test.time())
    datetime_end = test.utcnow()

    show_terminated = request.GET.get('show_terminated', False)

    usage = {}
    if not tenant_id:
        tenant_id = request.user.tenant_id

    try:
        usage = api.usage_get(request, tenant_id, datetime_start, datetime_end)
    except api_exceptions.ApiException, e:
        LOG.exception(_('ApiException in instance usage'))

        messages.error(request, _('Unable to get usage info: %s') % e.message)