From 812101ae5cdf53a1c6deb294ec92a0ee1e4f3fcc 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 fc3571df6f..59f0f57bb7 100644 --- a/glance/store/swift.py +++ b/glance/store/swift.py @@ -51,6 +51,7 @@ swift_opts = [ 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', @@ -216,6 +217,7 @@ class Store(glance.store.base.Store): 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 @@ -328,7 +330,7 @@ class Store(glance.store.base.Store): 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( @@ -339,8 +341,8 @@ class Store(glance.store.base.Store): 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. @@ -348,6 +350,7 @@ class Store(glance.store.base.Store): 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 """ @@ -375,8 +378,11 @@ class Store(glance.store.base.Store): 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