summaryrefslogtreecommitdiff
path: root/openstack_dashboard/dashboards/project/stacks/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'openstack_dashboard/dashboards/project/stacks/views.py')
-rw-r--r--openstack_dashboard/dashboards/project/stacks/views.py358
1 files changed, 0 insertions, 358 deletions
diff --git a/openstack_dashboard/dashboards/project/stacks/views.py b/openstack_dashboard/dashboards/project/stacks/views.py
deleted file mode 100644
index f5d47ec..0000000
--- a/openstack_dashboard/dashboards/project/stacks/views.py
+++ /dev/null
@@ -1,358 +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
13import json
14from operator import attrgetter
15
16import yaml
17
18from django.core.urlresolvers import reverse
19from django.core.urlresolvers import reverse_lazy
20from django.http import HttpResponse
21from django.utils.translation import ugettext_lazy as _
22import django.views.generic
23
24from horizon import exceptions
25from horizon import forms
26from horizon import tables
27from horizon import tabs
28from horizon.utils import memoized
29from horizon import views
30from openstack_dashboard import api
31from openstack_dashboard.dashboards.project.stacks \
32 import api as project_api
33from openstack_dashboard.dashboards.project.stacks \
34 import forms as project_forms
35from openstack_dashboard.dashboards.project.stacks \
36 import tables as project_tables
37from openstack_dashboard.dashboards.project.stacks \
38 import tabs as project_tabs
39
40
41class IndexView(tables.DataTableView):
42 table_class = project_tables.StacksTable
43 page_title = _("Stacks")
44
45 def __init__(self, *args, **kwargs):
46 super(IndexView, self).__init__(*args, **kwargs)
47 self._more = None
48
49 def has_prev_data(self, table):
50 return self._prev
51
52 def has_more_data(self, table):
53 return self._more
54
55 def get_data(self):
56 stacks = []
57 filters = self.get_filters()
58 prev_marker = self.request.GET.get(
59 project_tables.StacksTable._meta.prev_pagination_param)
60 if prev_marker is not None:
61 sort_dir = 'asc'
62 marker = prev_marker
63 else:
64 sort_dir = 'desc'
65 marker = self.request.GET.get(
66 project_tables.StacksTable._meta.pagination_param)
67 try:
68 stacks, self._more, self._prev = api.heat.stacks_list(
69 self.request,
70 marker=marker,
71 paginate=True,
72 sort_dir=sort_dir,
73 filters=filters)
74 if prev_marker is not None:
75 stacks = sorted(stacks, key=attrgetter('creation_time'),
76 reverse=True)
77 except Exception:
78 self._prev = False
79 self._more = False
80 msg = _('Unable to retrieve stack list.')
81 exceptions.handle(self.request, msg)
82 return stacks
83
84
85class SelectTemplateView(forms.ModalFormView):
86 template_name = 'project/stacks/select_template.html'
87 form_id = "select_template"
88 form_class = project_forms.TemplateForm
89 submit_label = _("Next")
90 submit_url = reverse_lazy("horizon:project:stacks:select_template")
91 success_url = reverse_lazy('horizon:project:stacks:launch')
92 page_title = _("Select Template")
93
94 def get_initial(self):
95 initial = {}
96 for name in [
97 'template_url',
98 'template_source',
99 'template_data',
100 'environment_source',
101 'environment_data'
102 ]:
103 tmp = self.request.GET.get(name)
104 if tmp:
105 initial[name] = tmp
106 return initial
107
108 def get_form_kwargs(self):
109 kwargs = super(SelectTemplateView, self).get_form_kwargs()
110 kwargs['next_view'] = CreateStackView
111 return kwargs
112
113
114class ChangeTemplateView(forms.ModalFormView):
115 template_name = 'project/stacks/change_template.html'
116 form_id = "change_template"
117 form_class = project_forms.ChangeTemplateForm
118 submit_label = _("Next")
119 submit_url = "horizon:project:stacks:change_template"
120 cancel_url = reverse_lazy('horizon:project:stacks:index')
121 success_url = reverse_lazy('horizon:project:stacks:edit_stack')
122 page_title = _("Change Template")
123
124 def get_context_data(self, **kwargs):
125 context = super(ChangeTemplateView, self).get_context_data(**kwargs)
126 args = (self.get_object().id,)
127 context['submit_url'] = reverse(self.submit_url, args=args)
128 return context
129
130 @memoized.memoized_method
131 def get_object(self):
132 stack_id = self.kwargs['stack_id']
133 try:
134 self._stack = api.heat.stack_get(self.request, stack_id)
135 except Exception:
136 msg = _("Unable to retrieve stack.")
137 redirect = reverse('horizon:project:stacks:index')
138 exceptions.handle(self.request, msg, redirect=redirect)
139 return self._stack
140
141 def get_initial(self):
142 stack = self.get_object()
143 return {'stack_id': stack.id,
144 'stack_name': stack.stack_name
145 }
146
147 def get_form_kwargs(self):
148 kwargs = super(ChangeTemplateView, self).get_form_kwargs()
149 kwargs['next_view'] = EditStackView
150 return kwargs
151
152
153class PreviewTemplateView(forms.ModalFormView):
154 template_name = 'project/stacks/preview_template.html'
155 form_id = "preview_template"
156 form_class = project_forms.PreviewTemplateForm
157 submit_label = _("Next")
158 submit_url = reverse_lazy('horizon:project:stacks:preview_template')
159 success_url = reverse_lazy('horizon:project:stacks:preview')
160 page_title = _("Preview Template")
161
162 def get_form_kwargs(self):
163 kwargs = super(PreviewTemplateView, self).get_form_kwargs()
164 kwargs['next_view'] = PreviewStackView
165 return kwargs
166
167
168class CreateStackView(forms.ModalFormView):
169 template_name = 'project/stacks/create.html'
170 form_id = "launch_stack"
171 form_class = project_forms.CreateStackForm
172 submit_label = _("Launch")
173 submit_url = reverse_lazy("horizon:project:stacks:launch")
174 success_url = reverse_lazy('horizon:project:stacks:index')
175 page_title = _("Launch Stack")
176
177 def get_initial(self):
178 initial = {}
179 if 'environment_data' in self.kwargs:
180 initial['environment_data'] = self.kwargs['environment_data']
181 if 'parameters' in self.kwargs:
182 initial['parameters'] = json.dumps(self.kwargs['parameters'])
183 return initial
184
185 def get_form_kwargs(self):
186 kwargs = super(CreateStackView, self).get_form_kwargs()
187 if 'parameters' in self.kwargs:
188 kwargs['parameters'] = self.kwargs['parameters']
189 else:
190 data = json.loads(self.request.POST['parameters'])
191 kwargs['parameters'] = data
192 return kwargs
193
194
195# edit stack parameters, coming from template selector
196class EditStackView(CreateStackView):
197 template_name = 'project/stacks/update.html'
198 form_id = "update_stack"
199 form_class = project_forms.EditStackForm
200 submit_label = _("Update")
201 submit_url = "horizon:project:stacks:edit_stack"
202 success_url = reverse_lazy('horizon:project:stacks:index')
203 page_title = _("Update Stack")
204
205 def get_initial(self):
206 initial = super(EditStackView, self).get_initial()
207
208 initial['stack'] = self.get_object()['stack']
209 if initial['stack']:
210 initial['stack_id'] = initial['stack'].id
211 initial['stack_name'] = initial['stack'].stack_name
212
213 return initial
214
215 def get_context_data(self, **kwargs):
216 context = super(EditStackView, self).get_context_data(**kwargs)
217 args = (self.get_object()['stack'].id,)
218 context['submit_url'] = reverse(self.submit_url, args=args)
219 return context
220
221 @memoized.memoized_method
222 def get_object(self):
223 stack_id = self.kwargs['stack_id']
224 try:
225 stack = {}
226 stack['stack'] = api.heat.stack_get(self.request, stack_id)
227 stack['template'] = api.heat.template_get(self.request, stack_id)
228 self._stack = stack
229 except Exception:
230 msg = _("Unable to retrieve stack.")
231 redirect = reverse('horizon:project:stacks:index')
232 exceptions.handle(self.request, msg, redirect=redirect)
233 return self._stack
234
235
236class PreviewStackView(CreateStackView):
237 template_name = 'project/stacks/preview.html'
238 form_id = "preview_stack"
239 form_class = project_forms.PreviewStackForm
240 submit_label = _("Preview")
241 submit_url = reverse_lazy('horizon:project:stacks:preview')
242 success_url = reverse_lazy('horizon:project:stacks:index')
243 page_title = _("Preview Stack")
244
245 def get_form_kwargs(self):
246 kwargs = super(CreateStackView, self).get_form_kwargs()
247 kwargs['next_view'] = PreviewStackDetailsView
248 return kwargs
249
250
251class PreviewStackDetailsView(forms.ModalFormMixin, views.HorizonTemplateView):
252 template_name = 'project/stacks/preview_details.html'
253 page_title = _("Preview Stack Details")
254
255 def get_context_data(self, **kwargs):
256 context = super(
257 PreviewStackDetailsView, self).get_context_data(**kwargs)
258 context['stack_preview'] = self.kwargs['stack_preview'].to_dict()
259 return context
260
261
262class DetailView(tabs.TabView):
263 tab_group_class = project_tabs.StackDetailTabs
264 template_name = 'horizon/common/_detail.html'
265 page_title = "{{ stack.stack_name|default:stack.id }}"
266
267 def get_context_data(self, **kwargs):
268 context = super(DetailView, self).get_context_data(**kwargs)
269 stack = self.get_data(self.request, **kwargs)
270 table = project_tables.StacksTable(self.request)
271 context["stack"] = stack
272 context["url"] = self.get_redirect_url()
273 context["actions"] = table.render_row_actions(stack)
274 return context
275
276 @memoized.memoized_method
277 def get_data(self, request, **kwargs):
278 stack_id = kwargs['stack_id']
279 try:
280 stack = api.heat.stack_get(request, stack_id)
281 request.session['stack_id'] = stack.id
282 request.session['stack_name'] = stack.stack_name
283 return stack
284 except Exception:
285 msg = _("Unable to retrieve stack.")
286 exceptions.handle(request, msg, redirect=self.get_redirect_url())
287
288 @memoized.memoized_method
289 def get_template(self, request, **kwargs):
290 try:
291 stack_template = api.heat.template_get(
292 request,
293 kwargs['stack_id'])
294 return yaml.safe_dump(stack_template, indent=2)
295 except Exception:
296 msg = _("Unable to retrieve stack template.")
297 exceptions.handle(request, msg, redirect=self.get_redirect_url())
298
299 def get_tabs(self, request, **kwargs):
300 stack = self.get_data(request, **kwargs)
301 stack_template = self.get_template(request, **kwargs)
302 return self.tab_group_class(
303 request, stack=stack, stack_template=stack_template, **kwargs)
304
305 @staticmethod
306 def get_redirect_url():
307 return reverse('horizon:project:stacks:index')
308
309
310class ResourceView(tabs.TabView):
311 tab_group_class = project_tabs.ResourceDetailTabs
312 template_name = 'horizon/common/_detail.html'
313 page_title = "{{ resource.resource_name|"\
314 "default:resource.logical_resource_id }}"
315
316 def get_context_data(self, **kwargs):
317 context = super(ResourceView, self).get_context_data(**kwargs)
318 context["resource"] = self.get_data(self.request, **kwargs)
319 context["metadata"] = self.get_metadata(self.request, **kwargs)
320 return context
321
322 @memoized.memoized_method
323 def get_data(self, request, **kwargs):
324 try:
325 resource = api.heat.resource_get(
326 request,
327 kwargs['stack_id'],
328 kwargs['resource_name'])
329 return resource
330 except Exception:
331 msg = _("Unable to retrieve resource.")
332 redirect = reverse('horizon:project:stacks:index')
333 exceptions.handle(request, msg, redirect=redirect)
334
335 @memoized.memoized_method
336 def get_metadata(self, request, **kwargs):
337 try:
338 metadata = api.heat.resource_metadata_get(
339 request,
340 kwargs['stack_id'],
341 kwargs['resource_name'])
342 return json.dumps(metadata, indent=2)
343 except Exception:
344 msg = _("Unable to retrieve metadata.")
345 redirect = reverse('horizon:project:stacks:index')
346 exceptions.handle(request, msg, redirect=redirect)
347
348 def get_tabs(self, request, **kwargs):
349 resource = self.get_data(request, **kwargs)
350 metadata = self.get_metadata(request, **kwargs)
351 return self.tab_group_class(
352 request, resource=resource, metadata=metadata, **kwargs)
353
354
355class JSONView(django.views.generic.View):
356 def get(self, request, stack_id=''):
357 return HttpResponse(project_api.d3_data(request, stack_id=stack_id),
358 content_type="application/json")