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:
{
"resourceGroup": "<resource-group-name>", // [Required] Unique. Only allow up to 90 characters
"storageAccountName": "<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.
"accountType": "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
:
{
"resourceGroup": "azure-service-broker",
"storageAccountName": "generated-string",
"location": "eastus",
"accountType": "Standard_LRS"
}
NOTE:
* Please remove the comments in the JSON file before you use it.
* The names of parameters "resource_group_name", "storage_account_name",and "account_type" are deprecated since their formats are not unified with other services.
Above parameters are also the defaults if the broker operator doesn't change broker default settings. You can just run the following command to create a service instance without the json file:
cf create-service azure-storage standard mystorageservice
- 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']['storageAccountName']
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