diff options
Diffstat (limited to 'glance_store/_drivers')
-rw-r--r-- | glance_store/_drivers/cinder.py | 2 | ||||
-rw-r--r-- | glance_store/_drivers/filesystem.py | 4 | ||||
-rw-r--r-- | glance_store/_drivers/http.py | 2 | ||||
-rw-r--r-- | glance_store/_drivers/rbd.py | 4 | ||||
-rw-r--r-- | glance_store/_drivers/s3.py | 10 | ||||
-rw-r--r-- | glance_store/_drivers/swift/store.py | 44 | ||||
-rw-r--r-- | glance_store/_drivers/swift/utils.py | 17 | ||||
-rw-r--r-- | glance_store/_drivers/vmware_datastore.py | 19 |
8 files changed, 42 insertions, 60 deletions
diff --git a/glance_store/_drivers/cinder.py b/glance_store/_drivers/cinder.py index 1fe06b4..feee5ac 100644 --- a/glance_store/_drivers/cinder.py +++ b/glance_store/_drivers/cinder.py @@ -1047,7 +1047,7 @@ class Store(glance_store.driver.Store): image_metadata = {} location_url = 'cinder://%s' % volume.id if self.backend_group: - image_metadata['store'] = u"%s" % self.backend_group + image_metadata['store'] = self.backend_group location_url = 'cinder://%s/%s' % (self.backend_group, volume.id) diff --git a/glance_store/_drivers/filesystem.py b/glance_store/_drivers/filesystem.py index c9f9ec4..6ff4eb5 100644 --- a/glance_store/_drivers/filesystem.py +++ b/glance_store/_drivers/filesystem.py @@ -22,6 +22,7 @@ import errno import logging import os import stat +import urllib import jsonschema from oslo_config import cfg @@ -29,7 +30,6 @@ from oslo_serialization import jsonutils from oslo_utils import encodeutils from oslo_utils import excutils from oslo_utils import units -from six.moves import urllib import glance_store from glance_store import capabilities @@ -793,7 +793,7 @@ class Store(glance_store.driver.Store): # Add store backend information to location metadata if self.backend_group: - metadata['store'] = u"%s" % self.backend_group + metadata['store'] = self.backend_group return ('file://%s' % filepath, bytes_written, diff --git a/glance_store/_drivers/http.py b/glance_store/_drivers/http.py index b0b70f5..79d3ab7 100644 --- a/glance_store/_drivers/http.py +++ b/glance_store/_drivers/http.py @@ -14,11 +14,11 @@ # under the License. import logging +import urllib from oslo_config import cfg from oslo_utils import encodeutils -from six.moves import urllib import requests diff --git a/glance_store/_drivers/rbd.py b/glance_store/_drivers/rbd.py index 9c1d45b..b632854 100644 --- a/glance_store/_drivers/rbd.py +++ b/glance_store/_drivers/rbd.py @@ -20,11 +20,11 @@ import contextlib import logging import math +import urllib from oslo_config import cfg from oslo_utils import encodeutils from oslo_utils import units -from six.moves import urllib from glance_store import capabilities from glance_store.common import utils @@ -651,7 +651,7 @@ class Store(driver.Store): # Add store backend information to location metadata metadata = {} if self.backend_group: - metadata['store'] = u"%s" % self.backend_group + metadata['store'] = self.backend_group return (loc.get_uri(), image_size, diff --git a/glance_store/_drivers/s3.py b/glance_store/_drivers/s3.py index 6eeba86..1a21ddd 100644 --- a/glance_store/_drivers/s3.py +++ b/glance_store/_drivers/s3.py @@ -15,9 +15,11 @@ """Storage backend for S3 or Storage Servers that follow the S3 Protocol""" +import io import logging import math import re +import urllib from boto3 import session as boto_session from botocore import client as boto_client @@ -27,8 +29,6 @@ import eventlet from oslo_config import cfg from oslo_utils import encodeutils from oslo_utils import units -import six -from six.moves import urllib import glance_store from glance_store import capabilities @@ -706,7 +706,7 @@ class Store(glance_store.driver.Store): checksum.update(write_chunk) if verifier: verifier.update(write_chunk) - fp = six.BytesIO(write_chunk) + fp = io.BytesIO(write_chunk) fp.seek(0) part = UploadPart(mpu, fp, cstart + 1, len(write_chunk)) pool.spawn_n(run_upload, s3_client, bucket, key, part) @@ -721,7 +721,7 @@ class Store(glance_store.driver.Store): checksum.update(write_chunk) if verifier: verifier.update(write_chunk) - fp = six.BytesIO(write_chunk) + fp = io.BytesIO(write_chunk) fp.seek(0) part = UploadPart(mpu, fp, cstart + 1, len(write_chunk)) pool.spawn_n(run_upload, s3_client, bucket, key, part) @@ -888,7 +888,7 @@ class Store(glance_store.driver.Store): { 'PartNumber': pnum, 'ETag': etag - } for pnum, etag in six.iteritems(pedict) + } for pnum, etag in pedict.items() ] } diff --git a/glance_store/_drivers/swift/store.py b/glance_store/_drivers/swift/store.py index c5d415c..ab8b49f 100644 --- a/glance_store/_drivers/swift/store.py +++ b/glance_store/_drivers/swift/store.py @@ -15,8 +15,11 @@ """Storage backend for SWIFT""" +import http.client +import io import logging import math +import urllib.parse from keystoneauth1.access import service_catalog as keystone_sc from keystoneauth1 import identity as ks_identity @@ -26,9 +29,6 @@ from oslo_config import cfg from oslo_utils import encodeutils from oslo_utils import excutils from oslo_utils import units -import six -from six.moves import http_client -from six.moves import urllib try: import swiftclient except ImportError: @@ -478,17 +478,13 @@ Related options: def swift_retry_iter(resp_iter, length, store, location, manager): - if not length and isinstance(resp_iter, six.BytesIO): - if six.PY3: - # On Python 3, io.BytesIO does not have a len attribute, instead - # go the end using seek to get the size of the file - pos = resp_iter.tell() - resp_iter.seek(0, 2) - length = resp_iter.tell() - resp_iter.seek(pos) - else: - # On Python 2, StringIO has a len attribute - length = resp_iter.len + if not length and isinstance(resp_iter, io.BytesIO): + # io.BytesIO does not have a len attribute, instead go the end using + # seek to get the size of the file + pos = resp_iter.tell() + resp_iter.seek(0, 2) + length = resp_iter.tell() + resp_iter.seek(pos) length = length if length else (resp_iter.len if hasattr(resp_iter, 'len') else 0) @@ -773,7 +769,7 @@ Store.OPTIONS = _SWIFT_OPTS + sutils.swift_opts + buffered.BUFFERING_OPTS def _is_slo(slo_header): - if (slo_header is not None and isinstance(slo_header, six.string_types) + if (slo_header is not None and isinstance(slo_header, str) and slo_header.lower() == 'true'): return True @@ -836,7 +832,7 @@ class BaseStore(driver.Store): location.container, location.obj, resp_chunk_size=self.CHUNKSIZE, headers=headers) except swiftclient.ClientException as e: - if e.http_status == http_client.NOT_FOUND: + if e.http_status == http.client.NOT_FOUND: msg = _("Swift could not find object %s.") % location.obj LOG.warning(msg) raise exceptions.NotFound(message=msg) @@ -1065,19 +1061,19 @@ class BaseStore(driver.Store): metadata = {} if self.backend_group: - metadata['store'] = u"%s" % self.backend_group + metadata['store'] = self.backend_group return (location.get_uri(credentials_included=include_creds), image_size, obj_etag, os_hash_value.hexdigest(), metadata) except swiftclient.ClientException as e: - if e.http_status == http_client.CONFLICT: + if e.http_status == http.client.CONFLICT: msg = _("Swift already has an image at this location") raise exceptions.Duplicate(message=msg) - elif e.http_status == http_client.REQUEST_ENTITY_TOO_LARGE: + elif e.http_status == http.client.REQUEST_ENTITY_TOO_LARGE: raise exceptions.StorageFull(message=e.msg) - msg = (_(u"Failed to add object to Swift.\n" + msg = (_("Failed to add object to Swift.\n" "Got error from Swift: %s.") % encodeutils.exception_to_unicode(e)) LOG.error(msg) @@ -1102,7 +1098,7 @@ class BaseStore(driver.Store): dlo_manifest = headers.get('x-object-manifest') slo_manifest = headers.get('x-static-large-object') except swiftclient.ClientException as e: - if e.http_status != http_client.NOT_FOUND: + if e.http_status != http.client.NOT_FOUND: raise if _is_slo(slo_manifest): @@ -1134,7 +1130,7 @@ class BaseStore(driver.Store): connection.delete_object(location.container, location.obj) except swiftclient.ClientException as e: - if e.http_status == http_client.NOT_FOUND: + if e.http_status == http.client.NOT_FOUND: msg = _("Swift could not find image at URI.") raise exceptions.NotFound(message=msg) else: @@ -1155,7 +1151,7 @@ class BaseStore(driver.Store): try: connection.head_container(container) except swiftclient.ClientException as e: - if e.http_status == http_client.NOT_FOUND: + if e.http_status == http.client.NOT_FOUND: if store_conf.swift_store_create_container_on_put: try: msg = (_LI("Creating swift container %(container)s") % @@ -1541,7 +1537,7 @@ class MultiTenantStore(BaseStore): try: connection.post_container(location.container, headers=headers) except swiftclient.ClientException as e: - if e.http_status == http_client.NOT_FOUND: + if e.http_status == http.client.NOT_FOUND: msg = _("Swift could not find image at URI.") raise exceptions.NotFound(message=msg) else: diff --git a/glance_store/_drivers/swift/utils.py b/glance_store/_drivers/swift/utils.py index 7285ba1..da034b4 100644 --- a/glance_store/_drivers/swift/utils.py +++ b/glance_store/_drivers/swift/utils.py @@ -12,11 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. +import configparser import logging -import sys from oslo_config import cfg -from six.moves import configparser from glance_store import exceptions from glance_store.i18n import _, _LE @@ -104,16 +103,11 @@ _config_defaults = {'user_domain_id': 'default', 'project_domain_id': 'default', 'project_domain_name': 'default'} -if sys.version_info >= (3, 2): - parser_class = configparser.ConfigParser -else: - parser_class = configparser.SafeConfigParser - -class SwiftConfigParser(parser_class): +class SwiftConfigParser(configparser.ConfigParser): def get(self, *args, **kwargs): - value = super(parser_class, self).get(*args, **kwargs) + value = super(configparser.ConfigParser, self).get(*args, **kwargs) return self._process_quotes(value) @staticmethod @@ -127,10 +121,7 @@ class SwiftConfigParser(parser_class): return value -if sys.version_info >= (3,): - CONFIG = SwiftConfigParser(defaults=_config_defaults) -else: - CONFIG = parser_class(defaults=_config_defaults) +CONFIG = SwiftConfigParser(defaults=_config_defaults) LOG = logging.getLogger(__name__) diff --git a/glance_store/_drivers/vmware_datastore.py b/glance_store/_drivers/vmware_datastore.py index 2b304cd..993f6d0 100644 --- a/glance_store/_drivers/vmware_datastore.py +++ b/glance_store/_drivers/vmware_datastore.py @@ -17,6 +17,7 @@ import logging import os +import urllib.parse from oslo_config import cfg from oslo_utils import excutils @@ -31,15 +32,9 @@ try: except ImportError: api = None -from six.moves import urllib -import six.moves.urllib.parse as urlparse - import requests from requests import adapters from requests.packages.urllib3.util import retry -import six -# NOTE(jokke): simplified transition to py3, behaves like py2 xrange -from six.moves import range import glance_store from glance_store import capabilities @@ -349,9 +344,9 @@ class StoreLocation(location.StoreLocation): Creates a https url that can be used to upload/download data from a vmware store. """ - parsed_url = urlparse.urlparse(self.get_uri()) + parsed_url = urllib.parse.urlparse(self.get_uri()) new_url = parsed_url._replace(scheme='https') - return urlparse.urlunparse(new_url) + return urllib.parse.urlunparse(new_url) class Store(glance_store.Store): @@ -597,7 +592,7 @@ class Store(glance_store.Store): image_file = _Reader(image_file, hashing_algo, verifier) headers = {} if image_size > 0: - headers.update({'Content-Length': six.text_type(image_size)}) + headers.update({'Content-Length': str(image_size)}) data = image_file else: data = utils.chunkiter(image_file, CHUNKSIZE) @@ -656,7 +651,7 @@ class Store(glance_store.Store): metadata = {} if self.backend_group: - metadata['store'] = u"%s" % self.backend_group + metadata['store'] = self.backend_group return (loc.get_uri(), image_file.size, @@ -804,9 +799,9 @@ class Store(glance_store.Store): # Note(sabari): The redirect url will have a scheme 'http(s)', but the # store only accepts url with scheme 'vsphere'. Thus, replacing with # store's scheme. - parsed_url = urlparse.urlparse(url) + parsed_url = urllib.parse.urlparse(url) new_url = parsed_url._replace(scheme='vsphere') - vsphere_url = urlparse.urlunparse(new_url) + vsphere_url = urllib.parse.urlunparse(new_url) return glance_store.location.Location(store_name, store_class, self.conf, |