From 92cb9da7c2f37f36ee8a5adc3bd1483b6f52a107 Mon Sep 17 00:00:00 2001 From: Erik Olof Gunnar Andersson Date: Wed, 16 May 2018 11:09:07 -0700 Subject: [PATCH] Adding Swift backend Region support This adds support to configure the region_name for the Swift backend. We need to override the object_storage_url, as the swiftclient does not respect the region_name when using sessions. Change-Id: I13d9b1b6d75f2566622881286d80fba71dbc8af5 Closes-Bug: #1771647 --- zaqar/storage/swift/driver.py | 12 +++++++++++- zaqar/storage/swift/options.py | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/zaqar/storage/swift/driver.py b/zaqar/storage/swift/driver.py index 4fa7b9a32..b4128df2e 100644 --- a/zaqar/storage/swift/driver.py +++ b/zaqar/storage/swift/driver.py @@ -104,6 +104,7 @@ class _ClientWrapper(object): def __init__(self, conf): self.conf = conf + self.endpoint = None self.parsed_url = urllib.parse.urlparse(conf.uri) self.session = None @@ -118,10 +119,19 @@ class _ClientWrapper(object): project_domain_name=self.conf.project_domain_name, auth_url=self.conf.auth_url) self.session = keystone_session.Session(auth=auth) + self.endpoint = self.session.get_endpoint( + service_type='object-store', + interface=self.conf.interface, + region_name=self.conf.region_name + ) def __getattr__(self, attr): if self.session is None: self._init_auth() + os_options = { + 'object_storage_url': self.endpoint + } client = swiftclient.Connection(session=self.session, - insecure=self.conf.insecure) + insecure=self.conf.insecure, + os_options=os_options) return getattr(client, attr) diff --git a/zaqar/storage/swift/options.py b/zaqar/storage/swift/options.py index 4b57d0634..eddb166c3 100644 --- a/zaqar/storage/swift/options.py +++ b/zaqar/storage/swift/options.py @@ -26,6 +26,9 @@ MESSAGE_SWIFT_OPTIONS = ( cfg.StrOpt("project_domain_name", help="Domain name containing project"), cfg.StrOpt("user_domain_id", default="default", help="User's domain id"), cfg.StrOpt("user_domain_name", help="User's domain name"), + cfg.StrOpt("region_name", help="Region name"), + cfg.StrOpt("interface", default="publicURL", + help="The default interface for endpoint URL discovery."), )