Merge "Support update volume type public status"
This commit is contained in:
commit
e156c0b9d9
@ -643,14 +643,17 @@ def volume_type_list(request):
|
||||
return cinderclient(request).volume_types.list()
|
||||
|
||||
|
||||
def volume_type_create(request, name, description=None):
|
||||
return cinderclient(request).volume_types.create(name, description)
|
||||
def volume_type_create(request, name, description=None, is_public=True):
|
||||
return cinderclient(request).volume_types.create(name, description,
|
||||
is_public)
|
||||
|
||||
|
||||
def volume_type_update(request, volume_type_id, name=None, description=None):
|
||||
def volume_type_update(request, volume_type_id, name=None, description=None,
|
||||
is_public=None):
|
||||
return cinderclient(request).volume_types.update(volume_type_id,
|
||||
name,
|
||||
description)
|
||||
description,
|
||||
is_public)
|
||||
|
||||
|
||||
@memoized
|
||||
|
@ -15,6 +15,6 @@
|
||||
</div>
|
||||
<div class="right">
|
||||
<h3>{% trans "Description:" %}</h3>
|
||||
<p>{% trans "Modify volume type name and description." %}</p>
|
||||
<p>{% trans "Modify volume type name, description, and public status." %}</p>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
@ -28,6 +28,12 @@ class CreateVolumeType(forms.SelfHandlingForm):
|
||||
widget=forms.Textarea(attrs={'rows': 4}),
|
||||
label=_("Description"),
|
||||
required=False)
|
||||
is_public = forms.BooleanField(
|
||||
label=_("Public"),
|
||||
initial=True,
|
||||
required=False,
|
||||
help_text=_("By default, volume type is created as public. To "
|
||||
"create a private volume type, uncheck this field."))
|
||||
|
||||
def clean_name(self):
|
||||
cleaned_name = self.cleaned_data['name']
|
||||
@ -42,7 +48,8 @@ class CreateVolumeType(forms.SelfHandlingForm):
|
||||
volume_type = cinder.volume_type_create(
|
||||
request,
|
||||
data['name'],
|
||||
data['vol_type_description'])
|
||||
data['vol_type_description'],
|
||||
data['is_public'])
|
||||
messages.success(request, _('Successfully created volume type: %s')
|
||||
% data['name'])
|
||||
return volume_type
|
||||
@ -262,6 +269,10 @@ class EditVolumeType(forms.SelfHandlingForm):
|
||||
widget=forms.Textarea(attrs={'rows': 4}),
|
||||
label=_("Description"),
|
||||
required=False)
|
||||
is_public = forms.BooleanField(label=_("Public"), required=False,
|
||||
help_text=_(
|
||||
"To make volume type private, uncheck "
|
||||
"this field."))
|
||||
|
||||
def clean_name(self):
|
||||
cleaned_name = self.cleaned_data['name']
|
||||
@ -277,7 +288,8 @@ class EditVolumeType(forms.SelfHandlingForm):
|
||||
cinder.volume_type_update(request,
|
||||
volume_type_id,
|
||||
data['name'],
|
||||
data['description'])
|
||||
data['description'],
|
||||
data['is_public'])
|
||||
message = _('Successfully updated volume type.')
|
||||
messages.success(request, message)
|
||||
return True
|
||||
|
@ -203,12 +203,14 @@ class UpdateCell(tables.UpdateAction):
|
||||
setattr(vol_type_obj, cell_name, new_cell_value)
|
||||
name_value = getattr(vol_type_obj, 'name', None)
|
||||
desc_value = getattr(vol_type_obj, 'description', None)
|
||||
public_value = getattr(vol_type_obj, 'public', None)
|
||||
|
||||
cinder.volume_type_update(
|
||||
request,
|
||||
volume_type_id,
|
||||
name=name_value,
|
||||
description=desc_value)
|
||||
description=desc_value,
|
||||
is_public=public_value)
|
||||
except Exception as ex:
|
||||
if ex.code and ex.code == 409:
|
||||
error_message = _('New name conflicts with another '
|
||||
@ -239,6 +241,12 @@ class VolumeTypesTable(tables.DataTable):
|
||||
verbose_name=_("Encryption"),
|
||||
link="horizon:admin:volumes:volume_types:"
|
||||
"type_encryption_detail")
|
||||
public = tables.Column("is_public",
|
||||
verbose_name=_("Public"),
|
||||
filters=(filters.yesno, filters.capfirst),
|
||||
update_action=UpdateCell,
|
||||
form_field=forms.BooleanField(
|
||||
label=_('Public'), required=False))
|
||||
|
||||
def get_object_display(self, vol_type):
|
||||
return vol_type.name
|
||||
|
@ -26,11 +26,13 @@ class VolumeTypeTests(test.BaseAdminViewTests):
|
||||
@test.create_stubs({cinder: ('volume_type_create',)})
|
||||
def test_create_volume_type(self):
|
||||
formData = {'name': 'volume type 1',
|
||||
'vol_type_description': 'test desc'}
|
||||
'vol_type_description': 'test desc',
|
||||
'is_public': True}
|
||||
cinder.volume_type_create(
|
||||
IsA(http.HttpRequest),
|
||||
formData['name'],
|
||||
formData['vol_type_description']).AndReturn(
|
||||
formData['vol_type_description'],
|
||||
formData['is_public']).AndReturn(
|
||||
self.cinder_volume_types.first())
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@ -43,17 +45,19 @@ class VolumeTypeTests(test.BaseAdminViewTests):
|
||||
|
||||
@test.create_stubs({cinder: ('volume_type_get',
|
||||
'volume_type_update')})
|
||||
def test_update_volume_type(self):
|
||||
def _test_update_volume_type(self, is_public):
|
||||
volume_type = self.cinder_volume_types.first()
|
||||
formData = {'name': volume_type.name,
|
||||
'description': 'test desc updated'}
|
||||
'description': 'test desc updated',
|
||||
'is_public': is_public}
|
||||
volume_type = cinder.volume_type_get(
|
||||
IsA(http.HttpRequest), volume_type.id).AndReturn(volume_type)
|
||||
cinder.volume_type_update(
|
||||
IsA(http.HttpRequest),
|
||||
volume_type.id,
|
||||
formData['name'],
|
||||
formData['description']).AndReturn(volume_type)
|
||||
formData['description'],
|
||||
formData['is_public']).AndReturn(volume_type)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
url = reverse('horizon:admin:volumes:volume_types:update_type',
|
||||
@ -63,6 +67,12 @@ class VolumeTypeTests(test.BaseAdminViewTests):
|
||||
redirect = reverse('horizon:admin:volumes:volume_types_tab')
|
||||
self.assertRedirectsNoFollow(res, redirect)
|
||||
|
||||
def test_update_volume_type_public_true(self):
|
||||
self._test_update_volume_type(True)
|
||||
|
||||
def test_update_volume_type_public_false(self):
|
||||
self._test_update_volume_type(False)
|
||||
|
||||
@test.create_stubs({api.nova: ('server_list',),
|
||||
cinder: ('volume_list',
|
||||
'volume_type_list_with_qos_associations',
|
||||
|
@ -137,6 +137,7 @@ class EditVolumeTypeView(forms.ModalFormView):
|
||||
volume_type = self.get_data()
|
||||
return {'id': self.kwargs['type_id'],
|
||||
'name': volume_type.name,
|
||||
'is_public': getattr(volume_type, 'is_public', True),
|
||||
'description': getattr(volume_type, 'description', "")}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user