Skip to content

Commit

Permalink
Compatibility fixes for contrail-horizon Liberty-8.0.0
Browse files Browse the repository at this point in the history
Closes-Bug: #1508467
Change-Id: Iadec45d23ddc24826b94001673ccc82e82d8e019
  • Loading branch information
Adam Tengler committed Jan 8, 2016
1 parent 1cf1e6c commit 7f7c89b
Show file tree
Hide file tree
Showing 16 changed files with 328 additions and 49 deletions.
24 changes: 20 additions & 4 deletions openstack_dashboard/dashboards/project/l3routers/ports/tables.py
Expand Up @@ -15,6 +15,7 @@
import logging

from django.core.urlresolvers import reverse
from django.utils.translation import pgettext_lazy
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy

Expand Down Expand Up @@ -89,22 +90,37 @@ def delete(self, request, obj_id):
exceptions.handle(request, msg, redirect=redirect)


DISPLAY_CHOICES = (
("UP", pgettext_lazy("Admin state of a Port", u"UP")),
("DOWN", pgettext_lazy("Admin state of a Port", u"DOWN")),
)
STATUS_DISPLAY_CHOICES = (
("ACTIVE", pgettext_lazy("current status of port", u"Active")),
("BUILD", pgettext_lazy("current status of port", u"Build")),
("DOWN", pgettext_lazy("current status of port", u"Down")),
("ERROR", pgettext_lazy("current status of port", u"Error")),
)


class PortsTable(tables.DataTable):
name = tables.Column("name",
name = tables.Column("name_or_id",
verbose_name=_("Name"),
link="horizon:project:networking:ports:detail")
fixed_ips = tables.Column(project_tables.get_fixed_ips,
verbose_name=_("Fixed IPs"))
status = tables.Column("status", verbose_name=_("Status"))
status = tables.Column("status",
verbose_name=_("Status"),
display_choices=STATUS_DISPLAY_CHOICES)
device_owner = tables.Column(get_device_owner,
verbose_name=_("Type"))
admin_state = tables.Column("admin_state",
verbose_name=_("Admin State"))
verbose_name=_("Admin State"),
display_choices=DISPLAY_CHOICES)

def get_object_display(self, port):
return port.id

class Meta:
class Meta(object):
name = "interfaces"
verbose_name = _("Interfaces")
table_actions = (AddInterface, RemoveInterface)
Expand Down
47 changes: 43 additions & 4 deletions openstack_dashboard/dashboards/project/l3routers/tables.py
Expand Up @@ -16,15 +16,18 @@

from django.core.urlresolvers import reverse
from django.template import defaultfilters as filters
from django.utils.translation import pgettext_lazy
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
from neutronclient.common import exceptions as q_ext

from horizon import exceptions
from horizon import messages
from horizon import tables

from openstack_dashboard import api
from openstack_dashboard import policy
from openstack_dashboard.usage import quotas

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -77,6 +80,20 @@ class CreateRouter(tables.LinkAction):
icon = "plus"
policy_rules = (("network", "create_router"),)

def allowed(self, request, datum=None):
usages = quotas.tenant_quota_usages(request)
# when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False
# usages['routers'] is empty
if usages.get('routers', {}).get('available', 1) <= 0:
if "disabled" not in self.classes:
self.classes = [c for c in self.classes] + ["disabled"]
self.verbose_name = _("Create Router (Quota exceeded)")
else:
self.verbose_name = _("Create Router")
self.classes = [c for c in self.classes if c != "disabled"]

return True


class EditRouter(policy.PolicyTargetMixin, tables.LinkAction):
name = "update"
Expand Down Expand Up @@ -160,14 +177,32 @@ def get_external_network(router):
return "-"


class RoutersFilterAction(tables.FilterAction):

def filter(self, table, routers, filter_string):
"""Naive case-insensitive search."""
query = filter_string.lower()
return [router for router in routers
if query in router.name.lower()]


class RoutersTable(tables.DataTable):
STATUS_DISPLAY_CHOICES = (
("active", pgettext_lazy("current status of router", u"Active")),
("error", pgettext_lazy("current status of router", u"Error")),
)
ADMIN_STATE_DISPLAY_CHOICES = (
("UP", pgettext_lazy("Admin state of a Router", u"UP")),
("DOWN", pgettext_lazy("Admin state of a Router", u"DOWN")),
)

name = tables.Column("name",
verbose_name=_("Name"),
link="horizon:project:l3routers:detail")
status = tables.Column("status",
filters=(filters.title,),
verbose_name=_("Status"),
status=True)
status=True,
display_choices=STATUS_DISPLAY_CHOICES)
distributed = tables.Column("distributed",
filters=(filters.yesno, filters.capfirst),
verbose_name=_("Distributed"))
Expand All @@ -177,6 +212,9 @@ class RoutersTable(tables.DataTable):
verbose_name=_("HA mode"))
ext_net = tables.Column(get_external_network,
verbose_name=_("External Network"))
admin_state = tables.Column("admin_state",
verbose_name=_("Admin State"),
display_choices=ADMIN_STATE_DISPLAY_CHOICES)

def __init__(self, request, data=None, needs_form_wrapper=None, **kwargs):
super(RoutersTable, self).__init__(
Expand All @@ -192,10 +230,11 @@ def __init__(self, request, data=None, needs_form_wrapper=None, **kwargs):
def get_object_display(self, obj):
return obj.name

class Meta:
class Meta(object):
name = "Routers"
verbose_name = _("Routers")
status_columns = ["status"]
row_class = UpdateRow
table_actions = (CreateRouter, DeleteRouter)
table_actions = (CreateRouter, DeleteRouter,
RoutersFilterAction)
row_actions = (SetGateway, ClearGateway, EditRouter, DeleteRouter)
2 changes: 1 addition & 1 deletion openstack_dashboard/dashboards/project/lbaas/tables.py
Expand Up @@ -165,7 +165,7 @@ class UpdateMonitorLink(policy.PolicyTargetMixin, tables.LinkAction):
policy_rules = (("network", "update_health_monitor"),)

def get_link_url(self, monitor):
base_url = reverse("horizon:project:loadbalancers:updatemonitor",
base_url = reverse("horizon:project:lbaas:updatemonitor",
kwargs={'monitor_id': monitor.id})
return base_url

Expand Down
Empty file.
@@ -0,0 +1,29 @@
# Copyright 2015 Cisco Systems.
#
# 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.utils.translation import ugettext_lazy as _

from contrail_openstack_dashboard.openstack_dashboard.dashboards.project.networking import tables


class DeleteNetwork(tables.DeleteNetwork):
redirect_url = "horizon:project:networking_topology:network"


class NetworksTable(tables.NetworksTable):
class Meta(object):
name = "networks"
verbose_name = _("Networks")
table_actions = (DeleteNetwork,)
row_actions = (DeleteNetwork,)
Empty file.
@@ -0,0 +1,30 @@
# Copyright 2015 Cisco Systems.
#
# 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.utils.translation import ugettext_lazy as _

from contrail_openstack_dashboard.openstack_dashboard.dashboards.project.networking.subnets import tables


class DeleteSubnet(tables.DeleteSubnet):
failure_url = 'horizon:project:networking_topology:network'


class SubnetsTable(tables.SubnetsTable):
class Meta(object):
name = "subnets"
verbose_name = _("Subnets")
row_actions = (DeleteSubnet, )
table_actions = (DeleteSubnet, )
Expand Up @@ -22,10 +22,11 @@
[[/console_id]]
{% endif %}
</div>
<a class="add-interface btn btn-primary btn-xs ajax-modal [[type]]" href="[[add_interface_url]]">[[add_interface_label]]</a>
[[#type]]
<div class="cell delete">
<button class="delete-device btn btn-danger btn-xs [[type]]" data-type="[[type]]" data-device-id="[[id]]">[[delete_label]]</button>
</div>
[[/type]]
</div>
</div>
</div>
Expand Down
@@ -0,0 +1,23 @@
{% extends "horizon/client_side/template.html" %}
{% load horizon %}

{% block id %}balloon_instance{% endblock %}

{% block template %}
{% jstemplate %}
<div class="portTableHeader">
<div class="title">[[ips_label]]</div>
</div>
<table class="detailInfoTable">
<caption></caption>
<tbody>
[[#ips]]
<tr>
<th>[[ip_address]]</th>
<td>[[subnet_id]]</td>
</tr>
[[/ips]]
</tbody>
</table>
{% endjstemplate %}
{% endblock %}
@@ -0,0 +1,38 @@
{% extends "horizon/client_side/template.html" %}
{% load horizon %}

{% block id %}balloon_net{% endblock %}

{% block template %}
{% jstemplate %}
<div class="portTableHeader">
<div class="title">[[subnets_label]]</div>
<div class="action">
<a class="add-subnet btn btn-default btn-xs ajax-modal [[type]]" href="[[add_subnet_url]]">
<span class="fa fa-plus"></span>
[[add_subnet_label]]
</a>
</div>
</div>
<table class="detailInfoTable">
<caption></caption>
<tbody>
[[#subnet]]
<tr>
<th>
<span title="[[id]]">
<a href="[[url]]">[[id]]</a>
</span>
</th>
<td>[[cidr]]</td>
<td class="delete">
<button class="delete-port btn btn-danger btn-xs"
data-router-id="[[router_id]]" data-network-id="[[network_id]]"
data-port-id="[[id]]">[[delete_subnet_label]]</button>
</td>
</tr>
[[/subnet]]
</tbody>
</table>
{% endjstemplate %}
{% endblock %}
Expand Up @@ -5,8 +5,17 @@

{% block template %}
{% jstemplate %}
<div class="portTableHeader">
<div class="title">[[interfaces_label]]</div>
<div class="action">
<a class="add-interface btn btn-default btn-xs ajax-modal [[type]]" href="[[add_interface_url]]">
<span class="fa fa-plus"></span>
[[add_interface_label]]
</a>
</div>
</div>
<table class="detailInfoTable">
<caption>[[interfaces_label]]</caption>
<caption></caption>
<tbody>
[[#port]]
<tr>
Expand All @@ -22,7 +31,9 @@
</td>
<td class="delete">
[[#is_interface]]
<button class="delete-port btn btn-danger btn-xs" data-router-id="[[router_id]]" data-port-id="[[id]]">[[delete_interface_label]]</button>
<button class="delete-port btn btn-danger btn-xs"
data-router-id="[[router_id]]" data-network-id="[[network_id]]"
data-port-id="[[id]]">[[delete_interface_label]]</button>
[[/is_interface]]
</td>
</tr>
Expand Down
Expand Up @@ -2,10 +2,6 @@
{% load i18n %}
{% block title %}{% trans "Create Router" %}{% endblock %}

{% block page_header %}
{% include "horizon/common/_page_header.html" with title=_("Create a Router") %}
{% endblock page_header %}

{% block main %}
{% include 'project/networking_topology/_create_router.html' %}
{% endblock %}
@@ -1,3 +1,5 @@
{% load firstof from future %}

<!DOCTYPE html>
<html>
<head>
Expand All @@ -6,7 +8,7 @@
</head>
<body>
{% include "horizon/_messages.html" %}
{% firstof table.render interfaces_table.render tab_group.render%}
{% firstof subnets_table.render table.render interfaces_table.render tab_group.render %}
{% include "project/networking_topology/_post_massage.html" %}
</body>
</html>

0 comments on commit 7f7c89b

Please sign in to comment.