Пример #1
0
def get_api(provider):
    """Returns thread local API instance for cloud provider.

  Uses thread local storage to make sure only one instance of an API exists
  per thread per provider.

  Args:
    provider (storage_url.ProviderPrefix): Cloud provider prefix.

  Returns:
    CloudApi client object for provider argument.

  Raises:
    ValueError: Invalid API provider.
  """
    if properties.VALUES.storage.use_threading_local.GetBool():
        api_client = getattr(_cloud_api_thread_local_storage, provider.value,
                             None)
        if api_client:
            return api_client

    if provider == storage_url.ProviderPrefix.GCS:
        api_client = gcs_api.GcsApi()
    elif provider == storage_url.ProviderPrefix.S3:
        api_client = s3_api.S3Api()
    else:
        raise ValueError(
            'Provider must be a valid storage_url.ProviderPrefix.')

    if properties.VALUES.storage.use_threading_local.GetBool():
        setattr(_cloud_api_thread_local_storage, provider.value, api_client)

    return api_client
Пример #2
0
def get_api(provider):
    """Returns API instance for cloud provider.

  Args:
    provider (ProviderPrefix): Cloud provider prefix.

  Returns:
    CloudApi instance for specific cloud provider.

  Raises:
    ValueError: Invalid API provider.
  """
    # TODO(b/167685797): Use thread-local.
    if provider == storage_url.ProviderPrefix.GCS:
        return gcs_api.GcsApi()
    elif provider == storage_url.ProviderPrefix.S3:
        return s3_api.S3Api()
    raise ValueError('Provider API value must be "gs" or "s3".')
Пример #3
0
 def SetUp(self):
   self.s3_api = s3_api.S3Api()
   self.stubber = stub.Stubber(self.s3_api.client)