Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge "Return a friendly error at flavor creation"

  • Loading branch information...
commit 8734ea4977b03a2862615f5e0289b57269fee24d 2 parents e6d3c23 + dcda694
authored November 21, 2012 openstack-gerrit committed November 21, 2012
21  openstack_dashboard/dashboards/admin/flavors/forms.py
@@ -40,6 +40,24 @@ class CreateFlavor(forms.SelfHandlingForm):
40 40
     disk_gb = forms.IntegerField(label=_("Root Disk GB"))
41 41
     eph_gb = forms.IntegerField(label=_("Ephemeral Disk GB"))
42 42
 
  43
+    def clean_name(self):
  44
+        name = self.cleaned_data.get('name')
  45
+        try:
  46
+            flavors = api.nova.flavor_list(self.request)
  47
+        except:
  48
+            flavors = []
  49
+            msg = _('Unable to get flavor list')
  50
+            exceptions.check_message(["Connection", "refused"], msg)
  51
+            raise
  52
+        if flavors is not None:
  53
+            for flavor in flavors:
  54
+                if flavor.name == name:
  55
+                    raise forms.ValidationError(
  56
+                      _('The name "%s" is already used by another flavor.')
  57
+                      % name
  58
+                    )
  59
+        return name
  60
+
43 61
     def handle(self, request, data):
44 62
         try:
45 63
             flavor = api.nova.flavor_create(request,
@@ -59,6 +77,9 @@ def handle(self, request, data):
59 77
 class EditFlavor(CreateFlavor):
60 78
     flavor_id = forms.IntegerField(widget=forms.widgets.HiddenInput)
61 79
 
  80
+    def clean_name(self):
  81
+        return self.cleaned_data['name']
  82
+
62 83
     def handle(self, request, data):
63 84
         try:
64 85
             flavor_id = data['flavor_id']
1  openstack_dashboard/dashboards/admin/flavors/tests.py
@@ -23,6 +23,7 @@ def test_create_new_flavor_when_none_exist(self):
23 23
                                flavor.disk,
24 24
                                IsA(uuid.uuid4()),
25 25
                                ephemeral=eph).AndReturn(flavor)
  26
+        api.nova.flavor_list(IsA(http.HttpRequest))
26 27
         self.mox.ReplayAll()
27 28
 
28 29
         url = reverse('horizon:admin:flavors:create')

0 notes on commit 8734ea4

Please sign in to comment.
Something went wrong with that request. Please try again.