Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge "Return a friendly error at flavor creation"

  • Loading branch information...
commit 8734ea4977b03a2862615f5e0289b57269fee24d 2 parents e6d3c23 + dcda694
Jenkins authored openstack-gerrit committed
View
21 openstack_dashboard/dashboards/admin/flavors/forms.py
@@ -40,6 +40,24 @@ class CreateFlavor(forms.SelfHandlingForm):
disk_gb = forms.IntegerField(label=_("Root Disk GB"))
eph_gb = forms.IntegerField(label=_("Ephemeral Disk GB"))
+ def clean_name(self):
+ name = self.cleaned_data.get('name')
+ try:
+ flavors = api.nova.flavor_list(self.request)
+ except:
+ flavors = []
+ msg = _('Unable to get flavor list')
+ exceptions.check_message(["Connection", "refused"], msg)
+ raise
+ if flavors is not None:
+ for flavor in flavors:
+ if flavor.name == name:
+ raise forms.ValidationError(
+ _('The name "%s" is already used by another flavor.')
+ % name
+ )
+ return name
+
def handle(self, request, data):
try:
flavor = api.nova.flavor_create(request,
@@ -59,6 +77,9 @@ def handle(self, request, data):
class EditFlavor(CreateFlavor):
flavor_id = forms.IntegerField(widget=forms.widgets.HiddenInput)
+ def clean_name(self):
+ return self.cleaned_data['name']
+
def handle(self, request, data):
try:
flavor_id = data['flavor_id']
View
1  openstack_dashboard/dashboards/admin/flavors/tests.py
@@ -23,6 +23,7 @@ def test_create_new_flavor_when_none_exist(self):
flavor.disk,
IsA(uuid.uuid4()),
ephemeral=eph).AndReturn(flavor)
+ api.nova.flavor_list(IsA(http.HttpRequest))
self.mox.ReplayAll()
url = reverse('horizon:admin:flavors:create')
Please sign in to comment.
Something went wrong with that request. Please try again.