From 173d8214637c3db1225e42a9f7908eb4430f96b1 Mon Sep 17 00:00:00 2001 From: Mark Washenberger Date: Tue, 11 Sep 2012 22:59:52 +0000 Subject: [PATCH] Add region configuration for swift Addresses bug 1050034 Change-Id: Ib83f5dbb2c1fbeacd741e0cb92b619e67b2243c7 --- etc/glance-api.conf | 4 ++++ glance/store/swift.py | 14 ++++++++++---- tools/pip-requires | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/etc/glance-api.conf b/etc/glance-api.conf index 4dd6e5f556..52ed789b6e 100644 --- a/etc/glance-api.conf +++ b/etc/glance-api.conf @@ -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 diff --git a/glance/store/swift.py b/glance/store/swift.py index 9c69ab26a1..7f49102364 100644 --- a/glance/store/swift.py +++ b/glance/store/swift.py @@ -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', @@ -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 @@ -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( @@ -341,8 +343,8 @@ 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. @@ -350,6 +352,7 @@ def _make_swift_connection(self, auth_url, user, key, storage_url=None, 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 """ @@ -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): diff --git a/tools/pip-requires b/tools/pip-requires index 8464215ed0..e873537ec2 100644 --- a/tools/pip-requires +++ b/tools/pip-requires @@ -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