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
5
# http://www.apache.org/licenses/LICENSE-2.0
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
13
from django.core.urlresolvers import reverse
14
from django.utils.translation import ugettext_lazy as _
16
from horizon import exceptions
17
from horizon import forms
18
from horizon import tables
20
from openstack_dashboard import api
22
from openstack_dashboard.dashboards.admin.volumes.extras \
23
import forms as project_forms
24
from openstack_dashboard.dashboards.admin.volumes.extras \
25
import tables as project_tables
28
class ExtraSpecMixin(object):
29
def get_context_data(self, **kwargs):
30
context = super(ExtraSpecMixin, self).get_context_data(**kwargs)
32
context['vol_type'] = api.cinder.volume_type_get(self.request,
33
self.kwargs['type_id'])
35
exceptions.handle(self.request,
36
_("Unable to retrieve volume type details."))
37
if 'key' in self.kwargs:
38
context['key'] = self.kwargs['key']
42
class IndexView(ExtraSpecMixin, forms.ModalFormMixin, tables.DataTableView):
43
table_class = project_tables.ExtraSpecsTable
44
template_name = 'admin/volumes/extras/index.html'
48
type_id = self.kwargs['type_id']
49
extras_list = api.cinder.volume_type_extra_get(self.request,
51
extras_list.sort(key=lambda es: (es.key,))
54
exceptions.handle(self.request,
55
_('Unable to retrieve extra spec list.'))
59
class CreateView(ExtraSpecMixin, forms.ModalFormView):
60
form_class = project_forms.CreateExtraSpec
61
template_name = 'admin/volumes/extras/create.html'
63
def get_initial(self):
64
return {'type_id': self.kwargs['type_id']}
66
def get_success_url(self):
67
return "/admin/volumes/%s/extras/" % (self.kwargs['type_id'])
70
class EditView(ExtraSpecMixin, forms.ModalFormView):
71
form_class = project_forms.EditExtraSpec
72
template_name = 'admin/volumes/extras/edit.html'
73
success_url = 'horizon:admin:volumes:extras:index'
75
def get_success_url(self):
76
return reverse(self.success_url,
77
args=(self.kwargs['type_id'],))
79
def get_initial(self):
80
type_id = self.kwargs['type_id']
81
key = self.kwargs['key']
83
extra_specs = api.cinder.volume_type_extra_get(self.request,
88
exceptions.handle(self.request,
89
_('Unable to retrieve volume type extra spec '
91
return {'type_id': type_id,
93
'value': extra_specs.get(key, '')}