~ubuntu-branches/ubuntu/precise/horizon/precise-updates

« back to all changes in this revision

Viewing changes to horizon/dashboards/nova/instances_and_volumes/instances/tables.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Adam Gandelman, Adrien Cunin
  • Date: 2012-04-04 07:21:15 UTC
  • mfrom: (1.1.12)
  • Revision ID: package-import@ubuntu.com-20120404072115-lb9v3gq3yv93ern2
Tags: 2012.1~rc2-0ubuntu1
[ Chuck Short ]
* New usptream release.
* debian/control: Use python-cherrypy3
* debian/rules: Update pythonpath in order to run tests.
* debian/patches/fix-coverage-binary-name.patch: Make the testsuite
  run.
* debian/rules: Fail build if tests fail.

[ Adam Gandelman ]
* debian/control: Add python-memcache 
* debain/dashboard.conf: Update to match current upstream documentation
  (LP: #966069)

[ Adrien Cunin ]
* Renamed Apache config file from dashboard.conf to openstack-dashboard.conf
  (LP: #965410)
  - Updated post{inst,rm} and added preinst to handle correctly the rename

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
from django import template
20
20
from django.template.defaultfilters import title
21
 
from django.utils.datastructures import SortedDict
22
 
from django.utils.translation import ugettext as _
 
21
from django.utils.translation import ugettext_lazy as _
23
22
 
24
23
from horizon import api
25
24
from horizon import tables
26
25
from horizon.templatetags import sizeformat
27
26
 
 
27
from .tabs import InstanceDetailTabs, LogTab, VNCTab
 
28
 
28
29
 
29
30
LOG = logging.getLogger(__name__)
30
31
 
91
92
        self.paused = instance.status == "PAUSED"
92
93
        if self.paused:
93
94
            self.current_present_action = UNPAUSE
 
95
        else:
 
96
            self.current_present_action = PAUSE
94
97
        return instance.status in ACTIVE_STATES or self.paused
95
98
 
96
99
    def action(self, request, obj_id):
117
120
        self.suspended = instance.status == "SUSPENDED"
118
121
        if self.suspended:
119
122
            self.current_present_action = RESUME
 
123
        else:
 
124
            self.current_present_action = SUSPEND
120
125
        return instance.status in ACTIVE_STATES or self.suspended
121
126
 
122
127
    def action(self, request, obj_id):
155
160
class ConsoleLink(tables.LinkAction):
156
161
    name = "console"
157
162
    verbose_name = _("VNC Console")
158
 
    url = "horizon:nova:instances_and_volumes:instances:vnc"
 
163
    url = "horizon:nova:instances_and_volumes:instances:detail"
159
164
    classes = ("btn-console",)
160
165
 
161
166
    def allowed(self, request, instance=None):
162
167
        return instance.status in ACTIVE_STATES
163
168
 
 
169
    def get_link_url(self, datum):
 
170
        base_url = super(ConsoleLink, self).get_link_url(datum)
 
171
        tab_query_string = VNCTab(InstanceDetailTabs).get_query_string()
 
172
        return "?".join([base_url, tab_query_string])
 
173
 
164
174
 
165
175
class LogLink(tables.LinkAction):
166
176
    name = "log"
167
177
    verbose_name = _("View Log")
168
 
    url = "horizon:nova:instances_and_volumes:instances:console"
 
178
    url = "horizon:nova:instances_and_volumes:instances:detail"
169
179
    classes = ("btn-log",)
170
180
 
171
181
    def allowed(self, request, instance=None):
172
182
        return instance.status in ACTIVE_STATES
173
183
 
 
184
    def get_link_url(self, datum):
 
185
        base_url = super(LogLink, self).get_link_url(datum)
 
186
        tab_query_string = LogTab(InstanceDetailTabs).get_query_string()
 
187
        return "?".join([base_url, tab_query_string])
 
188
 
174
189
 
175
190
class UpdateRow(tables.Row):
176
191
    ajax = True
177
192
 
178
 
    @classmethod
179
 
    def get_data(cls, request, instance_id):
 
193
    def get_data(self, request, instance_id):
180
194
        instance = api.server_get(request, instance_id)
181
 
        flavors = api.flavor_list(request)
182
 
        keyed_flavors = [(str(flavor.id), flavor) for flavor in flavors]
183
 
        instance.full_flavor = SortedDict(keyed_flavors)[instance.flavor["id"]]
 
195
        instance.full_flavor = api.flavor_get(request, instance.flavor["id"])
184
196
        return instance
185
197
 
186
198
 
204
216
    return POWER_STATES.get(getattr(instance, "OS-EXT-STS:power_state", 0), '')
205
217
 
206
218
 
 
219
def replace_underscores(string):
 
220
    return string.replace("_", " ")
 
221
 
 
222
 
207
223
class InstancesTable(tables.DataTable):
208
224
    TASK_STATUS_CHOICES = (
209
225
        (None, True),
211
227
    )
212
228
    STATUS_CHOICES = (
213
229
        ("active", True),
 
230
        ("suspended", True),
 
231
        ("paused", True),
214
232
        ("error", False),
215
233
    )
216
234
    name = tables.Column("name", link="horizon:nova:instances_and_volumes:" \
219
237
    ip = tables.Column(get_ips, verbose_name=_("IP Address"))
220
238
    size = tables.Column(get_size, verbose_name=_("Size"))
221
239
    status = tables.Column("status",
222
 
                           filters=(title,),
 
240
                           filters=(title, replace_underscores),
223
241
                           verbose_name=_("Status"),
224
242
                           status=True,
225
243
                           status_choices=STATUS_CHOICES)
226
244
    task = tables.Column("OS-EXT-STS:task_state",
227
245
                         verbose_name=_("Task"),
228
 
                         filters=(title,),
 
246
                         filters=(title, replace_underscores),
229
247
                         status=True,
230
248
                         status_choices=TASK_STATUS_CHOICES)
231
249
    state = tables.Column(get_power_state,
232
 
                          filters=(title,),
 
250
                          filters=(title, replace_underscores),
233
251
                          verbose_name=_("Power State"))
234
252
 
235
253
    class Meta: