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
14
Admin views for managing volumes.
17
from django.core.urlresolvers import reverse
18
from django.utils.translation import ugettext_lazy as _
20
from horizon import exceptions
21
from horizon import forms
22
from horizon.utils import memoized
24
from openstack_dashboard import api
25
from openstack_dashboard.dashboards.admin.volumes.volume_types \
26
import forms as volume_type_forms
27
from openstack_dashboard.dashboards.admin.volumes.volumes \
28
import forms as volumes_forms
31
class CreateVolumeTypeView(forms.ModalFormView):
32
form_class = volumes_forms.CreateVolumeType
33
template_name = 'admin/volumes/volume_types/create_volume_type.html'
34
success_url = 'horizon:admin:volumes:volume_types_tab'
36
def get_success_url(self):
37
return reverse(self.success_url)
40
class CreateQosSpecView(forms.ModalFormView):
41
form_class = volumes_forms.CreateQosSpec
42
template_name = 'admin/volumes/volume_types/create_qos_spec.html'
43
success_url = 'horizon:admin:volumes:volume_types_tab'
45
def get_success_url(self):
46
return reverse(self.success_url)
49
class EditQosSpecConsumerView(forms.ModalFormView):
50
form_class = volume_type_forms.EditQosSpecConsumer
51
template_name = 'admin/volumes/volume_types/edit_qos_spec_consumer.html'
52
success_url = 'horizon:admin:volumes:volume_types_tab'
54
def get_success_url(self):
55
return reverse(self.success_url)
57
def get_context_data(self, **kwargs):
58
context = super(EditQosSpecConsumerView, self).\
59
get_context_data(**kwargs)
60
context['qos_spec_id'] = self.kwargs["qos_spec_id"]
63
@memoized.memoized_method
64
def get_object(self, *args, **kwargs):
65
qos_spec_id = self.kwargs['qos_spec_id']
67
self._object = api.cinder.qos_spec_get(self.request, qos_spec_id)
69
msg = _('Unable to retrieve QOS Spec details.')
70
exceptions.handle(self.request, msg)
73
def get_initial(self):
74
qos_spec = self.get_object()
75
qos_spec_id = self.kwargs['qos_spec_id']
77
return {'qos_spec_id': qos_spec_id,
81
class ManageQosSpecAssociationView(forms.ModalFormView):
82
form_class = volume_type_forms.ManageQosSpecAssociation
83
template_name = 'admin/volumes/volume_types/associate_qos_spec.html'
84
success_url = 'horizon:admin:volumes:volume_types_tab'
86
def get_success_url(self):
87
return reverse(self.success_url)
89
def get_context_data(self, **kwargs):
90
context = super(ManageQosSpecAssociationView, self).\
91
get_context_data(**kwargs)
92
context['type_id'] = self.kwargs["type_id"]
95
@memoized.memoized_method
96
def get_object(self, *args, **kwargs):
97
type_id = self.kwargs['type_id']
99
self._object = api.cinder.volume_type_get(self.request, type_id)
101
msg = _('Unable to retrieve volume type details.')
102
exceptions.handle(self.request, msg)
105
@memoized.memoized_method
106
def get_qos_specs(self, *args, **kwargs):
108
return api.cinder.qos_spec_list(self.request)
110
exceptions.handle(self.request,
111
_('Unable to retrieve QOS Specs.'))
113
def find_current_qos_spec_association(self, vol_type_id):
114
qos_specs = self.get_qos_specs()
117
# find out which QOS Spec is currently associated with this
118
# volume type, if any
119
# NOTE - volume type can only have ONE QOS Spec association
120
for qos_spec in qos_specs:
122
api.cinder.qos_spec_get_associations(self.request,
124
for vtype in type_ids:
125
if vtype.id == vol_type_id:
129
exceptions.handle(self.request,
130
_('Unable to retrieve QOS Spec association.'))
134
def get_initial(self):
135
volume_type = self.get_object()
136
vol_type_id = self.kwargs['type_id']
138
cur_qos_spec_id = None
139
cur_qos_spec_name = None
141
qos_spec = self.find_current_qos_spec_association(vol_type_id)
143
cur_qos_spec_id = qos_spec.id
144
cur_qos_spec_name = qos_spec.name
146
return {'type_id': vol_type_id,
147
'name': getattr(volume_type, 'name', None),
148
'cur_qos_spec_id': cur_qos_spec_id,
149
'cur_qos_spec_name': cur_qos_spec_name,
150
'qos_specs': self.get_qos_specs()}