Azure Storage Service offers reliable, economical cloud storage for data big and small. This broker currently publishes a single service and plan for provisioning Azure Storage Service.
- Create a Storage Account.
- Check whether creating the Storage Account succeeds or not.
- Collect credentials.
Do nothing.
- Delete the Storage Account.
- Check whether deleting the Storage Account succeeds or not.
- Get the service name and plans
cf marketplace
Sample output:
service plans description
azure-storage standard Azure Storage Service
If you can not find the service name, please use the following command to make the plans public.
cf enable-service-access azure-storage
- Create a service instance
Configuration parameters are passed in a valid JSON object containing configuration parameters, provided either in-line or in a file. If these parameters are not provided, the broker will create the resources according to Naming Conventions.
cf create-service azure-storage $service_plan $service_instance_name -c $path_to_parameters
Supported configuration parameters:
{
"resource_group_name": "<resource-group-name>", // [Required] Unique. Only allow up to 90 characters
"storage_account_name": "<storage-account-name>", // [Required] Unique. Can contain only lowercase letters and numbers. Name must be between 3 and 24 characters.
"location": "<location>", // [Required] e.g. eastasia, eastus2, westus, etc. You can use azure cli command 'azure location list' to list all locations.
"account_type": "Standard_LRS | <other-account-type>" // [Required] Possible value: Standard_LRS | Standard_ZRS | Standard_GRS | Standard_RAGRS | Premium_LRS . See more details: https://azure.microsoft.com/en-us/pricing/details/storage/
}
For example:
cf create-service azure-storage standard mystorageservice -c examples/storage-example-config.json
The contents of examples/storage-example-config.json
:
{
"resource_group_name": "myResourceGroup",
"storage_account_name": "mystorageaccount",
"location": "eastus",
"account_type": "Standard_LRS"
}
NOTE: Please remove the comments in the JSON file before you use it.
- Check the operation status of creating the service instance
The creating operation is asynchronous. You can get the operation status after the creating operation.
cf service $service_instance_name
For example:
cf service mystorageservice
The credentials provided in a bind call have the following format:
"credentials":{
"primary_access_key": "PRIMARY-ACCOUNT-KEY",
"secondary_access_key": "SECONDARY-ACCOUNT-KEY",
"storage_account_name": "ACCOUNT-NAME"
}
Azure Storage Consumer is a simple example to use the service.
In the application, you can use Azure SDK for Python to operate your storage account (e.g. create your containers, and upload blobs).
- Get the credentials from the environment variables
service_name = 'azure-storage'
vcap_services = json.loads(os.environ['VCAP_SERVICES'])
account_name = vcap_services[service_name][0]['credentials']['storage_account_name']
account_key = vcap_services[service_name][0]['credentials']['primary_access_key']
- Create the storage service using the credentials
from azure.storage import BlobService
blob_service = BlobService(account_name, account_key)
If you would like to create a blob service in Azure China Cloud, you need to specify host_base
in BlobService
.
NOTE: The demo is based on
azure==0.11.1
. If you would like to use the lastestazure-storage-python
, please refer to azure-storage-python.
- Build the demo application
git clone https://github.com/bingosummer/azure-storage-consumer
cd azure-storage-consumer
cf push --no-start
- Bind the service instance to the application
cf bind-service azure-storage-consumer mystorageservice
- Restart the application
cf restart azure-storage-consumer
- Show the service instance
cf services
- Verify that the credentials are set as environment variables
cf env azure-storage-consumer
- Unbind the application from the service instance
cf unbind-service azure-storage-consumer mystorageservice
- Delete the service instance
cf delete-service mystorageservice -f