OpenStack Dashboard (Horizon)
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

87 lines
3.1KB

  1. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  2. # not use this file except in compliance with the License. You may obtain
  3. # a copy of the License at
  4. #
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. #
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  9. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  10. # License for the specific language governing permissions and limitations
  11. # under the License.
  12. from django.core import urlresolvers
  13. from django.template.defaultfilters import floatformat # noqa
  14. from django.template.defaultfilters import timesince # noqa
  15. from django.utils.translation import ugettext_lazy as _ # noqa
  16. from horizon import tables
  17. from horizon.templatetags import sizeformat
  18. from horizon.utils import filters
  19. class CSVSummary(tables.LinkAction):
  20. name = "csv_summary"
  21. verbose_name = _("Download CSV Summary")
  22. classes = ("btn-download",)
  23. def get_link_url(self, usage=None):
  24. return self.table.kwargs['usage'].csv_link()
  25. class BaseUsageTable(tables.DataTable):
  26. vcpus = tables.Column('vcpus', verbose_name=_("VCPUs"))
  27. disk = tables.Column('local_gb', verbose_name=_("Disk"))
  28. memory = tables.Column('memory_mb',
  29. verbose_name=_("RAM"),
  30. filters=(sizeformat.mbformat,),
  31. attrs={"data-type": "size"})
  32. hours = tables.Column('vcpu_hours', verbose_name=_("VCPU Hours"),
  33. filters=(lambda v: floatformat(v, 2),))
  34. class GlobalUsageTable(BaseUsageTable):
  35. project = tables.Column('project_name', verbose_name=_("Project Name"))
  36. disk_hours = tables.Column('disk_gb_hours',
  37. verbose_name=_("Disk GB Hours"),
  38. filters=(lambda v: floatformat(v, 2),))
  39. def get_object_id(self, datum):
  40. return datum.tenant_id
  41. class Meta:
  42. name = "global_usage"
  43. verbose_name = _("Usage Summary")
  44. columns = ("project", "vcpus", "disk", "memory",
  45. "hours", "disk_hours")
  46. table_actions = (CSVSummary,)
  47. multi_select = False
  48. def get_instance_link(datum):
  49. view = "horizon:project:instances:detail"
  50. if datum.get('instance_id', False):
  51. return urlresolvers.reverse(view, args=(datum.get('instance_id'),))
  52. else:
  53. return None
  54. class ProjectUsageTable(BaseUsageTable):
  55. instance = tables.Column('name',
  56. verbose_name=_("Instance Name"),
  57. link=get_instance_link)
  58. uptime = tables.Column('uptime_at',
  59. verbose_name=_("Uptime"),
  60. filters=(filters.timesince_sortable,),
  61. attrs={'data-type': 'timesince'})
  62. def get_object_id(self, datum):
  63. return datum.get('instance_id', id(datum))
  64. class Meta:
  65. name = "project_usage"
  66. verbose_name = _("Usage Summary")
  67. columns = ("instance", "vcpus", "disk", "memory", "uptime")
  68. table_actions = (CSVSummary,)
  69. multi_select = False