コード例 #1
0
ファイル: wsgi.py プロジェクト: suman-d/cinder
    def set_api_version_request(self, url):
        """Set API version request based on the request header information.

        Microversions starts with /v3, so if a client sends a request for
        version 1.0 or 2.0 with the /v3 endpoint, throw an exception.
        Sending a header with any microversion to a /v1 or /v2 endpoint will
        be ignored.
        Note that a microversion must be set for the legacy endpoints. This
        will appear as 1.0 and 2.0 for /v1 and /v2.
        """
        if API_VERSION_REQUEST_HEADER in self.headers and 'v3' in url:
            hdr_string = self.headers[API_VERSION_REQUEST_HEADER]
            # 'latest' is a special keyword which is equivalent to requesting
            # the maximum version of the API supported
            hdr_string_list = hdr_string.split(",")
            volume_version = None
            for hdr in hdr_string_list:
                if VOLUME_SERVICE in hdr:
                    service, volume_version = hdr.split()
                    break
            if not volume_version:
                raise exception.VersionNotFoundForAPIMethod(
                    version=volume_version)
            if volume_version == 'latest':
                self.api_version_request = api_version.max_api_version()
            else:
                self.api_version_request = api_version.APIVersionRequest(
                    volume_version)

                # Check that the version requested is within the global
                # minimum/maximum of supported API versions
                if not self.api_version_request.matches(
                        api_version.min_api_version(),
                        api_version.max_api_version()):
                    raise exception.InvalidGlobalAPIVersion(
                        req_ver=self.api_version_request.get_string(),
                        min_ver=api_version.min_api_version().get_string(),
                        max_ver=api_version.max_api_version().get_string())

        else:
            if 'v1' in url:
                self.api_version_request = api_version.legacy_api_version1()
            elif 'v2' in url:
                self.api_version_request = api_version.legacy_api_version2()
            else:
                self.api_version_request = api_version.APIVersionRequest(
                    api_version._MIN_API_VERSION)
コード例 #2
0
    def test_min_version(self):

        self.assertEqual(
            api_version_request.APIVersionRequest(
                api_version_request._MIN_API_VERSION),
            api_version_request.min_api_version())
コード例 #3
0
    def test_min_version(self):

        self.assertEqual(
            api_version_request.APIVersionRequest(api_version_request._MIN_API_VERSION),
            api_version_request.min_api_version(),
        )