示例#1
0
def _check_location_uri(context, store_api, store_utils, uri, backend=None):
    """Check if an image location is valid.

    :param context: Glance request context
    :param store_api: store API module
    :param store_utils: store utils module
    :param uri: location's uri string
    :param backend: A backend name for the store
    """

    try:
        # NOTE(zhiyan): Some stores return zero when it catch exception
        if CONF.enabled_backends:
            size_from_backend = store_api.get_size_from_uri_and_backend(
                uri, backend, context=context)
        else:
            size_from_backend = store_api.get_size_from_backend(
                uri, context=context)

        is_ok = (store_utils.validate_external_location(uri)
                 and size_from_backend > 0)
    except (store.UnknownScheme, store.NotFound, store.BadStoreUri):
        is_ok = False
    if not is_ok:
        reason = _('Invalid location')
        raise exception.BadStoreUri(message=reason)
示例#2
0
文件: utils.py 项目: xglhjk6/glance
 def validate_external_location(self, uri):
     if uri and urllib.parse.urlparse(uri).scheme:
         return store_utils.validate_external_location(uri)
     else:
         return True
示例#3
0
 def validate_external_location(self, uri):
     if uri and urlparse.urlparse(uri).scheme:
         return store_utils.validate_external_location(uri)
     else:
         return True