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 Blob Service.
- Get the service name and plans
cf marketplace
Sample output:
service plans description
azurestorageblob default Azure Storage Blob Service
If you can not find the service name, please use the following command to make the plans public.
cf enable-service-access azurestorageblob
- Create a service instance
cf create-service azurestorageblob $service_plan $service_instance_name
For example:
cf create-service azurestorageblob default myblobservice
Additional configuration parameters are supported with the provision request. These 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 azurestorageblob $service_plan $service_instance_name -c $path_to_parameters
Supported configuration parameters:
{
"resource_group_name": "<resource-group-name>",
"storage_account_name": "<storage-account-name>",
"location": "<location>",
"account_type": "<account-type>"
}
For example:
cf create-service azurestorageblob default myblobservice -c /tmp/config.json
The contents of /tmp/config.json
:
{
"resource_group_name": "myResourceGroup",
"storage_account_name": "mystorageaccount",
"location": "eastus",
"account_type": "Standard_LRS"
}
- 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 myblobservice
The credentials provided in a bind call have the following format:
"credentials":{
"container_name": "cloud-foundry-2eac2d52-bfc9-4d0f-af28-c02187689d72",
"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. put or get your blobs).
- Get the credentials from the environment variables
service_name = 'azurestorageblob'
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 blob 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 myblobservice
- 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 myblobservice
- Delete the service instance
cf delete-service myblobservice -f
A service provisioning call will create Azure Storage Account.
The following names are used and can be customized with a prefix:
Resource | Name is based on | Custom Prefix Environment Variable | Default Prefix | Example Name |
---|---|---|---|---|
Azure Resource Group | service instance ID | RESOURCE_GROUP_NAME_PREFIX | cloud-foundry- | cloud-foundry-2eac2d52-bfc9-4d0f-af28-c02187689d72 |
Azure Storage Account | part of service instance ID | STORAGE_ACCOUNT_NAME_PREFIX | cf | cf2eac2d52bfc94d0faf28c0 |
Azure Storage Containers | service instance ID | CONTAINER_NAME_PREFIX | cloud-foundry- | cloud-foundry-2eac2d52-bfc9-4d0f-af28-c02187689d72 |