diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-01-15 02:32:40 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-01-15 02:32:40 +0000 |
| commit | 832413f9de91902b67aa0b45dad1ec64b44df3bf (patch) | |
| tree | 0b879c89a82f6ebe3dad728ae4244f7ed0bdaebd /nova/compute | |
| parent | 76cf59e1d16420e659759f6fd4fc5a83980ce70c (diff) | |
| parent | 7b2510f401eb54743f5f6fa3a0c8a286cf575c24 (diff) | |
Merge "Cells: Reduce the create_image call depth for cells"
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 293ab2d74..bddb83449 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -1288,7 +1288,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 @@ -1301,9 +1301,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) @@ -1311,7 +1316,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 @@ -1323,8 +1329,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 |
