Tihomir Trifonov ba27042d65 Added custom parser for tablesorter.js
A custom parser is needed for sorting of
custom type columns like the 'Size' columns.
The 'KB', 'MB', 'GB'... values break the sorter
logic and need to be parsed manually.

The custom parser works on all 'Size'/'RAM'/'Memory'
columns. It works also on flavor-info columns like:

    `m1.tiny | 512MB RAM | 1 VCPU | 0 Disk`

The custom parser sorts these lines based on the RAM value.

Note: as seen in horizon.tables.js file, an workaround was
added as there is one more <th> in the <thead> (incl. the table_caption)
than the <td>'s in <tbody>. Thus the custom parser needs
to be added to [i-1] header, while the header itself needs [i],
as the parser is processed in <tbody>, while headers are processed
including the table_caption... This might be a problem at some time,
although currently it works...

Fixes bug 1013475

Change-Id: I793ae330c33fde4e625f96e55fdda3748c84b8c3
2012-07-23 19:10:34 +03:00

103 lines
4.0 KiB
Python

# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2012 Openstack, LLC
# Copyright 2012 Nebula, Inc.
#
# 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.
import logging
from django.template.defaultfilters import title
from django.utils.translation import ugettext_lazy as _
from horizon import api
from horizon import tables
from horizon.dashboards.nova.instances.tables import (TerminateInstance,
EditInstance, ConsoleLink, LogLink, SnapshotLink,
TogglePause, ToggleSuspend, RebootInstance, get_size, UpdateRow,
LaunchLink, get_ips, get_power_state)
from horizon.utils.filters import replace_underscores
LOG = logging.getLogger(__name__)
class AdminLaunchLink(LaunchLink):
url = "horizon:syspanel:instances:launch"
class AdminUpdateRow(UpdateRow):
def get_data(self, request, instance_id):
instance = super(AdminUpdateRow, self).get_data(request, instance_id)
tenant = api.keystone.tenant_get(request,
instance.tenant_id,
admin=True)
instance.tenant_name = getattr(tenant, "name", None)
return instance
class SyspanelInstancesTable(tables.DataTable):
TASK_STATUS_CHOICES = (
(None, True),
("none", True)
)
STATUS_CHOICES = (
("active", True),
("suspended", True),
("paused", True),
("error", False),
)
TASK_DISPLAY_CHOICES = (
("image_snapshot", "Snapshotting"),
)
tenant = tables.Column("tenant_name", verbose_name=_("Project Name"))
# NOTE(gabriel): Commenting out the user column because all we have
# is an ID, and correlating that at production scale using our current
# techniques isn't practical. It can be added back in when we have names
# returned in a practical manner by the API.
#user = tables.Column("user_id", verbose_name=_("User"))
host = tables.Column("OS-EXT-SRV-ATTR:host",
verbose_name=_("Host"),
classes=('nowrap-col',))
name = tables.Column("name",
link=("horizon:nova:instances:detail"),
verbose_name=_("Instance Name"))
ip = tables.Column(get_ips, verbose_name=_("IP Address"))
size = tables.Column(get_size,
verbose_name=_("Size"),
classes=('nowrap-col',),
attrs={'data-type': 'size'})
status = tables.Column("status",
filters=(title, replace_underscores),
verbose_name=_("Status"),
status=True,
status_choices=STATUS_CHOICES)
task = tables.Column("OS-EXT-STS:task_state",
verbose_name=_("Task"),
filters=(title, replace_underscores),
status=True,
status_choices=TASK_STATUS_CHOICES,
display_choices=TASK_DISPLAY_CHOICES)
state = tables.Column(get_power_state,
filters=(title, replace_underscores),
verbose_name=_("Power State"))
class Meta:
name = "instances"
verbose_name = _("Instances")
status_columns = ["status", "task"]
table_actions = (AdminLaunchLink, TerminateInstance,)
row_class = AdminUpdateRow
row_actions = (EditInstance, ConsoleLink, LogLink, SnapshotLink,
TogglePause, ToggleSuspend, RebootInstance,
TerminateInstance)