Source code for openstack_dashboard.dashboards.project.loadbalancers.tables

#    Copyright 2013, Big Switch Networks, 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.


from django.core.urlresolvers import reverse
from django.template import defaultfilters as filters
from django.utils import http
from django.utils.translation import pgettext_lazy
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy

from horizon import exceptions
from horizon import tables

from openstack_dashboard import api
from openstack_dashboard import policy

















[docs]class UpdatePoolsRow(tables.Row): ajax = True
[docs] def get_data(self, request, pool_id): pool = api.lbaas.pool_get(request, pool_id) try: vip = api.lbaas.vip_get(request, pool.vip_id) pool.vip_name = vip.name except Exception: pool.vip_name = pool.vip_id try: subnet = api.neutron.subnet_get(request, pool.subnet_id) pool.subnet_name = subnet.cidr except Exception: pool.subnet_name = pool.subnet_id return pool
STATUS_CHOICES = ( ("Active", True), ("Down", True), ("Error", False), ) STATUS_DISPLAY_CHOICES = ( ("Active", pgettext_lazy("Current status of a Pool", u"Active")), ("Down", pgettext_lazy("Current status of a Pool", u"Down")), ("Error", pgettext_lazy("Current status of a Pool", u"Error")), ("Created", pgettext_lazy("Current status of a Pool", u"Created")), ("Pending_Create", pgettext_lazy("Current status of a Pool", u"Pending Create")), ("Pending_Update", pgettext_lazy("Current status of a Pool", u"Pending Update")), ("Pending_Delete", pgettext_lazy("Current status of a Pool", u"Pending Delete")), ("Inactive", pgettext_lazy("Current status of a Pool", u"Inactive")), )
[docs]class PoolsTable(tables.DataTable): name = tables.Column("name_or_id", verbose_name=_("Name"), link="horizon:project:loadbalancers:pooldetails") description = tables.Column('description', verbose_name=_("Description")) provider = tables.Column('provider', verbose_name=_("Provider"), filters=(lambda v: filters.default(v, _('N/A')),)) subnet_name = tables.Column('subnet_name', verbose_name=_("Subnet")) protocol = tables.Column('protocol', verbose_name=_("Protocol")) status = tables.Column('status', verbose_name=_("Status"), status=True, status_choices=STATUS_CHOICES, display_choices=STATUS_DISPLAY_CHOICES) vip_name = tables.Column('vip_name', verbose_name=_("VIP"), link=get_vip_link)
[docs] class Meta(object): name = "poolstable" verbose_name = _("Pools") status_columns = ["status"] row_class = UpdatePoolsRow table_actions = (AddPoolLink, DeletePoolLink) row_actions = (UpdatePoolLink, AddVipLink, UpdateVipLink, DeleteVipLink, AddPMAssociationLink, DeletePMAssociationLink, DeletePoolLink)
[docs]class UpdateMemberRow(tables.Row): ajax = True
[docs] def get_data(self, request, member_id): member = api.lbaas.member_get(request, member_id) try: pool = api.lbaas.pool_get(request, member.pool_id) member.pool_name = pool.name except Exception: member.pool_name = member.pool_id return member
[docs]class MembersTable(tables.DataTable): address = tables.Column('address', verbose_name=_("IP Address"), link=get_member_link, attrs={'data-type': "ip"}) protocol_port = tables.Column('protocol_port', verbose_name=_("Protocol Port")) weight = tables.Column('weight', verbose_name=_("Weight")) pool_name = tables.Column('pool_name', verbose_name=_("Pool"), link=get_pool_link) status = tables.Column('status', verbose_name=_("Status"), status=True, status_choices=STATUS_CHOICES, display_choices=STATUS_DISPLAY_CHOICES)
[docs] class Meta(object): name = "memberstable" verbose_name = _("Members") status_columns = ["status"] row_class = UpdateMemberRow table_actions = (AddMemberLink, DeleteMemberLink) row_actions = (UpdateMemberLink, DeleteMemberLink)
[docs]def get_monitor_details(monitor): if monitor.type in ('HTTP', 'HTTPS'): return ("%(http_method)s %(url_path)s => %(codes)s" % {'http_method': monitor.http_method, 'url_path': monitor.url_path, 'codes': monitor.expected_codes}) else: return _("-")
[docs]class MonitorsTable(tables.DataTable): monitor_type = tables.Column( "type", verbose_name=_("Monitor Type"), link="horizon:project:loadbalancers:monitordetails") delay = tables.Column("delay", verbose_name=_("Delay")) timeout = tables.Column("timeout", verbose_name=_("Timeout")) max_retries = tables.Column("max_retries", verbose_name=_("Max Retries")) details = tables.Column(get_monitor_details, verbose_name=_("Details"))
[docs] class Meta(object): name = "monitorstable" verbose_name = _("Monitors") table_actions = (AddMonitorLink, DeleteMonitorLink) row_actions = (UpdateMonitorLink, DeleteMonitorLink)