'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.'

@check_instance_lock
@check_instance_cell
@check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.STOPPED])
def resize(self, context, instance, flavor_id=None, clean_shutdown=True, **extra_instance_updates):

    self._check_auto_disk_config(instance, **extra_instance_updates)
    current_instance_type = instance.get_flavor()
    if (not flavor_id):
        LOG.debug('flavor_id    is    None.    Assuming    migration.', instance=instance)
        new_instance_type = current_instance_type
    else:
        new_instance_type = flavors.get_flavor_by_flavor_id(flavor_id, read_deleted='no')
        if ((new_instance_type.get('root_gb') == 0) and (current_instance_type.get('root_gb') != 0) and (not compute_utils.is_volume_backed_instance(context, instance))):
            reason = _('Resize    to    zero    disk    flavor    is    not    allowed.')
            raise exception.CannotResizeDisk(reason=reason)
    if (not new_instance_type):
        raise exception.FlavorNotFound(flavor_id=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,    new    instance    type    %(new_instance_type_name)s', {'current_instance_type_name': current_instance_type_name, 'new_instance_type_name': new_instance_type_name}, instance=instance)
    same_instance_type = (current_instance_type['id'] == new_instance_type['id'])
    if ((not same_instance_type) and new_instance_type.get('disabled')):
        raise exception.FlavorNotFound(flavor_id=flavor_id)
    if (same_instance_type and flavor_id and (self.cell_type != 'compute')):
        raise exception.CannotResizeToSameFlavor()
    if flavor_id:
        self._check_quota_for_upsize(context, instance, current_instance_type, new_instance_type)
    instance.task_state = task_states.RESIZE_PREP
    instance.progress = 0
    instance.update(extra_instance_updates)
    instance.save(expected_task_state=[None])
    filter_properties = {'ignore_hosts': []}
    if (not CONF.allow_resize_to_same_host):
        filter_properties['ignore_hosts'].append(instance.host)
    if (self.cell_type == 'api'):
        self._resize_cells_support(context, instance, current_instance_type, new_instance_type)
    if (not flavor_id):
        self._record_action_start(context, instance, instance_actions.MIGRATE)
    else:
        self._record_action_start(context, instance, instance_actions.RESIZE)
    try:
        request_spec = objects.RequestSpec.get_by_instance_uuid(context, instance.uuid)
        request_spec.ignore_hosts = filter_properties['ignore_hosts']
    except exception.RequestSpecNotFound:
        request_spec = None
    scheduler_hint = {'filter_properties': filter_properties}
    self.compute_task_api.resize_instance(context, instance, extra_instance_updates, scheduler_hint=scheduler_hint, flavor=new_instance_type, clean_shutdown=clean_shutdown, request_spec=request_spec)
