| OLD | NEW |
| 1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
| 2 # Copyright 2013 Google Inc. All Rights Reserved. | 2 # Copyright 2013 Google Inc. All Rights Reserved. |
| 3 # | 3 # |
| 4 # Licensed under the Apache License, Version 2.0 (the "License"); | 4 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 # you may not use this file except in compliance with the License. | 5 # you may not use this file except in compliance with the License. |
| 6 # You may obtain a copy of the License at | 6 # You may obtain a copy of the License at |
| 7 # | 7 # |
| 8 # http://www.apache.org/licenses/LICENSE-2.0 | 8 # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 # | 9 # |
| 10 # Unless required by applicable law or agreed to in writing, software | 10 # Unless required by applicable law or agreed to in writing, software |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 During initialization it takes as an argument a gsutil_api_map which maps | 34 During initialization it takes as an argument a gsutil_api_map which maps |
| 35 providers to their default and supported gsutil Cloud API implementations | 35 providers to their default and supported gsutil Cloud API implementations |
| 36 (see comments in cs_api_map for details). | 36 (see comments in cs_api_map for details). |
| 37 | 37 |
| 38 Instantiation of multiple delegators per-thread is required for multiprocess | 38 Instantiation of multiple delegators per-thread is required for multiprocess |
| 39 and/or multithreaded operations. Calling methods on the same delegator in | 39 and/or multithreaded operations. Calling methods on the same delegator in |
| 40 multiple threads is unsafe. | 40 multiple threads is unsafe. |
| 41 """ | 41 """ |
| 42 | 42 |
| 43 def __init__(self, bucket_storage_uri_class, gsutil_api_map, logger, | 43 def __init__(self, bucket_storage_uri_class, gsutil_api_map, logger, |
| 44 provider=None, debug=0): | 44 provider=None, debug=0, trace_token=None): |
| 45 """Performs necessary setup for delegating cloud storage requests. | 45 """Performs necessary setup for delegating cloud storage requests. |
| 46 | 46 |
| 47 This function has different arguments than the gsutil Cloud API __init__ | 47 This function has different arguments than the gsutil Cloud API __init__ |
| 48 function because of the delegation responsibilties of this class. | 48 function because of the delegation responsibilties of this class. |
| 49 | 49 |
| 50 Args: | 50 Args: |
| 51 bucket_storage_uri_class: boto storage_uri class, used by APIs that | 51 bucket_storage_uri_class: boto storage_uri class, used by APIs that |
| 52 provide boto translation or mocking. | 52 provide boto translation or mocking. |
| 53 gsutil_api_map: Map of providers and API selector tuples to api classes | 53 gsutil_api_map: Map of providers and API selector tuples to api classes |
| 54 which can be used to communicate with those providers. | 54 which can be used to communicate with those providers. |
| 55 logger: logging.logger for outputting log messages. | 55 logger: logging.logger for outputting log messages. |
| 56 provider: Default provider prefix describing cloud storage provider to | 56 provider: Default provider prefix describing cloud storage provider to |
| 57 connect to. | 57 connect to. |
| 58 debug: Debug level for the API implementation (0..3). | 58 debug: Debug level for the API implementation (0..3). |
| 59 trace_token: Apiary trace token to pass to API. |
| 59 """ | 60 """ |
| 60 super(CloudApiDelegator, self).__init__(bucket_storage_uri_class, logger, | 61 super(CloudApiDelegator, self).__init__(bucket_storage_uri_class, logger, |
| 61 provider=provider, debug=debug) | 62 provider=provider, debug=debug, |
| 63 trace_token=trace_token) |
| 62 self.api_map = gsutil_api_map | 64 self.api_map = gsutil_api_map |
| 63 self.prefer_api = boto.config.get('GSUtil', 'prefer_api', '').upper() | 65 self.prefer_api = boto.config.get('GSUtil', 'prefer_api', '').upper() |
| 64 self.loaded_apis = {} | 66 self.loaded_apis = {} |
| 65 | 67 |
| 66 if not self.api_map[ApiMapConstants.API_MAP]: | 68 if not self.api_map[ApiMapConstants.API_MAP]: |
| 67 raise ArgumentException('No apiclass supplied for gsutil Cloud API map.') | 69 raise ArgumentException('No apiclass supplied for gsutil Cloud API map.') |
| 68 | 70 |
| 69 def _GetApi(self, provider): | 71 def _GetApi(self, provider): |
| 70 """Returns a valid CloudApi for use by the caller. | 72 """Returns a valid CloudApi for use by the caller. |
| 71 | 73 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 'gsutil Cloud API map contains no entry for provider %s.' % provider) | 111 'gsutil Cloud API map contains no entry for provider %s.' % provider) |
| 110 if api_selector not in self.api_map[ApiMapConstants.API_MAP][provider]: | 112 if api_selector not in self.api_map[ApiMapConstants.API_MAP][provider]: |
| 111 raise ArgumentException( | 113 raise ArgumentException( |
| 112 'gsutil Cloud API map does not support API %s for provider %s.' % | 114 'gsutil Cloud API map does not support API %s for provider %s.' % |
| 113 (api_selector, provider)) | 115 (api_selector, provider)) |
| 114 self.loaded_apis[provider][api_selector] = ( | 116 self.loaded_apis[provider][api_selector] = ( |
| 115 self.api_map[ApiMapConstants.API_MAP][provider][api_selector]( | 117 self.api_map[ApiMapConstants.API_MAP][provider][api_selector]( |
| 116 self.bucket_storage_uri_class, | 118 self.bucket_storage_uri_class, |
| 117 self.logger, | 119 self.logger, |
| 118 provider=provider, | 120 provider=provider, |
| 119 debug=self.debug)) | 121 debug=self.debug, |
| 122 trace_token=self.trace_token)) |
| 120 | 123 |
| 121 def GetApiSelector(self, provider=None): | 124 def GetApiSelector(self, provider=None): |
| 122 """Returns a cs_api_map.ApiSelector based on input and configuration. | 125 """Returns a cs_api_map.ApiSelector based on input and configuration. |
| 123 | 126 |
| 124 Args: | 127 Args: |
| 125 provider: Provider to return the ApiSelector for. If None, class-wide | 128 provider: Provider to return the ApiSelector for. If None, class-wide |
| 126 default is used. | 129 default is used. |
| 127 | 130 |
| 128 Returns: | 131 Returns: |
| 129 cs_api_map.ApiSelector that will be used for calls to the delegator | 132 cs_api_map.ApiSelector that will be used for calls to the delegator |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 | 419 |
| 417 Raises: | 420 Raises: |
| 418 ArgumentException for errors during input validation. | 421 ArgumentException for errors during input validation. |
| 419 ServiceException for errors interacting with cloud storage providers. | 422 ServiceException for errors interacting with cloud storage providers. |
| 420 | 423 |
| 421 Returns: | 424 Returns: |
| 422 Website configuration XML for the bucket specified by storage_url. | 425 Website configuration XML for the bucket specified by storage_url. |
| 423 """ | 426 """ |
| 424 return self._GetApi(provider).XmlPassThroughGetWebsite(storage_url) | 427 return self._GetApi(provider).XmlPassThroughGetWebsite(storage_url) |
| 425 | 428 |
| OLD | NEW |