summaryrefslogtreecommitdiff
path: root/openstack_dashboard/dashboards/project/stacks/tables.py
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2017-12-09 10:27:43 +0000
committerGerrit Code Review <review@openstack.org>2017-12-09 10:27:43 +0000
commitb4fccffccca501388b0e1800375f3e6c7efaea81 (patch)
treed75a6461aa71d2c2b2d638df787a86ce96e04e72 /openstack_dashboard/dashboards/project/stacks/tables.py
parentf63183bc8161096446a454f75c5f98fc5b3085e9 (diff)
parenteac3e7032a48fb9f03f56af0cc2e2085d55af0d0 (diff)
Merge "Drop Heat related code from horizon"
Diffstat (limited to 'openstack_dashboard/dashboards/project/stacks/tables.py')
-rw-r--r--openstack_dashboard/dashboards/project/stacks/tables.py413
1 files changed, 0 insertions, 413 deletions
diff --git a/openstack_dashboard/dashboards/project/stacks/tables.py b/openstack_dashboard/dashboards/project/stacks/tables.py
deleted file mode 100644
index 96391ab..0000000
--- a/openstack_dashboard/dashboards/project/stacks/tables.py
+++ /dev/null
@@ -1,413 +0,0 @@
1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13from django.core import urlresolvers
14from django.http import Http404
15from django.template.defaultfilters import title
16from django.utils.translation import pgettext_lazy
17from django.utils.translation import ugettext_lazy as _
18from django.utils.translation import ungettext_lazy
19from heatclient import exc
20
21from horizon import exceptions
22from horizon import messages
23from horizon import tables
24from horizon.utils import filters
25
26from openstack_dashboard import api
27from openstack_dashboard.dashboards.project.stacks import mappings
28
29
30class LaunchStack(tables.LinkAction):
31 name = "launch"
32 verbose_name = _("Launch Stack")
33 url = "horizon:project:stacks:select_template"
34 classes = ("ajax-modal",)
35 icon = "plus"
36 policy_rules = (("orchestration", "stacks:validate_template"),
37 ("orchestration", "stacks:create"),)
38
39
40class PreviewStack(tables.LinkAction):
41 name = "preview"
42 verbose_name = _("Preview Stack")
43 url = "horizon:project:stacks:preview_template"
44 classes = ("ajax-modal",)
45 icon = "eye"
46 policy_rules = (("orchestration", "stacks:validate_template"),
47 ("orchestration", "stacks:preview"),)
48
49
50class CheckStack(tables.BatchAction):
51 name = "check"
52 verbose_name = _("Check Stack")
53 policy_rules = (("orchestration", "actions:action"),)
54 icon = "check-square"
55
56 @staticmethod
57 def action_present(count):
58 return ungettext_lazy(
59 u"Check Stack",
60 u"Check Stacks",
61 count
62 )
63
64 @staticmethod
65 def action_past(count):
66 return ungettext_lazy(
67 u"Checked Stack",
68 u"Checked Stacks",
69 count
70 )
71
72 def action(self, request, stack_id):
73 api.heat.action_check(request, stack_id)
74
75
76class SuspendStack(tables.BatchAction):
77 name = "suspend"
78 verbose_name = _("Suspend Stack")
79 policy_rules = (("orchestration", "actions:action"),)
80 icon = "pause"
81
82 @staticmethod
83 def action_present(count):
84 return ungettext_lazy(
85 u"Suspend Stack",
86 u"Suspend Stacks",
87 count
88 )
89
90 @staticmethod
91 def action_past(count):
92 return ungettext_lazy(
93 u"Suspended Stack",
94 u"Suspended Stacks",
95 count
96 )
97
98 def action(self, request, stack_id):
99 try:
100 api.heat.action_suspend(request, stack_id)
101 except Exception:
102 msg = _('Failed to suspend stack.')
103 exceptions.handle(request, msg)
104
105
106class ResumeStack(tables.BatchAction):
107 name = "resume"
108 verbose_name = _("Resume Stack")
109 policy_rules = (("orchestration", "actions:action"),)
110 icon = "play"
111
112 @staticmethod
113 def action_present(count):
114 return ungettext_lazy(
115 u"Resume Stack",
116 u"Resume Stacks",
117 count
118 )
119
120 @staticmethod
121 def action_past(count):
122 return ungettext_lazy(
123 u"Resumed Stack",
124 u"Resumed Stacks",
125 count
126 )
127
128 def action(self, request, stack_id):
129 try:
130 api.heat.action_resume(request, stack_id)
131 except Exception:
132 msg = _('Failed to resume stack.')
133 exceptions.handle(request, msg)
134
135
136class ChangeStackTemplate(tables.LinkAction):
137 name = "edit"
138 verbose_name = _("Change Stack Template")
139 url = "horizon:project:stacks:change_template"
140 classes = ("ajax-modal",)
141 icon = "pencil"
142
143 def get_link_url(self, stack):
144 return urlresolvers.reverse(self.url, args=[stack.id])
145
146
147class DeleteStack(tables.DeleteAction):
148 @staticmethod
149 def action_present(count):
150 return ungettext_lazy(
151 u"Delete Stack",
152 u"Delete Stacks",
153 count
154 )
155
156 @staticmethod
157 def action_past(count):
158 return ungettext_lazy(
159 u"Deleted Stack",
160 u"Deleted Stacks",
161 count
162 )
163
164 policy_rules = (("orchestration", "stacks:delete"),)
165
166 def delete(self, request, stack_id):
167 try:
168 api.heat.stack_delete(request, stack_id)
169 except Exception:
170 msg = _('Failed to delete stack.')
171 exceptions.handle(request, msg)
172
173 def allowed(self, request, stack):
174 if stack is not None:
175 return stack.stack_status != 'DELETE_COMPLETE'
176 return True
177
178
179class StacksUpdateRow(tables.Row):
180 ajax = True
181
182 def can_be_selected(self, datum):
183 return datum.stack_status != 'DELETE_COMPLETE'
184
185 def get_data(self, request, stack_id):
186 try:
187 stack = api.heat.stack_get(request, stack_id)
188 if stack.stack_status == 'DELETE_COMPLETE':
189 # returning 404 to the ajax call removes the
190 # row from the table on the ui
191 raise Http404
192 return stack
193 except Http404:
194 raise
195 except Exception as e:
196 messages.error(request, e)
197 raise
198
199
200class StacksFilterAction(tables.FilterAction):
201 filter_type = 'server'
202 filter_choices = (('name', _('Stack Name ='), True, _('Case-sensitive')),
203 ('id', _('Stack ID ='), True),
204 ('status', _('Status ='), True))
205
206
207class StacksTable(tables.DataTable):
208 STATUS_CHOICES = (
209 ("Complete", True),
210 ("Failed", False),
211 )
212 STACK_STATUS_DISPLAY_CHOICES = (
213 ("init_in_progress", pgettext_lazy("current status of stack",
214 u"Init In Progress")),
215 ("init_complete", pgettext_lazy("current status of stack",
216 u"Init Complete")),
217 ("init_failed", pgettext_lazy("current status of stack",
218 u"Init Failed")),
219 ("create_in_progress", pgettext_lazy("current status of stack",
220 u"Create In Progress")),
221 ("create_complete", pgettext_lazy("current status of stack",
222 u"Create Complete")),
223 ("create_failed", pgettext_lazy("current status of stack",
224 u"Create Failed")),
225 ("delete_in_progress", pgettext_lazy("current status of stack",
226 u"Delete In Progress")),
227 ("delete_complete", pgettext_lazy("current status of stack",
228 u"Delete Complete")),
229 ("delete_failed", pgettext_lazy("current status of stack",
230 u"Delete Failed")),
231 ("update_in_progress", pgettext_lazy("current status of stack",
232 u"Update In Progress")),
233 ("update_complete", pgettext_lazy("current status of stack",
234 u"Update Complete")),
235 ("update_failed", pgettext_lazy("current status of stack",
236 u"Update Failed")),
237 ("rollback_in_progress", pgettext_lazy("current status of stack",
238 u"Rollback In Progress")),
239 ("rollback_complete", pgettext_lazy("current status of stack",
240 u"Rollback Complete")),
241 ("rollback_failed", pgettext_lazy("current status of stack",
242 u"Rollback Failed")),
243 ("suspend_in_progress", pgettext_lazy("current status of stack",
244 u"Suspend In Progress")),
245 ("suspend_complete", pgettext_lazy("current status of stack",
246 u"Suspend Complete")),
247 ("suspend_failed", pgettext_lazy("current status of stack",
248 u"Suspend Failed")),
249 ("resume_in_progress", pgettext_lazy("current status of stack",
250 u"Resume In Progress")),
251 ("resume_complete", pgettext_lazy("current status of stack",
252 u"Resume Complete")),
253 ("resume_failed", pgettext_lazy("current status of stack",
254 u"Resume Failed")),
255 ("adopt_in_progress", pgettext_lazy("current status of stack",
256 u"Adopt In Progress")),
257 ("adopt_complete", pgettext_lazy("current status of stack",
258 u"Adopt Complete")),
259 ("adopt_failed", pgettext_lazy("current status of stack",
260 u"Adopt Failed")),
261 ("snapshot_in_progress", pgettext_lazy("current status of stack",
262 u"Snapshot In Progress")),
263 ("snapshot_complete", pgettext_lazy("current status of stack",
264 u"Snapshot Complete")),
265 ("snapshot_failed", pgettext_lazy("current status of stack",
266 u"Snapshot Failed")),
267 ("check_in_progress", pgettext_lazy("current status of stack",
268 u"Check In Progress")),
269 ("check_complete", pgettext_lazy("current status of stack",
270 u"Check Complete")),
271 ("check_failed", pgettext_lazy("current status of stack",
272 u"Check Failed")),
273 )
274 name = tables.Column("stack_name",
275 verbose_name=_("Stack Name"),
276 link="horizon:project:stacks:detail",)
277 created = tables.Column("creation_time",
278 verbose_name=_("Created"),
279 filters=(filters.parse_isotime,
280 filters.timesince_sortable),
281 attrs={'data-type': 'timesince'})
282 updated = tables.Column("updated_time",
283 verbose_name=_("Updated"),
284 filters=(filters.parse_isotime,
285 filters.timesince_or_never))
286 status = tables.Column("status",
287 hidden=True,
288 status=True,
289 status_choices=STATUS_CHOICES)
290
291 stack_status = tables.Column("stack_status",
292 verbose_name=_("Status"),
293 display_choices=STACK_STATUS_DISPLAY_CHOICES)
294
295 def get_object_display(self, stack):
296 return stack.stack_name
297
298 class Meta(object):
299 name = "stacks"
300 verbose_name = _("Stacks")
301 pagination_param = 'stack_marker'
302 status_columns = ["status", ]
303 row_class = StacksUpdateRow
304 table_actions_menu = (CheckStack,
305 SuspendStack,
306 ResumeStack,)
307 table_actions = (LaunchStack,
308 PreviewStack,
309 DeleteStack,
310 StacksFilterAction,)
311 row_actions = (CheckStack,
312 SuspendStack,
313 ResumeStack,
314 ChangeStackTemplate,
315 DeleteStack,)
316
317
318def get_resource_url(obj):
319 if obj.physical_resource_id == obj.stack_id:
320 return None
321 return urlresolvers.reverse('horizon:project:stacks:resource',
322 args=(obj.stack_id, obj.resource_name))
323
324
325class EventsTable(tables.DataTable):
326
327 logical_resource = tables.Column('resource_name',
328 verbose_name=_("Stack Resource"),
329 link=get_resource_url)
330 physical_resource = tables.Column('physical_resource_id',
331 verbose_name=_("Resource"))
332 timestamp = tables.Column('event_time',
333 verbose_name=_("Time Since Event"),
334 filters=(filters.parse_isotime,
335 filters.timesince_or_never))
336 status = tables.Column("resource_status",
337 filters=(title, filters.replace_underscores),
338 verbose_name=_("Status"),)
339
340 statusreason = tables.Column("resource_status_reason",
341 verbose_name=_("Status Reason"),)
342
343 class Meta(object):
344 name = "events"
345 verbose_name = _("Stack Events")
346
347
348class ResourcesUpdateRow(tables.Row):
349 ajax = True
350
351 def get_data(self, request, resource_name):
352 try:
353 stack = self.table.stack
354 stack_identifier = '%s/%s' % (stack.stack_name, stack.id)
355 return api.heat.resource_get(
356 request, stack_identifier, resource_name)
357 except exc.HTTPNotFound:
358 # returning 404 to the ajax call removes the
359 # row from the table on the ui
360 raise Http404
361 except Exception as e:
362 messages.error(request, e)
363
364
365class ResourcesTable(tables.DataTable):
366 class StatusColumn(tables.Column):
367 def get_raw_data(self, datum):
368 return datum.resource_status.partition("_")[2]
369
370 STATUS_CHOICES = (
371 ("Complete", True),
372 ("Failed", False),
373 )
374 STATUS_DISPLAY_CHOICES = StacksTable.STACK_STATUS_DISPLAY_CHOICES
375
376 logical_resource = tables.Column('resource_name',
377 verbose_name=_("Stack Resource"),
378 link=get_resource_url)
379 physical_resource = tables.Column('physical_resource_id',
380 verbose_name=_("Resource"),
381 link=mappings.resource_to_url)
382 resource_type = tables.Column("resource_type",
383 verbose_name=_("Stack Resource Type"),)
384 updated_time = tables.Column('updated_time',
385 verbose_name=_("Date Updated"),
386 filters=(filters.parse_isotime,
387 filters.timesince_or_never))
388 status = tables.Column("resource_status",
389 verbose_name=_("Status"),
390 display_choices=STATUS_DISPLAY_CHOICES)
391
392 statusreason = tables.Column("resource_status_reason",
393 verbose_name=_("Status Reason"),)
394
395 status_hidden = StatusColumn("status",
396 hidden=True,
397 status=True,
398 status_choices=STATUS_CHOICES)
399
400 def __init__(self, request, data=None,
401 needs_form_wrapper=None, **kwargs):
402 super(ResourcesTable, self).__init__(
403 request, data, needs_form_wrapper, **kwargs)
404 self.stack = kwargs['stack']
405
406 def get_object_id(self, datum):
407 return datum.resource_name
408
409 class Meta(object):
410 name = "resources"
411 verbose_name = _("Stack Resources")
412 status_columns = ["status_hidden", ]
413 row_class = ResourcesUpdateRow