diff options
| author | iccha.sethi <iccha.sethi@rackspace.com> | 2012-09-14 14:48:35 -0400 |
|---|---|---|
| committer | Chris Behrens <cbehrens@codestud.com> | 2013-01-13 22:55:52 +0000 |
| commit | 7b2510f401eb54743f5f6fa3a0c8a286cf575c24 (patch) | |
| tree | 6b09b6d47cdc51c16b5025f145c73c0ec25ec261 /nova/compute | |
| parent | 86544fad81f95b74407a76bea8b081f490e2832f (diff) | |
Cells: Reduce the create_image call depth for cells
This patch reduces the create image call depth (for snapshot/backup) by
returning the basic image details to the user before we call down to
the child cell. The image entry is created in glance immediately, and
the child cell will finish up the rest.
Implements blueprint nova-compute-cells
Change-Id: I048cc532614c602f3aa6b539fb51e951174e4598
Diffstat (limited to 'nova/compute')
| -rw-r--r-- | nova/compute/api.py | 25 | ||||
| -rw-r--r-- | nova/compute/cells_api.py | 31 |
2 files changed, 40 insertions, 16 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py index 344761801..62dd410aa 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -1264,7 +1264,7 @@ class API(base.Base): @wrap_check_policy @check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.STOPPED]) def backup(self, context, instance, name, backup_type, rotation, - extra_properties=None): + extra_properties=None, image_id=None): """Backup the given instance :param instance: nova.db.sqlalchemy.models.Instance @@ -1277,9 +1277,14 @@ class API(base.Base): instance = self.update(context, instance, task_state=task_states.IMAGE_BACKUP, expected_task_state=None) - image_meta = self._create_image(context, instance, name, 'backup', - backup_type=backup_type, rotation=rotation, - extra_properties=extra_properties) + if image_id: + # The image entry has already been created, so just pull the + # metadata. + image_meta = self.image_service.show(context, image_id) + else: + image_meta = self._create_image(context, instance, name, + 'backup', backup_type=backup_type, + rotation=rotation, extra_properties=extra_properties) self.compute_rpcapi.snapshot_instance(context, instance=instance, image_id=image_meta['id'], image_type='backup', backup_type=backup_type, rotation=rotation) @@ -1287,7 +1292,8 @@ class API(base.Base): @wrap_check_policy @check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.STOPPED]) - def snapshot(self, context, instance, name, extra_properties=None): + def snapshot(self, context, instance, name, extra_properties=None, + image_id=None): """Snapshot the given instance. :param instance: nova.db.sqlalchemy.models.Instance @@ -1299,8 +1305,13 @@ class API(base.Base): instance = self.update(context, instance, task_state=task_states.IMAGE_SNAPSHOT, expected_task_state=None) - image_meta = self._create_image(context, instance, name, - 'snapshot', extra_properties=extra_properties) + if image_id: + # The image entry has already been created, so just pull the + # metadata. + image_meta = self.image_service.show(context, image_id) + else: + image_meta = self._create_image(context, instance, name, + 'snapshot', extra_properties=extra_properties) self.compute_rpcapi.snapshot_instance(context, instance=instance, image_id=image_meta['id'], image_type='snapshot') return image_meta diff --git a/nova/compute/cells_api.py b/nova/compute/cells_api.py index 698c6eed0..47d60aec4 100644 --- a/nova/compute/cells_api.py +++ b/nova/compute/cells_api.py @@ -115,15 +115,28 @@ class ComputeCellsAPI(compute_api.API): """ return - def _create_image(self, context, instance, name, image_type, - backup_type=None, rotation=None, extra_properties=None): - if backup_type: - return self._call_to_cells(context, instance, 'backup', - name, backup_type, rotation, - extra_properties=extra_properties) - else: - return self._call_to_cells(context, instance, 'snapshot', - name, extra_properties=extra_properties) + def backup(self, context, instance, name, backup_type, rotation, + extra_properties=None, image_id=None): + """Backup the given instance.""" + image_meta = super(ComputeCellsAPI, self).backup(context, + instance, name, backup_type, rotation, + extra_properties=extra_properties, image_id=image_id) + image_id = image_meta['id'] + self._cast_to_cells(context, instance, 'backup', name, + backup_type=backup_type, rotation=rotation, + extra_properties=extra_properties, image_id=image_id) + return image_meta + + def snapshot(self, context, instance, name, extra_properties=None, + image_id=None): + """Snapshot the given instance.""" + image_meta = super(ComputeCellsAPI, self).snapshot(context, + instance, name, extra_properties=extra_properties, + image_id=image_id) + image_id = image_meta['id'] + self._cast_to_cells(context, instance, 'snapshot', + name, extra_properties=extra_properties, image_id=image_id) + return image_meta def create(self, *args, **kwargs): """We can use the base functionality, but I left this here just |
