This article about the Microsoft Windows Azure SDK python features . Windows Azure provides a multiple features that support the infrastructure, platform, and software services like storage, virtual machines, virtual networks, queues, tables, blobs, SQL services, websites, mobile services and cloud services. One of the most populat product of Microsoft is as software as a service or "SaaS" is Office365. The following paragraphs will talk about the Python SDK features and at the end of topic you will be able to install and know all Azure features . First, to install the python SDK of windows Azure clickhere.
Windows Azure SDK Python Features:
1- Storage Features: Cloud Storage is one of the core elements of Azure's IAAS. Windows Azure storage provides different kinds of storage and different ways to manage these data.
- Tables: no SQL structured storage. It is a key/value storage.
- Blobs: Simple storage interface for unstructured data like videos, images, and virtual machines VHDs.
- Storage Queues: Persistent messaging storage system is used specially for logging.
2- Compute Features: Execution Models or compute models that Windows Azure provides are four models: Virtual Machines, Cloud Services,Websites, and Mobile Services. We will focus on the virtual machines and cloud services only.
- Virtual Machines
- Cloud Service
- Website Service
- Mobile Service
3- Network Features
- Virtual Private Networks
- Hybrid networks
SERVICE MANAGEMENT
Service management is used to manage the cloud services, storage accounts, authentication and creating new deployments on Windows Azure, so the following describe how to setup the certificates to authenticate azure services, list the location of Windows Azure data center, create a new cloud service and create new deployment.
Setup your certificate:
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, 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
After you have created the certificate, you will need to upload the .cer file to Microsoft Azure via the "Upload" action of the "Settings" tab of the management portal. To initialize the management service, pass in your subscription id and the path to the .pem file.
from azure.servicemanagement import ServiceManagementService subscription_id = '00000000-0000-0000-0000-000000000000' cert_file = 'mycert.pem' sms = ServiceManagementService(subscription_id, cert_file)
Create a Cloud Service:
A cloud service is also known as a hosted service (from earlier versions of Microsoft 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 Microsoft Azure), a label (automatically encoded to base-64), and the location or the affinity group for your service.
name = "myhostedservice" desc = name label = name location = 'West US' result = sms.create_hosted_service(name, label, desc, location=location)
List available Datacenter locations:
locations = sms.list_locations() for location in locations: print(location.name)
Create Storage Account:
To create a storage service, you need a name for the service (between 3 and 24 lowercase characters and unique within Microsoft Azure), a label (up to 100 characters, automatically encoded to base-64), and either a location or an affinity group.
To create a storage service, you need a name for the service (between 3 and 24 lowercase characters and unique within Microsoft Azure), a label (up to 100 characters, automatically encoded to base-64), and either a location or an affinity group.
name = "mystorageservice" desc = name label = name location = 'West US' result = sms.create_storage_account(name, desc, label, location=location)
Create New Virtual Machine Deployment:
To make a new deployment to Azure you must store the package file in a Microsoft Azure Blob Storage account under the same subscription as the hosted service to which the package is being uploaded.
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)
STORAGE MANAGEMENT
First if you need to start writing your application to get any service of storage services you will need to get to authenticate your service by using account name for your storage account and the primary account key of this account see the following Figure:
![]() |
| Windows Azure Storage Account |
get the storage account name, storage account primary key. for example if you like to create a new table service in this storage account , just start by the following lines:
from azure.storage import TableServicets = TableService(account_name, account_key)ts.create_table('tasktable')
To add a new entity in this table:
from datetime import datetimets = TableService(account_name, account_key)ts.create_table('tasktable')ts.insert_entity('tasktable',{'PartitionKey' : 'tasksSeattle','RowKey': '1','Description': 'Take out the trash','DueDate': datetime(2011, 12, 14, 12)})
to fetch this entity:
ts = TableService(account_name, account_key)entity = ts.get_entity('tasktable', 'tasksSeattle', '1')
To start working on Blob Services, we need to illustrate what are the blobs ???? Windows Azure Blobs is designed to store unstructured data like images, videos, and file systems, provides inexpensive
storage in a single blob can be large up to 1 Tera bytes per Blob. Blobs is divides into two types of storage Block Blobs and Page Blobs . For upload operation you can upload a parallel uploads if the storage type is Blob.
To create a new container in the same storage account:
from azure.storage import BlobServiceblob_service = BlobService(account_name, account_key)blob_service.create_container('images')
To upload a file as an block blob
from azure.storage import BlobServiceblob_service = BlobService(account_name, account_key)blob_service.put_block_blob_from_path('images', 'image.png', 'uploads/image.png')
To download a file as a block blob in your storage account:
from azure.storage import BlobServiceblob_service = BlobService(account_name, account_key)blob = blob_service.get_blob_to_path('images', 'image.png', 'downloads/image.png')
Storage Queue as mentioned before Persistent messaging storage system is used specially for logging so to create a new queue service
from azure.storage import QueueServicequeue_service = QueueService(account_name, account_key)queue_service.create_queue('taskqueue')
to insert a new message in this queue
from azure.storage import QueueServicequeue_service = QueueService(account_name, account_key)queue_service.put_message('taskqueue', 'Hello world!')
to get the queue messages and delete this message from queue
from azure.storage import QueueServicequeue_service = QueueService(account_name, account_key)messages = queue_service.get_messages('taskqueue')queue_service.delete_message('taskqueue', messages[0].message_id, messages[0].pop_receipt)
Network post will be coming soon

0 comments:
Post a Comment