コード例 #1
0
    import json
except ImportError:
    import simplejson as json

_VALID_VERSIONS = ['v1', 'v2', 'v3']
V3_SERVICE_TYPE = 'volumev3'
V2_SERVICE_TYPE = 'volumev2'
V1_SERVICE_TYPE = 'volume'
SERVICE_TYPES = {'1': V1_SERVICE_TYPE,
                 '2': V2_SERVICE_TYPE,
                 '3': V3_SERVICE_TYPE}

# tell keystoneclient that we can ignore the /v1|v2/{project_id} component of
# the service catalog when doing discovery lookups
for svc in ('volume', 'volumev2', 'volumev3'):
    discover.add_catalog_discover_hack(svc, re.compile('/v[12]/\w+/?$'), '/')


def get_volume_api_from_url(url):
    scheme, netloc, path, query, frag = urlparse.urlsplit(url)
    components = path.split("/")

    for version in _VALID_VERSIONS:
        if version in components:
            return version[1:]

    msg = (_("Invalid url: '%(url)s'. It must include one of: %(version)s.")
        % {'url': url, 'version': ', '.join(_VALID_VERSIONS)})
    raise exceptions.UnsupportedVersion(msg)

コード例 #2
0
ファイル: client.py プロジェクト: liuxinf/python-cinderclient
try:
    import json
except ImportError:
    import simplejson as json

_VALID_VERSIONS = ['v2', 'v3']
V3_SERVICE_TYPE = 'volumev3'
V2_SERVICE_TYPE = 'volumev2'
SERVICE_TYPES = {'2': V2_SERVICE_TYPE,
                 '3': V3_SERVICE_TYPE}
REQ_ID_HEADER = 'X-OpenStack-Request-ID'

# tell keystoneclient that we can ignore the /v1|v2/{project_id} component of
# the service catalog when doing discovery lookups
for svc in ('volume', 'volumev2', 'volumev3'):
    discover.add_catalog_discover_hack(svc, re.compile(r'/v[12]/\w+/?$'), '/')


def get_server_version(url, insecure=False, cacert=None):
    """Queries the server via the naked endpoint and gets version info.

    :param url: url of the cinder endpoint
    :param insecure: Explicitly allow client to perform "insecure" TLS
                     (https) requests
    :param cacert: Specify a CA bundle file to use in verifying a TLS
                            (https) server certificate
    :returns: APIVersion object for min and max version supported by
              the server
    """
    min_version = "2.0"
    current_version = "2.0"
コード例 #3
0
try:
    import json
except ImportError:
    import simplejson as json

_VALID_VERSIONS = ["v1", "v2", "v3"]
V3_SERVICE_TYPE = "volumev3"
V2_SERVICE_TYPE = "volumev2"
V1_SERVICE_TYPE = "volume"
SERVICE_TYPES = {"1": V1_SERVICE_TYPE, "2": V2_SERVICE_TYPE, "3": V3_SERVICE_TYPE}

# tell keystoneclient that we can ignore the /v1|v2/{project_id} component of
# the service catalog when doing discovery lookups
for svc in ("volume", "volumev2", "volumev3"):
    discover.add_catalog_discover_hack(svc, re.compile("/v[12]/\w+/?$"), "/")


def get_volume_api_from_url(url):
    scheme, netloc, path, query, frag = urlparse.urlsplit(url)
    components = path.split("/")

    for version in _VALID_VERSIONS:
        if version in components:
            return version[1:]

    msg = _("Invalid url: '%(url)s'. It must include one of: %(version)s.") % {
        "url": url,
        "version": ", ".join(_VALID_VERSIONS),
    }
    raise exceptions.UnsupportedVersion(msg)