Merge "Updating Flavor Resize Restrictions"

This commit is contained in:
Jenkins 2015-03-30 15:02:38 +00:00 committed by Gerrit Code Review
commit 98734800f6

View File

@ -847,31 +847,28 @@ class Instance(BuiltInstance):
{'instance_id': self.id, 'flavor_id': new_flavor_id}) {'instance_id': self.id, 'flavor_id': new_flavor_id})
if self.db_info.cluster_id is not None: if self.db_info.cluster_id is not None:
raise exception.ClusterInstanceOperationNotSupported() raise exception.ClusterInstanceOperationNotSupported()
# Validate that the flavor can be found and that it isn't the same size
# as the current one. # Validate that the old and new flavor IDs are not the same, new flavor
# can be found and has ephemeral/volume support if required by the
# current flavor.
if self.flavor_id == new_flavor_id:
raise exception.BadRequest(_("The new flavor id must be different "
"than the current flavor id of '%s'.")
% self.flavor_id)
client = create_nova_client(self.context) client = create_nova_client(self.context)
try: try:
new_flavor = client.flavors.get(new_flavor_id) new_flavor = client.flavors.get(new_flavor_id)
except nova_exceptions.NotFound: except nova_exceptions.NotFound:
raise exception.FlavorNotFound(uuid=new_flavor_id) raise exception.FlavorNotFound(uuid=new_flavor_id)
old_flavor = client.flavors.get(self.flavor_id) old_flavor = client.flavors.get(self.flavor_id)
new_flavor_size = new_flavor.ram
old_flavor_size = old_flavor.ram
if self.volume_support: if self.volume_support:
if new_flavor.ephemeral != 0: if new_flavor.ephemeral != 0:
raise exception.LocalStorageNotSupported() raise exception.LocalStorageNotSupported()
if new_flavor_size == old_flavor_size:
raise exception.CannotResizeToSameSize()
elif self.device_path is not None: elif self.device_path is not None:
# ephemeral support enabled # ephemeral support enabled
if new_flavor.ephemeral == 0: if new_flavor.ephemeral == 0:
raise exception.LocalStorageNotSpecified(flavor=new_flavor_id) raise exception.LocalStorageNotSpecified(flavor=new_flavor_id)
if (new_flavor_size == old_flavor_size and
new_flavor.ephemeral == new_flavor.ephemeral):
raise exception.CannotResizeToSameSize()
elif new_flavor_size == old_flavor_size:
# uses local storage
raise exception.CannotResizeToSameSize()
# Set the task to RESIZING and begin the async call before returning. # Set the task to RESIZING and begin the async call before returning.
self.update_db(task_status=InstanceTasks.RESIZING) self.update_db(task_status=InstanceTasks.RESIZING)