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 _
24
23
from horizon import api
25
24
from horizon import tables
26
25
from horizon.templatetags import sizeformat
27
from .tabs import InstanceDetailTabs, LogTab, VNCTab
29
30
LOG = logging.getLogger(__name__)
91
92
self.paused = instance.status == "PAUSED"
93
94
self.current_present_action = UNPAUSE
96
self.current_present_action = PAUSE
94
97
return instance.status in ACTIVE_STATES or self.paused
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
124
self.current_present_action = SUSPEND
120
125
return instance.status in ACTIVE_STATES or self.suspended
122
127
def action(self, request, obj_id):
155
160
class ConsoleLink(tables.LinkAction):
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",)
161
166
def allowed(self, request, instance=None):
162
167
return instance.status in ACTIVE_STATES
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])
165
175
class LogLink(tables.LinkAction):
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",)
171
181
def allowed(self, request, instance=None):
172
182
return instance.status in ACTIVE_STATES
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])
175
190
class UpdateRow(tables.Row):
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"])
204
216
return POWER_STATES.get(getattr(instance, "OS-EXT-STS:power_state", 0), '')
219
def replace_underscores(string):
220
return string.replace("_", " ")
207
223
class InstancesTable(tables.DataTable):
208
224
TASK_STATUS_CHOICES = (
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",
240
filters=(title, replace_underscores),
223
241
verbose_name=_("Status"),
225
243
status_choices=STATUS_CHOICES)
226
244
task = tables.Column("OS-EXT-STS:task_state",
227
245
verbose_name=_("Task"),
246
filters=(title, replace_underscores),
230
248
status_choices=TASK_STATUS_CHOICES)
231
249
state = tables.Column(get_power_state,
250
filters=(title, replace_underscores),
233
251
verbose_name=_("Power State"))