Merge "Use UUIDs for flavor create/edit."
This commit is contained in:
commit
cd70bc9284
@ -19,6 +19,7 @@
|
||||
# under the License.
|
||||
|
||||
import logging
|
||||
import uuid
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
@ -39,22 +40,6 @@ class CreateFlavor(forms.SelfHandlingForm):
|
||||
disk_gb = forms.IntegerField(label=_("Root Disk GB"))
|
||||
eph_gb = forms.IntegerField(label=_("Ephemeral Disk GB"))
|
||||
|
||||
def _get_new_flavor_id(self):
|
||||
# TODO(gabriel): Get rid of this hack after flavor
|
||||
# id handling is improved in Nova's API.
|
||||
flavors = []
|
||||
try:
|
||||
flavors = api.nova.flavor_list(self.request)
|
||||
except:
|
||||
exceptions.handle(self.request,
|
||||
_("Unable to get unique ID for new flavor."))
|
||||
if flavors:
|
||||
largest_id = max(flavors, key=lambda f: f.id).id
|
||||
flavor_id = int(largest_id) + 1
|
||||
else:
|
||||
flavor_id = 1
|
||||
return flavor_id
|
||||
|
||||
def handle(self, request, data):
|
||||
try:
|
||||
flavor = api.nova.flavor_create(request,
|
||||
@ -62,7 +47,7 @@ class CreateFlavor(forms.SelfHandlingForm):
|
||||
data['memory_mb'],
|
||||
data['vcpus'],
|
||||
data['disk_gb'],
|
||||
self._get_new_flavor_id(),
|
||||
uuid.uuid4(),
|
||||
ephemeral=data['eph_gb'])
|
||||
msg = _('Created flavor "%s".') % data['name']
|
||||
messages.success(request, msg)
|
||||
@ -87,7 +72,7 @@ class EditFlavor(CreateFlavor):
|
||||
data['memory_mb'],
|
||||
data['vcpus'],
|
||||
data['disk_gb'],
|
||||
self._get_new_flavor_id(),
|
||||
uuid.uuid4(),
|
||||
ephemeral=data['eph_gb'])
|
||||
msg = _('Updated flavor "%s".') % data['name']
|
||||
messages.success(request, msg)
|
||||
|
@ -1,3 +1,5 @@
|
||||
import uuid
|
||||
|
||||
from django import http
|
||||
from django.core.urlresolvers import reverse
|
||||
from mox import IsA
|
||||
@ -14,13 +16,12 @@ class FlavorsTests(test.BaseAdminViewTests):
|
||||
self.mox.StubOutWithMock(api.nova, 'flavor_create')
|
||||
|
||||
# no pre-existing flavors
|
||||
api.nova.flavor_list(IsA(http.HttpRequest)).AndReturn([])
|
||||
api.nova.flavor_create(IsA(http.HttpRequest),
|
||||
flavor.name,
|
||||
flavor.ram,
|
||||
flavor.vcpus,
|
||||
flavor.disk,
|
||||
1, # Flavor id 1 because there are no others.
|
||||
IsA(uuid.uuid4()),
|
||||
ephemeral=eph).AndReturn(flavor)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@ -39,9 +40,7 @@ class FlavorsTests(test.BaseAdminViewTests):
|
||||
reverse("horizon:admin:flavors:index"))
|
||||
|
||||
def test_edit_flavor(self):
|
||||
flavors = self.flavors.list()
|
||||
flavor = self.flavors.first()
|
||||
next_id = int(max(flavors, key=lambda f: f.id).id) + 1
|
||||
eph = getattr(flavor, 'OS-FLV-EXT-DATA:ephemeral')
|
||||
self.mox.StubOutWithMock(api.nova, 'flavor_list')
|
||||
self.mox.StubOutWithMock(api.nova, 'flavor_get')
|
||||
@ -54,14 +53,12 @@ class FlavorsTests(test.BaseAdminViewTests):
|
||||
# POST
|
||||
api.nova.flavor_get(IsA(http.HttpRequest), flavor.id).AndReturn(flavor)
|
||||
api.nova.flavor_delete(IsA(http.HttpRequest), int(flavor.id))
|
||||
api.nova.flavor_list(IsA(http.HttpRequest)) \
|
||||
.AndReturn(flavors)
|
||||
api.nova.flavor_create(IsA(http.HttpRequest),
|
||||
flavor.name,
|
||||
flavor.ram,
|
||||
flavor.vcpus + 1,
|
||||
flavor.disk,
|
||||
next_id,
|
||||
IsA(uuid.uuid4()),
|
||||
ephemeral=eph).AndReturn(flavor)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user