Python is a language designed for quick results and straight forward coding. Azure provides a comprehensive SDK for Python for both Classic and Resource Manager services. To get started with Python on Azure, we need to make sure Python can talk to our Azure subscription.
For Classic services we enable this by uploading a management certificate.
Accessing Azure Classic (ASM) deployments using Python
The first step is to create a management certificate that we can upload to Azure. The management certificate will let Azure know, who we are and Azure will give us access to the resources that we own based on our identity.
The easiest way to generate a management certificate is through OpenSSL. A management certificate consists of two parts – a client and a server certificate. We are going to upload the server certificate to Azure and keep the client certificate safe on our client. Only if both parts are used in conjunction we will be able to prove our identity and if our client file is compromised then we should regenerate the management certificate as soon as possible.
The bash command generates my personal certificate first. It will be valid for 365 days. We can then create a server certificate based on the client certificate.
We will end up with the two required files:
More information: http://www.openssl.org/docs/apps/openssl.html
makecert.exe can create a similar set of certificates: https://azure.microsoft.com/en-us/documentation/articles/cloud-services-certs-create/
Once we have the certificates created we need to upload our server certificate to the Azure Management Portal. https://manage.windowsazure.com/
The option to do this is under Settings > Management Certificates > Upload.
Please check the subscription alignment for the certificate.
Once our certificate is uploaded we can log into your subscription using Python and the client certificate.
from azure import * from azure.servicemanagement import * subscription_id = 'eeeeeeee-bbbb-zzzz-yyyy-xxxxxxxxxxxxx' certificate_path = 'C:/Users/dasto/mycert.pem' my_service_management = ServiceManagementService(subscription_id, certificate_path)