|
12 | 12 | # License for the specific language governing permissions and limitations
|
13 | 13 | # under the License.
|
14 | 14 | import daiquiri
|
| 15 | +import keystoneauth1.session |
15 | 16 | from six.moves.urllib.parse import quote
|
16 | 17 |
|
| 18 | +from gnocchi import storage |
| 19 | + |
| 20 | +LOG = daiquiri.getLogger(__name__) |
| 21 | + |
| 22 | + |
17 | 23 | try:
|
18 | 24 | from swiftclient import client as swclient
|
19 | 25 | from swiftclient import utils as swift_utils
|
| 26 | + |
| 27 | + class CustomSwiftConnecion(swclient.Connection): |
| 28 | + def __init__(self, conf): |
| 29 | + self.conf = conf |
| 30 | + |
| 31 | + os_options = { |
| 32 | + 'endpoint_type': conf.swift_endpoint_type, |
| 33 | + 'service_type': conf.swift_service_type, |
| 34 | + 'user_domain_name': conf.swift_user_domain_name, |
| 35 | + 'project_domain_name': conf.swift_project_domain_name, |
| 36 | + } |
| 37 | + if conf.swift_region: |
| 38 | + os_options['region_name'] = conf.swift_region |
| 39 | + |
| 40 | + super(CustomSwiftConnecion, self).__init__( |
| 41 | + preauthurl=conf.swift_url, |
| 42 | + auth_version=conf.swift_auth_version, |
| 43 | + authurl=conf.swift_authurl, |
| 44 | + preauthtoken=conf.swift_preauthtoken, |
| 45 | + user=conf.swift_user, |
| 46 | + key=conf.swift_key, |
| 47 | + tenant_name=conf.swift_project_name, |
| 48 | + timeout=conf.swift_timeout, |
| 49 | + insecure=conf.swift_auth_insecure, |
| 50 | + os_options=os_options, |
| 51 | + cacert=conf.swift_cacert) |
| 52 | + |
| 53 | + def http_connection(self, url=None): |
| 54 | + url, conn = super(CustomSwiftConnecion, self).http_connection(url) |
| 55 | + adapter = keystoneauth1.session.TCPKeepAliveAdapter( |
| 56 | + pool_maxsize=self.conf.swift_max_parallel_requests) |
| 57 | + conn.request_session.mount("http://", adapter) |
| 58 | + conn.request_session.mount("https://", adapter) |
| 59 | + return url, conn |
| 60 | + |
20 | 61 | except ImportError:
|
21 | 62 | swclient = None
|
22 | 63 | swift_utils = None
|
23 | 64 |
|
24 |
| -from gnocchi import storage |
25 |
| - |
26 |
| -LOG = daiquiri.getLogger(__name__) |
27 |
| - |
28 | 65 |
|
29 | 66 | def get_connection(conf):
|
30 | 67 | if swclient is None:
|
31 | 68 | raise RuntimeError("python-swiftclient unavailable")
|
32 |
| - |
33 |
| - os_options = { |
34 |
| - 'endpoint_type': conf.swift_endpoint_type, |
35 |
| - 'service_type': conf.swift_service_type, |
36 |
| - 'user_domain_name': conf.swift_user_domain_name, |
37 |
| - 'project_domain_name': conf.swift_project_domain_name, |
38 |
| - } |
39 |
| - if conf.swift_region: |
40 |
| - os_options['region_name'] = conf.swift_region |
41 |
| - |
42 |
| - return swclient.Connection( |
43 |
| - preauthurl=conf.swift_url, |
44 |
| - auth_version=conf.swift_auth_version, |
45 |
| - authurl=conf.swift_authurl, |
46 |
| - preauthtoken=conf.swift_preauthtoken, |
47 |
| - user=conf.swift_user, |
48 |
| - key=conf.swift_key, |
49 |
| - tenant_name=conf.swift_project_name, |
50 |
| - timeout=conf.swift_timeout, |
51 |
| - insecure=conf.swift_auth_insecure, |
52 |
| - os_options=os_options, |
53 |
| - cacert=conf.swift_cacert, |
54 |
| - retries=0) |
| 69 | + return CustomSwiftConnecion(conf) |
55 | 70 |
|
56 | 71 |
|
57 | 72 | POST_HEADERS = {'Accept': 'application/json', 'Content-Type': 'text/plain'}
|
|
0 commit comments