~ubuntu-branches/ubuntu/utopic/horizon/utopic-updates

« back to all changes in this revision

Viewing changes to openstack_dashboard/dashboards/project/access_and_security/floating_ips/tables.py

  • Committer: Package Import Robot
  • Author(s): James Page, Chris Johnston, James Page
  • Date: 2014-10-03 17:54:18 UTC
  • mfrom: (0.4.1) (1.1.44) (70.1.2 utopic)
  • Revision ID: package-import@ubuntu.com-20141003175418-1jomx0azdvnl5fxz
Tags: 1:2014.2~rc1-0ubuntu1
[ Chris Johnston ]
* d/theme/css/ubuntu.css: Fix Ubuntu theme for Instances "more" dropdown
  (LP: #1308651).

[ James Page ]
* New upstream release candidate:
  - d/p/*: Refresh.
* d/watch: Use tarballs.openstack.org for upstream releases. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
import logging
17
17
 
18
18
from django.conf import settings
19
 
from django.core import urlresolvers
 
19
from django.core.urlresolvers import reverse
20
20
from django import shortcuts
21
21
from django.utils.http import urlencode
22
22
from django.utils.translation import string_concat  # noqa
23
23
from django.utils.translation import ugettext_lazy as _
 
24
from django.utils.translation import ungettext_lazy
24
25
 
25
26
from horizon import exceptions
26
27
from horizon import messages
69
70
 
70
71
class ReleaseIPs(tables.BatchAction):
71
72
    name = "release"
72
 
    action_present = _("Release")
73
 
    action_past = _("Released")
74
 
    data_type_singular = _("Floating IP")
75
 
    data_type_plural = _("Floating IPs")
76
73
    classes = ('btn-danger',)
77
74
    icon = "arrow-up"
78
75
 
 
76
    @staticmethod
 
77
    def action_present(count):
 
78
        return ungettext_lazy(
 
79
            u"Release Floating IP",
 
80
            u"Release Floating IPs",
 
81
            count
 
82
        )
 
83
 
 
84
    @staticmethod
 
85
    def action_past(count):
 
86
        return ungettext_lazy(
 
87
            u"Released Floating IP",
 
88
            u"Released Floating IPs",
 
89
            count
 
90
        )
 
91
 
79
92
    def allowed(self, request, fip=None):
80
93
        if api.base.is_service_enabled(request, "network"):
81
94
            policy = (("network", "delete_floatingip"),)
106
119
        return not fip.port_id and POLICY_CHECK(policy, request)
107
120
 
108
121
    def get_link_url(self, datum):
109
 
        base_url = urlresolvers.reverse(self.url)
 
122
        base_url = reverse(self.url)
110
123
        params = urlencode({"ip_id": self.table.get_object_id(datum)})
111
124
        return "?".join([base_url, params])
112
125
 
140
153
        return shortcuts.redirect('horizon:project:access_and_security:index')
141
154
 
142
155
 
143
 
def get_instance_info(instance):
144
 
    return getattr(instance, "instance_name", None)
 
156
def get_instance_info(fip):
 
157
    if fip.instance_type == 'compute':
 
158
        return (_("%(instance_name)s %(fixed_ip)s")
 
159
                % {'instance_name': getattr(fip, "instance_name", ''),
 
160
                   'fixed_ip': fip.fixed_ip})
 
161
    elif fip.instance_type == 'loadbalancer':
 
162
        return _("Load Balancer VIP %s") % fip.fixed_ip
 
163
    elif fip.instance_type:
 
164
        return fip.fixed_ip
 
165
    else:
 
166
        return None
145
167
 
146
168
 
147
169
def get_instance_link(datum):
148
 
    view = "horizon:project:instances:detail"
149
 
    if datum.instance_id:
150
 
        return urlresolvers.reverse(view, args=(datum.instance_id,))
 
170
    if datum.instance_type == 'compute':
 
171
        return reverse("horizon:project:instances:detail",
 
172
                       args=(datum.instance_id,))
151
173
    else:
152
174
        return None
153
175
 
156
178
    ip = tables.Column("ip",
157
179
                       verbose_name=_("IP Address"),
158
180
                       attrs={'data-type': "ip"})
159
 
    instance = tables.Column(get_instance_info,
 
181
    fixed_ip = tables.Column(get_instance_info,
160
182
                             link=get_instance_link,
161
 
                             verbose_name=_("Instance"),
 
183
                             verbose_name=_("Mapped Fixed IP Address"),
162
184
                             empty_value="-")
163
185
    pool = tables.Column("pool_name",
164
186
                         verbose_name=_("Floating IP Pool"),