'Extend size of volume.'

@wsgi.response(http_client.ACCEPTED)
@wsgi.action('os-extend')
def _extend(self, req, id, body):

    context = req.environ['cinder.context']
    req_version = req.api_version_request
    volume = self.volume_api.get(context, id)
    try:
        size = int(body['os-extend']['new_size'])
    except (KeyError, ValueError, TypeError):
        msg = _('New    volume    size    must    be    specified    as    an    integer.')
        raise webob.exc.HTTPBadRequest(explanation=msg)
    try:
        if (req_version.matches('3.42') and (volume.status in ['in-use'])):
            self.volume_api.extend_attached_volume(context, volume, size)
        else:
            self.volume_api.extend(context, volume, size)
    except exception.InvalidVolume as error:
        raise webob.exc.HTTPBadRequest(explanation=error.msg)
