Skip to content

Commit

Permalink
Add region configuration for swift
Browse files Browse the repository at this point in the history
Addresses bug 1050034

Change-Id: Ib83f5dbb2c1fbeacd741e0cb92b619e67b2243c7
  • Loading branch information
Mark Washenberger committed Sep 13, 2012
1 parent 7e3ecc2 commit 173d821
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 4 additions & 0 deletions etc/glance-api.conf
Expand Up @@ -231,6 +231,10 @@ swift_enable_snet = False
# containers created by Glance in multi-tenant mode.
#swift_store_admin_tenants = []

# The region of the swift endpoint to be used for single tenant. This setting
# is only necessary if the tenant has multiple swift endpoints.
#swift_store_region =

# ============ S3 Store Options =============================

# Address where the S3 authentication service lives
Expand Down
14 changes: 10 additions & 4 deletions glance/store/swift.py
Expand Up @@ -51,6 +51,7 @@
cfg.StrOpt('swift_store_user', secret=True),
cfg.StrOpt('swift_store_key', secret=True),
cfg.StrOpt('swift_store_auth_version', default='2'),
cfg.StrOpt('swift_store_region'),
cfg.StrOpt('swift_store_container',
default=DEFAULT_CONTAINER),
cfg.IntOpt('swift_store_large_object_size',
Expand Down Expand Up @@ -218,6 +219,7 @@ def configure(self):
self.snet = CONF.swift_enable_snet
self.multi_tenant = CONF.swift_store_multi_tenant
self.admin_tenants = CONF.swift_store_admin_tenants
self.region = CONF.swift_store_region
self.auth_version = self._option_get('swift_store_auth_version')
self.storage_url = None
self.token = None
Expand Down Expand Up @@ -330,7 +332,7 @@ def get_size(self, location):
def _swift_connection_for_location(self, loc):
if loc.user:
return self._make_swift_connection(
loc.swift_url, loc.user, loc.key)
loc.swift_url, loc.user, loc.key, region=self.region)
else:
if self.multi_tenant:
return self._make_swift_connection(
Expand All @@ -341,15 +343,16 @@ def _swift_connection_for_location(self, loc):
LOG.error(reason)
raise exception.BadStoreUri(message=reason)

def _make_swift_connection(self, auth_url, user, key, storage_url=None,
token=None):
def _make_swift_connection(self, auth_url, user, key, region=None,
storage_url=None, token=None):
"""
Creates a connection using the Swift client library.
:param auth_url The authentication for v1 style Swift auth or
v2 style Keystone auth.
:param user A string containing the tenant:user information.
:param key A string containing the key/password for the connection.
:param region A string containing the swift endpoint region
:param storage_url A string containing the storage URL.
:param token A string containing the token
"""
Expand Down Expand Up @@ -377,8 +380,11 @@ def _make_swift_connection(self, auth_url, user, key, storage_url=None,
None, user, None, preauthurl=storage_url, preauthtoken=token,
snet=snet, tenant_name=tenant_name, auth_version='2')
else:
os_options = {}
if region:
os_options['region_name'] = region
return swiftclient.Connection(
full_auth_url, user, key, snet=snet,
full_auth_url, user, key, snet=snet, os_options=os_options,
tenant_name=tenant_name, auth_version=auth_version)

def _option_get(self, param):
Expand Down
2 changes: 1 addition & 1 deletion tools/pip-requires
Expand Up @@ -20,7 +20,7 @@ iso8601>=0.1.4


# For Swift storage backend.
python-swiftclient>=1,<2
python-swiftclient>=1.2,<2

# Note you will need gcc buildtools installed and must
# have installed libxml headers for lxml to be successfully
Expand Down

0 comments on commit 173d821

Please sign in to comment.