genvid.toolbox.AzureStorageAccount¶
-
class
genvid.toolbox.
AzureStorageAccount
(bastionAPI, default_region=None)¶ Bases:
object
Utilities to create and manipulate Azure Storage Account.
-
AZURE_STORAGE_ACCOUNT
¶ A mirror of
AZURE_STORAGE_ACCOUNT
, giving the name of the Azure Storage Account
-
AZURE_RESOURCE_GROUP
¶ A mirror of
AZURE_RESOURCE_GROUP
, giving the name of the Azure resource group.
-
AZURE_DEFAULT_REGION
¶ Returns: The default region name.
-
get_storage_account_name
()¶ Retrieves the name of storage account to use.
Note
Name of storage acount must be unique, between 3 to 24 characters, and can only contain numbers and lowercase letters.
Returns: self.AZURE_STORAGE_ACCOUNT if the environment variable is set. Otherwise, a manipulated storage account name is returned.
-
create_storage_account
(storage_account_name: str, resource_group: str = None)¶ Creates storage account if it doesn’t exists.
The create command will create the account if it does not exist. Othervise, the command will be ignored.
Parameters: - storage_account_name – The name of storage account to create.
- resource_group – Resource group to be used.
-
list_storage_accounts
(resource_group: str = None) → list¶ List Storage accounts in the resource group.
Parameters: resource_group – Resource group to be used.
-
get_connection_string
(storage_account_name: str, resource_group: str = None) → str¶ Get the connection string for the storage account.
Parameters: - storage_account_name – The name of storage account for which connection string needs to be retrieved.
- resource_group – Resource group to be used.
Returns: Connection String for storage account.
-
create_resource_group
(region: str = None, resource_group: str = None)¶ Creates Resource Group if it doesn’t exists.
If the resource group already exists, nothing will be done. Othervise, a resource gorup in specified region will be created.
Parameters: - region – Region in which resource group needs to be created.
- resource_group – Resource group to be created.
-
check_resource_group_exist
(resource_group: str = None)¶ Check if resource group exists.
Parameters: resource_group – Resource group to be checked. Returns: True if the resource group exists, False othervise.
-
get_tenant_id
()¶ Gets the tenant id of the azure account.
Returns: Tenant ID of azure account.
-
upload_blob
(storage_account_name: str, container_name: str, blob_name: str, filepath: typing.Union[str, pathlib.Path], resource_group: str = None)¶ Upload specific blob to an Azure Container.
Parameters: - storage_account_name – Name of storage account.
- container_name – The name of container to operate on.
- blob_name – Name of the blob to be uploaded
- filepath – Path to the file to be uploaded.
- resource_group – Resource group in which storage account exists.
-
add_allowed_ip
(storage_account_name: str, ip: str)¶ Add the IP address to allowed list.
Parameters: - storage_account_name – Name of storage account.
- ip – IP Address to be added.
-
delete_blob
(storage_account_name: str, container_name: str, blob_name: str, resource_group: str = None)¶ Delete specific blob to an Azure Container.
Parameters: - storage_account_name – Name of storage account.
- container_name – The name of container to operate on.
- blob_name – Name of the blob to be Deleted
- resource_group – Resource group in which storage account exists.
-
create_container
(storage_account_name: str, container_name: str, access_level: str = 'blob', resource_group: typing.Optional[str] = None)¶ Create an Azure Container.
Parameters: - storage_account_name – Name of storage account.
- container_name – The name of container to operate on.
- access_level – Access level of blob.
- resource_group – Resource group in which storage account exists.
-
list_containers
(storage_account_name: str, resource_group: str = None)¶ List the containers in storage account.
Parameters: - storage_account_name – Name of storage account.
- resource_group – Resource group in which storage account exists.
-
list_allowed_ips
(storage_account_name: str) → list¶ List the of allowed IP address for a storage account.
Parameters: storage_account_name – Name of storage account. Returns: List of allowed IP addresses.
-
list_images
(storage_account_name: str, container_name: str, prefix: str, resource_group: str = None)¶ List of images for specific path in the Container.
Parameters: - storage_account_name – Name of storage account.
- container_name – The name of container to operate on.
- prefix – Prefix of image/blob.
Returns: List of Images/blobs.
List of shared image gallery.
Returns: List of Shared image gallery.
Create shared image gallery in specified resource group.
:param resource_group:Resource group to be created if it does not exists. :param gallery_name: Shared Gallery name to be created.
-
list_gallery_image_definition
(gallery_name: str, resource_group: str)¶ List of gallery image definitions.
Parameters: - gallery_name – Name of shared image gallery.
- resource_group – Resource group in which the shared image gallery exists.
Returns: List of Images/blobs.
-
create_image_definition
(resource_group: str, gallery_name: str, image_definition_name: str, publisher: str, image_sku: str, image_offer: str, os_type: str)¶ Create a gallery image definition.
Parameters: - resource_group – Name of resource group.
- gallery_name – The name of the shared image gallery.
- image_defintion_name – Gallery image definition.
- publisher – Image publisher.
- image_sku – Image sku.
- image_offer – Access level of blob.
- os_type – Name of storage account.
-
delete_storage_account
(storage_account_name: str, resource_group: str = None)¶ Delete the specified storage account.
Parameters: - storage_account_name – Name of storage account.
- resource_group – Resource group in which storage account exists.
-
delete_container
(container_name: str, storage_account_name: str, resource_group: str = None)¶ Delete the specified container.
Parameters: - storage_account_name – Name of storage account.
- container_name – Name of container to be deleted.
- resource_group – Resource group in which storage account exists.
-
delete_resource_group
(resource_group: str)¶ Delete the specified resource group.
Parameters: resource_group – Name of resource group.
-
-
class
azure_storage.
AzureStorageAccount
¶ Implementation of
genvid.toolbox.AzureStorageAccount