'Attempt to modify the type associated with an existing volume.'

@wrap_check_policy
def retype(self, context, volume, new_type, migration_policy=None):

    if (migration_policy and (migration_policy not in ('on-demand', 'never'))):
        msg = (_("migration_policy    must    be    'on-demand'    or    'never',    passed:    %s") % new_type)
        LOG.error(msg)
        raise exception.InvalidInput(reason=msg)
    try:
        vol_type = volume_types.get_by_name_or_id(context.elevated(), new_type)
    except exception.InvalidVolumeType:
        msg = (_('Invalid    volume_type    passed:    %s.') % new_type)
        LOG.error(msg)
        raise exception.InvalidInput(reason=msg)
    vol_type_id = vol_type['id']
    reservations = quota_utils.get_volume_type_reservation(context, volume, vol_type_id, reserve_vol_type_only=True)
    try:
        reserve_opts = {'volumes': (-1), 'gigabytes': (- volume.size)}
        QUOTAS.add_volume_type_opts(context, reserve_opts, volume.volume_type_id)
        reserve_opts.pop('volumes')
        reserve_opts.pop('gigabytes')
        old_reservations = QUOTAS.reserve(context, project_id=volume.project_id, **reserve_opts)
    except Exception:
        volume.status = volume.previous_status
        volume.save()
        msg = _('Failed    to    update    quota    usage    while    retyping    volume.')
        LOG.exception(msg, resource=volume)
        raise exception.CinderException(msg)
    expected = {'status': ('available', 'in-use'), 'migration_status': self.AVAILABLE_MIGRATION_STATUS, 'consistencygroup_id': (None, ''), 'group_id': (None, ''), 'volume_type_id': db.Not(vol_type_id)}
    filters = [db.volume_qos_allows_retype(vol_type_id)]
    updates = {'status': 'retyping', 'previous_status': objects.Volume.model.status}
    if (not volume.conditional_update(updates, expected, filters)):
        msg = _('Retype    needs    volume    to    be    in    available    or    in-use    state,    not    be    part    of    an    active    migration    or    a    consistency    group,    requested    type    has    to    be    different    that    the    one    from    the    volume,    and    for    in-use    volumes    front-end    qos    specs    cannot    change.')
        LOG.error(msg)
        QUOTAS.rollback(context, (reservations + old_reservations), project_id=volume.project_id)
        raise exception.InvalidVolume(reason=msg)
    request_spec = {'volume_properties': volume, 'volume_id': volume.id, 'volume_type': vol_type, 'migration_policy': migration_policy, 'quota_reservations': reservations, 'old_reservations': old_reservations}
    self.scheduler_rpcapi.retype(context, volume, request_spec=request_spec, filter_properties={})
    LOG.info('Retype    volume    request    issued    successfully.', resource=volume)
