Merge "Return a friendly error at flavor creation"
This commit is contained in:
commit
8734ea4977
@ -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 @@ class CreateFlavor(forms.SelfHandlingForm):
|
||||
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']
|
||||
|
@ -23,6 +23,7 @@ class FlavorsTests(test.BaseAdminViewTests):
|
||||
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')
|
||||
|
Loading…
Reference in New Issue
Block a user