libcloud.storage.drivers.azure_blobs module

class libcloud.storage.drivers.azure_blobs.AuthType[source]

Bases: object

AZURE_AD = 'azureAD'
class libcloud.storage.drivers.azure_blobs.AzureBlobLease(driver, object_path, use_lease)[source]

Bases: object

A class to help in leasing an azure blob and renewing the lease

Parameters:
  • driver (AzureStorageDriver) – The Azure storage driver that is being used

  • object_path (str) – The path of the object we need to lease

  • use_lease (bool) – Indicates if we must take a lease or not

renew()[source]

Renew the lease if it is older than a predefined time period

update_headers(headers)[source]

Update the lease id in the headers

class libcloud.storage.drivers.azure_blobs.AzureBlobsActiveDirectoryConnection(*args, **kwargs)[source]

Bases: AzureActiveDirectoryConnection

Represents a single connection to Azure Blobs.

The main Azure Blob Storage service uses a prefix in the hostname to distinguish between accounts, e.g. theaccount.blob.core.windows.net. However, some custom deployments of the service, such as the Azurite emulator, instead use a URL prefix such as /theaccount. To support these deployments, the parameter account_prefix must be set on the connection. This is done by instantiating the driver with arguments such as host='somewhere.tld' and key='theaccount'. To specify a custom host without an account prefix, e.g. to connect to Azure Government or Azure China, the driver can be instantiated with the appropriate storage endpoint suffix, e.g. host='blob.core.usgovcloudapi.net' and key='theaccount'.

This connection is similar to AzureBlobsConnection, but uses Azure Active Directory to authenticate

Parameters:

account_prefix (str) – Optional prefix identifying the storage account. Used when connecting to a custom deployment of the storage service like Azurite or IoT Edge Storage.

Initialize user_id and key; set secure to an int based on passed value.

API_VERSION = '2018-11-09'
morph_action_hook(action)[source]

Here we strip any duplicated leading or trailing slashes to prevent typos and other issues where some APIs don’t correctly handle double slashes.

Keep in mind that in some situations, “/” is a valid path name so we have a module flag which disables this behavior (https://github.com/apache/libcloud/issues/1529).

class libcloud.storage.drivers.azure_blobs.AzureBlobsConnection(*args, **kwargs)[source]

Bases: AzureConnection

Represents a single connection to Azure Blobs.

The main Azure Blob Storage service uses a prefix in the hostname to distinguish between accounts, e.g. theaccount.blob.core.windows.net. However, some custom deployments of the service, such as the Azurite emulator, instead use a URL prefix such as /theaccount. To support these deployments, the parameter account_prefix must be set on the connection. This is done by instantiating the driver with arguments such as host='somewhere.tld' and key='theaccount'. To specify a custom host without an account prefix, e.g. to connect to Azure Government or Azure China, the driver can be instantiated with the appropriate storage endpoint suffix, e.g. host='blob.core.usgovcloudapi.net' and key='theaccount'.

Parameters:

account_prefix (str) – Optional prefix identifying the storage account. Used when connecting to a custom deployment of the storage service like Azurite or IoT Edge Storage.

Initialize user_id and key; set secure to an int based on passed value.

API_VERSION = '2018-11-09'
morph_action_hook(action)[source]

Here we strip any duplicated leading or trailing slashes to prevent typos and other issues where some APIs don’t correctly handle double slashes.

Keep in mind that in some situations, “/” is a valid path name so we have a module flag which disables this behavior (https://github.com/apache/libcloud/issues/1529).

class libcloud.storage.drivers.azure_blobs.AzureBlobsStorageDriver(key, secret=None, secure=True, host=None, port=None, tenant_id=None, identity=None, auth_type=None, cloud_environment='default', **kwargs)[source]

Bases: StorageDriver

Parameters:
  • key (str) – API key or username to be used (required)

  • secret (str) – Secret password to be used (required)

  • secure (bool) – Whether to use HTTPS or HTTP. Note: Some providers only support HTTPS, and it is on by default.

  • host (str) – Override hostname used for connections.

  • port (int) – Override port used for connections.

  • api_version (str) – Optional API version. Only used by drivers which support multiple API versions.

  • region (str) – Optional driver region. Only used by drivers which support multiple regions.

Return type:

None

connectionCls

alias of AzureBlobsConnection

create_container(container_name)[source]

@inherits: StorageDriver.create_container

delete_container(container)[source]

@inherits: StorageDriver.delete_container

delete_object(obj)[source]

@inherits: StorageDriver.delete_object

download_object(obj, destination_path, overwrite_existing=False, delete_on_failure=True)[source]

@inherits: StorageDriver.download_object

download_object_as_stream(obj, chunk_size=None)[source]

@inherits: StorageDriver.download_object_as_stream

download_object_range(obj, destination_path, start_bytes, end_bytes=None, overwrite_existing=False, delete_on_failure=True)[source]

Download part of an object.

Parameters:
  • obj (libcloud.storage.base.Object) – Object instance.

  • destination_path (str) – Full path to a file or a directory where the incoming file will be saved.

  • start_bytes (int) – Start byte offset (inclusive) for the range download. Offset is 0 index based so the first byte in file file is “0”.

  • end_bytes (int) – End byte offset (non-inclusive) for the range download. If not provided, it will default to the end of the file.

  • overwrite_existing (bool) – True to overwrite an existing file, defaults to False.

  • delete_on_failure (bool) – True to delete a partially downloaded file if the download was not successful (hash mismatch / file size).

Returns:

True if an object has been successfully downloaded, False otherwise.

Return type:

bool

download_object_range_as_stream(obj, start_bytes, end_bytes=None, chunk_size=None)[source]

Return a iterator which yields range / part of the object data.

Parameters:
  • obj (libcloud.storage.base.Object) – Object instance

  • start_bytes (int) – Start byte offset (inclusive) for the range download. Offset is 0 index based so the first byte in file file is “0”.

  • end_bytes (int) – End byte offset (non-inclusive) for the range download. If not provided, it will default to the end of the file.

  • chunk_size (int) – Optional chunk size (in bytes).

Return type:

iterator of bytes

ex_set_object_metadata(obj, meta_data)[source]

Set metadata for an object

Parameters:
  • obj (Object) – The blob object

  • meta_data (dict) – Metadata key value pairs

get_container(container_name)[source]

@inherits: StorageDriver.get_container

get_object(container_name, object_name)[source]

@inherits: StorageDriver.get_object

get_object_cdn_url(obj, ex_expiry=24.0)[source]

Return a SAS URL that enables reading the given object.

Parameters:
  • obj (Object) – Object instance.

  • ex_expiry (float) – The number of hours after which the URL expires. Defaults to 24 hours.

Returns:

A SAS URL for the object.

Return type:

str

hash_type: str = 'md5'
iterate_container_objects(container, prefix=None, ex_prefix=None)[source]

@inherits: StorageDriver.iterate_container_objects

iterate_containers()[source]

@inherits: StorageDriver.iterate_containers

name: str = 'Microsoft Azure (blobs)'
supports_chunked_encoding: bool = False
upload_object(file_path, container, object_name, verify_hash=True, extra=None, headers=None, ex_use_lease=False, **deprecated_kwargs)[source]

Upload an object currently located on a disk.

@inherits: StorageDriver.upload_object

Parameters:

ex_use_lease (bool) – Indicates if we must take a lease before upload

upload_object_via_stream(iterator, container, object_name, verify_hash=True, extra=None, headers=None, ex_use_lease=False, **deprecated_kwargs)[source]

@inherits: StorageDriver.upload_object_via_stream

Parameters:

ex_use_lease (bool) – Indicates if we must take a lease before upload

website = 'http://windows.azure.com/'