@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
    def snapshot_instance(self, context, instance_id, image_id,
                          image_type='snapshot', backup_type=None,
                          rotation=None):
        """Snapshot an instance on this host.

        :param context: security context
        :param instance_id: nova.db.sqlalchemy.models.Instance.Id
        :param image_id: glance.db.sqlalchemy.models.Image.Id
        :param image_type: snapshot | backup
        :param backup_type: daily | weekly
        :param rotation: int representing how many backups to keep around;
            None if rotation shouldn't be used (as in the case of snapshots)
        """
        if image_type == "snapshot":
            task_state = task_states.IMAGE_SNAPSHOT
        elif image_type == "backup":
            task_state = task_states.IMAGE_BACKUP
        else:
            raise Exception(_('Image type not recognized %s') % image_type)

        context = context.elevated()
        instance_ref = self.db.instance_get(context, instance_id)

        current_power_state = self._get_power_state(context, instance_ref)
        self._instance_update(context,
                              instance_id,
                              power_state=current_power_state,
                              vm_state=vm_states.ACTIVE,
                              task_state=task_state)

        LOG.audit(_('instance %s: snapshotting'), instance_id,
                  context=context)

        if instance_ref['power_state'] != power_state.RUNNING:
            state = instance_ref['power_state']
            running = power_state.RUNNING
            LOG.warn(_('trying to snapshot a non-running '
                       'instance: %(instance_id)s (state: %(state)s '
                       'expected: %(running)s)') % locals())

        self.driver.snapshot(context, instance_ref, image_id)
        self._instance_update(context, instance_id, task_state=None)

        if image_type == 'snapshot' and rotation:
            raise exception.ImageRotationNotAllowed()

        elif image_type == 'backup' and rotation:
            instance_uuid = instance_ref['uuid']
            self.rotate_backups(context, instance_uuid, backup_type, rotation)

        elif image_type == 'backup':
            raise exception.RotationRequiredForBackup()
dataset/ETHPy150Open nii-cloud/dodai-compute/nova/compute/manager.py/ComputeManager.snapshot_instance/original