Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
2012-??-?? Version 0.9.0
* Initial Release
2012-10-16 Version 0.6.0
* Added service management API
* Added ability to specify custom hosts
* Added proxy server support (HTTP CONNECT tunneling)
2012-06-06 Version 0.5.0
* Initial Release
164 changes: 125 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ Python Developer Center.
* Service Bus
* Queues: create, list and delete queues; create, list, and delete subscriptions; send, receive, unlock and delete messages
* Topics: create, list, and delete topics; create, list, and delete rules
* Service Management
* storage accounts: create, update, delete, list, regenerate keys
* affinity groups: create, update, delete, list, get properties
* locations: list
* hosted services: create, update, delete, list, get properties
* deployment: create, get, delete, swap, change configuration, update status, upgrade, rollback
* role instance: reboot, reimage
* discover addresses and ports for the endpoints of other role instances in your service
* get configuration settings and access local resources
* get role instance information for current role and other role instances
* query and set the status of the current role

# Getting Started
## Download Source Code
Expand All @@ -45,20 +56,21 @@ the local Storage Emulator (with the exception of Service Bus features).
# Usage
## Table Storage

To ensure a table exists, call **create_table**:
To ensure a table exists, call **create\_table**:

```Python
from azure.storage import TableService
ts = TableService(account_name, account_key)
table = ts.create_table('tasktable')
ts.create_table('tasktable')
```

A new entity can be added by calling **insert_entity**:
A new entity can be added by calling **insert\_entity**:

```Python
from datetime import datetime
ts = TableService(account_name, account_key)
table = ts.create_table('tasktable')
table.insert_entity(
ts.create_table('tasktable')
ts.insert_entity(
'tasktable',
{
'PartitionKey' : 'tasksSeattle',
Expand All @@ -69,7 +81,7 @@ table.insert_entity(
)
```

The method **get_entity** can then be used to fetch the entity that was just inserted:
The method **get\_entity** can then be used to fetch the entity that was just inserted:

```Python
ts = TableService(account_name, account_key)
Expand All @@ -78,27 +90,25 @@ entity = ts.get_entity('tasktable', 'tasksSeattle', '1')

## Blob Storage

The **create_container** method can be used to create a
The **create\_container** method can be used to create a
container in which to store a blob:

```Python
from azure.storage import BlobService
blob_service = BlobService()
container = blob_service.create_container('taskcontainer')
blob_service = BlobService(account_name, account_key)
blob_service.create_container('taskcontainer')
```

To upload a file (assuming it is called task1-upload.txt, it contains the exact text "hello world" (no quotation marks), and it is placed in the same folder as the script below), the method **put_blob** can be used:
To upload a file (assuming it is called task1-upload.txt, it contains the exact text "hello world" (no quotation marks), and it is placed in the same folder as the script below), the method **put\_blob** can be used:

```Python
from azure.storage import BlobService
blob_service = BlobService(account_name, account_key)
blob_service.put_blob('taskcontainer', 'task1',
blobService = azure.createBlobService()
blobService.put_blob('taskcontainer', 'task1', file('task1-upload.txt').read())
blob_service.put_blob('taskcontainer', 'task1', file('task1-upload.txt').read(), 'BlockBlob')

```

To download the blob and write it to the file system, the **get_blob** method can be used:
To download the blob and write it to the file system, the **get\_blob** method can be used:

```Python
from azure.storage import BlobService
Expand All @@ -108,88 +118,164 @@ blob = blob_service.get_blob('taskcontainer', 'task1')

## Storage Queues

The **create_queue** method can be used to ensure a queue exists:
The **create\_queue** method can be used to ensure a queue exists:

```Python
from azure.storage import QueueService
queue_service = QueueService(account_name, account_key)
queue = queue_service.create_queue('taskqueue')
queue_service.create_queue('taskqueue')
```

The **put_message** method can then be called to insert the message into the queue:
The **put\_message** method can then be called to insert the message into the queue:

```Python
from azure.storage import QueueService
queue_service = QueueService(account_name, account_key)
queue_service.put_message('taskqueue', 'Hello world!')
```

It is then possible to call the **get___messages** method, process the message and then call **delete_message** on the messages ID. This two-step process ensures messages don't get lost when they are removed from the queue.
It is then possible to call the **get\_messages** method, process the message and then call **delete\_message** with the message id and receipt. This two-step process ensures messages don't get lost when they are removed from the queue.

```Python
from azure.storage import QueueService
queue_service = QueueService(account_name, account_key)
messages = queue_service.get_messages('taskqueue')
queue_service.delete_message('taskqueue', messages[0].message_id)
queue_service.delete_message('taskqueue', messages[0].message_id, messages[0].pop_receipt)
```

## ServiceBus Queues

ServiceBus Queues are an alternative to Storage Queues that might be useful in scenarios where more advanced messaging features are needed (larger message sizes, message ordering, single-operaiton destructive reads, scheduled delivery) using push-style delivery (using long polling).

The **create_queue** method can be used to ensure a queue exists:
The **create\_queue** method can be used to ensure a queue exists:

```Python
from azure.servicebus import ServiceBusService
sbs = ServiceBusService(service_namespace, account_key)
queue = sbs.create_queue('taskqueue');
sbs = ServiceBusService(service_namespace, account_key, 'owner')
sbs.create_queue('taskqueue')
```

The **send__queue__message** method can then be called to insert the message into the queue:
The **send\_queue\_message** method can then be called to insert the message into the queue:

```Python
from azure.servicebus import ServiceBusService
sbs = ServiceBusService(service_namespace, account_key)
sbs.send_queue_message('taskqueue', 'Hello World!')
from azure.servicebus import ServiceBusService, Message
sbs = ServiceBusService(service_namespace, account_key, 'owner')
msg = Message('Hello World!')
sbs.send_queue_message('taskqueue', msg)
```

It is then possible to call the **read__delete___queue__message** method to dequeue the message.
It is then possible to call the **receive\_queue\_message** method to dequeue the message.

```Python
from azure.servicebus import ServiceBusService
sbs = ServiceBusService(service_namespace, account_key)
msg = sbs.read_delete_queue_message('taskqueue')
sbs = ServiceBusService(service_namespace, account_key, 'owner')
msg = sbs.receive_queue_message('taskqueue')
```

## ServiceBus Topics

ServiceBus topics are an abstraction on top of ServiceBus Queues that make pub/sub scenarios easy to implement.

The **create_topic** method can be used to create a server-side topic:
The **create\_topic** method can be used to create a server-side topic:

```Python
from azure.servicebus import ServiceBusService
sbs = ServiceBusService(service_namespace, account_key)
topic = sbs.create_topic('taskdiscussion')
sbs = ServiceBusService(service_namespace, account_key, 'owner')
sbs.create_topic('taskdiscussion')
```

The **send__topic__message** method can be used to send a message to a topic:
The **send\_topic\_message** method can be used to send a message to a topic:

```Python
from azure.servicebus import ServiceBusService
sbs = ServiceBusService(service_namespace, account_key)
sbs.send_topic_message('taskdiscussion', 'Hello world!')
from azure.servicebus import ServiceBusService, Message
sbs = ServiceBusService(service_namespace, account_key, 'owner')
msg = Message('Hello World!')
sbs.send_topic_message('taskdiscussion', msg)
```

A client can then create a subscription and start consuming messages by calling the **create__subscription** method followed by the **receive__subscription__message** method. Please note that any messages sent before the subscription is created will not be received.
A client can then create a subscription and start consuming messages by calling the **create\_subscription** method followed by the **receive\_subscription\_message** method. Please note that any messages sent before the subscription is created will not be received.

```Python
from azure.servicebus import ServiceBusService
sbs = ServiceBusService(service_namespace, account_key)
from azure.servicebus import ServiceBusService, Message
sbs = ServiceBusService(service_namespace, account_key, 'owner')
sbs.create_subscription('taskdiscussion', 'client1')
msg = Message('Hello World!')
sbs.send_topic_message('taskdiscussion', msg)
msg = sbs.receive_subscription_message('taskdiscussion', 'client1')
```


## Service Management

### Set-up certificates

You need to create two certificates, one for the server (a .cer file) and one for the client (a .pem file). To create the .pem file using [OpenSSL](http://www.openssl.org), execute this:

openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem

To create the .cer certificate, execute this:

openssl x509 -inform pem -in mycert.pem -outform der -out mycert.cer

### List Available Locations

```Python
locations = sms.list_locations()
for location in locations:
print(location.name)
```

### Create a Storage Service

To create a storage service, you need a name for the service (between 3 and 24 lowercase characters and unique within Windows Azure), a label (up to 100 characters, automatically encoded to base-64), and either a location or an affinity group.

```Python
name = "mystorageservice"
desc = name
label = name
location = 'West US'

result = sms.create_storage_account(name, desc, label, location=location)
```


### Create a Cloud Service

A cloud service is also known as a hosted service (from earlier versions of Windows Azure). The **create_hosted_service** method allows you to create a new hosted service by providing a hosted service name (which must be unique in Windows Azure), a label (automatically encoded to base-64), and the location *or* the affinity group for your service.

```Python
name = "myhostedservice"
desc = name
label = name
location = 'West US'

result = sms.create_hosted_service(name, label, desc, location=location)
```

### Create a Deployment

To make a new deployment to Azure you must store the package file in a Windows Azure Blob Storage account under the same subscription as the hosted service to which the package is being uploaded. You can create a deployment package with the [Windows Azure PowerShell cmdlets](https://www.windowsazure.com/en-us/develop/php/how-to-guides/powershell-cmdlets/), or with the [cspack commandline tool](http://msdn.microsoft.com/en-us/library/windowsazure/gg432988.aspx).

```Python
service_name = "myhostedservice"
deployment_name = "v1"
slot = 'Production'
package_url = "URL_for_.cspkg_file"
configuration = base64.b64encode(open(file_path, 'rb').read('path_to_.cscfg_file'))
label = service_name

result = sms.create_deployment(service_name,
slot,
deployment_name,
package_url,
label,
configuration)

operation = sms.get_operation_status(result.request_id)
print('Operation status: ' + operation.status)
```


** For more examples please see the [Windows Azure Python Developer Center](http://www.windowsazure.com/en-us/develop/python) **

# Need Help?
Expand Down
10 changes: 9 additions & 1 deletion src/azure.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<InterpreterArguments />
<InterpreterId>2af0f10d-7135-4994-9156-5d01c9c11b7e</InterpreterId>
<InterpreterVersion>2.7</InterpreterVersion>
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -34,6 +38,8 @@
<Compile Include="azure\http\httpclient.py" />
<Compile Include="azure\http\winhttp.py" />
<Compile Include="azure\http\__init__.py" />
<Compile Include="azure\servicemanagement\servicemanagementservice.py" />
<Compile Include="azure\servicemanagement\__init__.py" />
<Compile Include="azure\servicebus\servicebusservice.py" />
<Compile Include="azure\storage\blobservice.py" />
<Compile Include="azure\storage\queueservice.py" />
Expand All @@ -44,10 +50,12 @@
<Compile Include="azure\servicebus\__init__.py" />
<Compile Include="azure\storage\storageclient.py" />
<Compile Include="azure\storage\__init__.py" />
<Compile Include="setup.py" />
</ItemGroup>
<ItemGroup>
<Folder Include="azure\" />
<Folder Include="azure\http" />
<Folder Include="azure\tests\" />
<Folder Include="azure\servicemanagement" />
<Folder Include="azure\servicebus\" />
<Folder Include="azure\storage" />
</ItemGroup>
Expand Down
Loading