'Permit admins to migrate a server to a new host.'

@wsgi.response(202)
@extensions.expected_errors((400, 403, 404, 409))
@wsgi.action('migrate')
def _migrate(self, req, id, body):

    context = req.environ['nova.context']
    context.can((ms_policies.POLICY_ROOT % 'migrate'))
    instance = common.get_instance(self.compute_api, context, id)
    try:
        self.compute_api.resize(req.environ['nova.context'], instance)
    except (exception.TooManyInstances, exception.QuotaError) as e:
        raise exc.HTTPForbidden(explanation=e.format_message())
    except exception.InstanceIsLocked as e:
        raise exc.HTTPConflict(explanation=e.format_message())
    except exception.InstanceInvalidState as state_error:
        common.raise_http_conflict_for_instance_invalid_state(state_error, 'migrate', id)
    except exception.InstanceNotFound as e:
        raise exc.HTTPNotFound(explanation=e.format_message())
    except exception.NoValidHost as e:
        raise exc.HTTPBadRequest(explanation=e.format_message())
