'Extracts and validates the volume size.
This function will validate or when not provided fill in the provided
size variable from the source_volume or snapshot and then does
validation on the size that is found and returns said validated size.'

@staticmethod
def _extract_size(size, source_volume, snapshot):

    def validate_snap_size(size):
        if (snapshot and (size < snapshot.volume_size)):
            msg = _("Volume    size    '%(size)s'GB    cannot    be    smaller    than    the    snapshot    size    %(snap_size)sGB.    They    must    be    >=    original    snapshot    size.")
            msg = (msg % {'size': size, 'snap_size': snapshot.volume_size})
            raise exception.InvalidInput(reason=msg)
    def validate_source_size(size):
        if (source_volume and (size < source_volume['size'])):
            msg = _("Volume    size    '%(size)s'GB    cannot    be    smaller    than    original    volume    size        %(source_size)sGB.    They    must    be    >=    original    volume    size.")
            msg = (msg % {'size': size, 'source_size': source_volume['size']})
            raise exception.InvalidInput(reason=msg)
    def validate_int(size):
        if ((not isinstance(size, six.integer_types)) or (size <= 0)):
            msg = (_("Volume    size    '%(size)s'    must    be    an    integer    and    greater    than    0") % {'size': size})
            raise exception.InvalidInput(reason=msg)
    validator_functors = [validate_int]
    if source_volume:
        validator_functors.append(validate_source_size)
    elif snapshot:
        validator_functors.append(validate_snap_size)
    if ((not size) and source_volume):
        size = source_volume['size']
    elif ((not size) and snapshot):
        size = snapshot.volume_size
    size = utils.as_int(size)
    LOG.debug("Validating    volume    size    '%(size)s'    using    %(functors)s", {'size': size, 'functors': ',    '.join([common.make_pretty_name(func) for func in validator_functors])})
    for func in validator_functors:
        func(size)
    return size
