diff options
| author | Chris Behrens <cbehrens@codestud.com> | 2011-07-12 16:13:01 -0700 |
|---|---|---|
| committer | Chris Behrens <cbehrens@codestud.com> | 2011-07-12 16:13:01 -0700 |
| commit | e547f4bde48a0142fbdb407a4c51f4b6f8fa56e2 (patch) | |
| tree | 36b98fac8f2890294d0a1fb42f72545652227fb7 /nova/compute | |
| parent | bbd8f482b916168871d1d83192b354355858e77c (diff) | |
| parent | 11611716e30f368df77816b40c4c77de0e0e047f (diff) | |
merged trunk
Diffstat (limited to 'nova/compute')
| -rw-r--r-- | nova/compute/api.py | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py index 511c17e7a..f795e345a 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -932,13 +932,24 @@ class API(base.Base): self.db.instance_update(context, instance_id, {'host': migration_ref['dest_compute'], }) - def resize(self, context, instance_id, flavor_id): - """Resize a running instance.""" + def resize(self, context, instance_id, flavor_id=None): + """Resize (ie, migrate) a running instance. + + If flavor_id is None, the process is considered a migration, keeping + the original flavor_id. If flavor_id is not None, the instance should + be migrated to a new host and resized to the new flavor_id. + """ instance = self.db.instance_get(context, instance_id) current_instance_type = instance['instance_type'] - new_instance_type = self.db.instance_type_get_by_flavor_id( - context, flavor_id) + # If flavor_id is not provided, only migrate the instance. + if not flavor_id: + LOG.debug(_("flavor_id is None. Assuming migration.")) + new_instance_type = current_instance_type + else: + new_instance_type = self.db.instance_type_get_by_flavor_id( + context, flavor_id) + current_instance_type_name = current_instance_type['name'] new_instance_type_name = new_instance_type['name'] LOG.debug(_("Old instance type %(current_instance_type_name)s, " @@ -952,7 +963,8 @@ class API(base.Base): if current_memory_mb > new_memory_mb: raise exception.ApiError(_("Invalid flavor: cannot downsize" "instances")) - if current_memory_mb == new_memory_mb: + + if (current_memory_mb == new_memory_mb) and flavor_id: raise exception.ApiError(_("Invalid flavor: cannot use" "the same flavor. ")) @@ -960,7 +972,7 @@ class API(base.Base): {"method": "prep_resize", "args": {"topic": FLAGS.compute_topic, "instance_id": instance_id, - "flavor_id": flavor_id}}) + "flavor_id": new_instance_type['id']}}) @scheduler_api.reroute_compute("add_fixed_ip") def add_fixed_ip(self, context, instance_id, network_id): |
