2013-11-05 13:08:06 -05:00
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
|
2012-06-21 21:55:57 -07:00
|
|
|
from django.core import urlresolvers
|
2013-08-02 13:23:46 +04:00
|
|
|
from django.template.defaultfilters import floatformat # noqa
|
|
|
|
from django.template.defaultfilters import timesince # noqa
|
2014-01-03 17:31:49 +01:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2012-01-31 16:26:24 -08:00
|
|
|
|
|
|
|
from horizon import tables
|
2013-08-23 17:26:48 +04:00
|
|
|
from horizon.templatetags import sizeformat
|
2013-10-21 15:28:40 +03:00
|
|
|
from horizon.utils import filters
|
2012-01-31 16:26:24 -08:00
|
|
|
|
|
|
|
|
|
|
|
class CSVSummary(tables.LinkAction):
|
|
|
|
name = "csv_summary"
|
|
|
|
verbose_name = _("Download CSV Summary")
|
2014-07-02 14:05:54 +02:00
|
|
|
icon = "download"
|
2012-01-31 16:26:24 -08:00
|
|
|
|
|
|
|
def get_link_url(self, usage=None):
|
|
|
|
return self.table.kwargs['usage'].csv_link()
|
|
|
|
|
|
|
|
|
|
|
|
class BaseUsageTable(tables.DataTable):
|
|
|
|
vcpus = tables.Column('vcpus', verbose_name=_("VCPUs"))
|
2014-07-23 16:09:43 -07:00
|
|
|
disk = tables.Column('local_gb', verbose_name=_("Disk"),
|
2016-07-27 02:55:30 +01:00
|
|
|
filters=(sizeformat.diskgbformat,),
|
|
|
|
attrs={"data-type": "size"})
|
2012-01-31 16:26:24 -08:00
|
|
|
memory = tables.Column('memory_mb',
|
|
|
|
verbose_name=_("RAM"),
|
2014-05-19 11:08:34 +08:00
|
|
|
filters=(sizeformat.mb_float_format,),
|
2012-07-23 18:59:51 +03:00
|
|
|
attrs={"data-type": "size"})
|
2012-01-31 16:26:24 -08:00
|
|
|
|
|
|
|
|
|
|
|
class GlobalUsageTable(BaseUsageTable):
|
2013-06-21 13:48:43 +03:00
|
|
|
project = tables.Column('project_name', verbose_name=_("Project Name"))
|
2015-02-04 13:51:16 +08:00
|
|
|
vcpu_hours = tables.Column('vcpu_hours', verbose_name=_("VCPU Hours"),
|
|
|
|
help_text=_("Total VCPU usage (Number of "
|
|
|
|
"VCPU in instance * Hours Used) "
|
|
|
|
"for the project"),
|
|
|
|
filters=(lambda v: floatformat(v, 2),))
|
2012-01-31 16:26:24 -08:00
|
|
|
disk_hours = tables.Column('disk_gb_hours',
|
2012-03-01 13:49:49 +02:00
|
|
|
verbose_name=_("Disk GB Hours"),
|
2014-10-23 18:38:35 -07:00
|
|
|
help_text=_("Total disk usage (GB * "
|
|
|
|
"Hours Used) for the project"),
|
2012-03-01 13:49:49 +02:00
|
|
|
filters=(lambda v: floatformat(v, 2),))
|
2015-02-02 15:06:42 +08:00
|
|
|
memory_hours = tables.Column('memory_mb_hours',
|
|
|
|
verbose_name=_("Memory MB Hours"),
|
|
|
|
help_text=_("Total memory usage (MB * "
|
|
|
|
"Hours Used) for the project"),
|
|
|
|
filters=(lambda v: floatformat(v, 2),))
|
2012-01-31 16:26:24 -08:00
|
|
|
|
|
|
|
def get_object_id(self, datum):
|
|
|
|
return datum.tenant_id
|
|
|
|
|
2015-02-04 18:56:23 -08:00
|
|
|
class Meta(object):
|
2012-01-31 16:26:24 -08:00
|
|
|
name = "global_usage"
|
2014-11-12 14:38:48 +00:00
|
|
|
hidden_title = False
|
2013-12-12 15:37:41 +05:30
|
|
|
verbose_name = _("Usage")
|
2013-06-21 13:48:43 +03:00
|
|
|
columns = ("project", "vcpus", "disk", "memory",
|
2015-02-04 13:51:16 +08:00
|
|
|
"vcpu_hours", "disk_hours", "memory_hours")
|
2012-01-31 16:26:24 -08:00
|
|
|
table_actions = (CSVSummary,)
|
|
|
|
multi_select = False
|
|
|
|
|
|
|
|
|
2012-06-21 21:55:57 -07:00
|
|
|
def get_instance_link(datum):
|
2012-10-23 11:33:32 +03:00
|
|
|
view = "horizon:project:instances:detail"
|
2012-06-21 21:55:57 -07:00
|
|
|
if datum.get('instance_id', False):
|
|
|
|
return urlresolvers.reverse(view, args=(datum.get('instance_id'),))
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2013-06-21 13:48:43 +03:00
|
|
|
class ProjectUsageTable(BaseUsageTable):
|
2012-05-13 13:25:38 -07:00
|
|
|
instance = tables.Column('name',
|
|
|
|
verbose_name=_("Instance Name"),
|
2012-06-21 21:55:57 -07:00
|
|
|
link=get_instance_link)
|
2012-01-31 16:26:24 -08:00
|
|
|
uptime = tables.Column('uptime_at',
|
2014-10-01 14:00:31 +02:00
|
|
|
verbose_name=_("Time since created"),
|
2013-10-21 15:28:40 +03:00
|
|
|
filters=(filters.timesince_sortable,),
|
|
|
|
attrs={'data-type': 'timesince'})
|
2012-01-31 16:26:24 -08:00
|
|
|
|
|
|
|
def get_object_id(self, datum):
|
2012-06-21 21:55:57 -07:00
|
|
|
return datum.get('instance_id', id(datum))
|
2012-01-31 16:26:24 -08:00
|
|
|
|
2015-02-04 18:56:23 -08:00
|
|
|
class Meta(object):
|
2013-06-21 13:48:43 +03:00
|
|
|
name = "project_usage"
|
2014-11-12 14:38:48 +00:00
|
|
|
hidden_title = False
|
2013-12-12 15:37:41 +05:30
|
|
|
verbose_name = _("Usage")
|
2012-01-31 16:26:24 -08:00
|
|
|
columns = ("instance", "vcpus", "disk", "memory", "uptime")
|
|
|
|
table_actions = (CSVSummary,)
|
|
|
|
multi_select = False
|