Dormidont
Dormidont

Reputation: 233

Python azure module: how to create a new deployment

azure.servicemanagmentservice.py contains:

def create_deployment(self, service_name, deployment_slot, name,
                          package_url, label, configuration,
                          start_deployment=False,
                          treat_warnings_as_error=False,
                          extended_properties=None):

What is package_url and configuration? Method comment indicates that

 package_url:
            A URL that refers to the location of the service package in the
            Blob service. The service package can be located either in a
            storage account beneath the same subscription or a Shared Access
            Signature (SAS) URI from any storage account.
....
configuration:
        The base-64 encoded service configuration file for the deployment.

All over the internet there are references to Visual Studio and Powershell to create those files. What do they look like? Can I manually create them? Can azure module create them? Why is Microsoft service so confusing and lacks documentation?

I am using https://pypi.python.org/pypi/azure Python Azure SDK. I am running Mac OS X on my dev box, so I don't have Visual Studio or cspack.exe. Any help appreciated. Thank you.

Upvotes: 0

Views: 578

Answers (1)

Ming Xu - MSFT
Ming Xu - MSFT

Reputation: 2116

According to your description, it looks like you are trying to use Python Azure SDK to create a cloud service deployment. Here is the documentation of how to use the create_deployment function.

Can I manually create them? Can azure module create them?

If you mean you wanna know how to create an Azure deployment package of your Python app, based on my experience, there are several options you can leverage.

  • If you have a visual studio, you can create a cloud project from projects’ template and package the project via 1 click. In VS, create new project -> cloud -> enter image description here

Then package the project: enter image description here

After you packaging the project, you would have the .cspkg file like this: enter image description here

For your better reference, I have uploaded the testing project at: https://onedrive.live.com/redir?resid=7B27A151CFCEAF4F%21143283

As to the ‘configuration’, it means the base-64 encoded service configuration file (.cscfg) for the deployment enter image description here

In Python, we can set up the ‘configuration’ via below code

configuration = base64.b64encode(open('E:\\TestProjects\\Python\\YourProjectFolder\\ServiceConfiguration.Cloud.cscfg', 'rb').read())

Hope above info could provide you a quick clarification. Now, let’s go back to Python SDK itself and see how we can use create_deployment function to create a cloud service deployment accordingly.

Firstly, I’d like to suggest you to refer to https://azure.microsoft.com/en-us/documentation/articles/cloud-services-python-how-to-use-service-management/ to get the basic idea of what azure Service Management is and how it’s processing. In general, we can make create_deployment function work via 5 steps

  1. Create your project’s deployment package and set up a configuration file (.cscfg) – (to have the quick test, you can use the one that I have uploaded)
  2. Store your project’s deployment package in a Microsoft Azure Blob Storage account under the same subscription as the hosted service to which the package is being uploaded. Get the blob file’s URL (or use a Shared Access Signature (SAS) URI from any storage account). You can use Azure storage explorer to upload the package file, and then it will be shown on Azure portal. enter image description here
  3. Use OpenSSL to create your management certificate. It is needed to create two certificates, one for the server (a .cer file) and one for the client (a .pem file), the article I mentioned just now have provided a detailed info https://azure.microsoft.com/en-us/documentation/articles/cloud-services-python-how-to-use-service-management/

Screenshot of my created certificates enter image description here Then, upload .cer certificate to Azure portal: SETTINGS -> management certificate tab -> click upload button (on the bottom of the page).

  1. Create a cloud service in Azure and keep the name in mind.
  2. Create another project to test Azure SDK - create_deployment, code snippet for your reference:

subscription_id = 'Your subscription ID That could be found in Azure portal'

certificate_path = 'E:\YourFoloder\mycert.pem'

sms = ServiceManagementService(subscription_id, certificate_path)

def TestForCreateADeployment():
    service_name = "Your Cloud Service Name"
    deployment_name = "name"
    slot = 'Production'
    package_url = ".cspkg file’s URL – from your blob"
    configuration = base64.b64encode(open('E:\\TestProjects\\Python\\ YourProjectFolder\\ServiceConfiguration.Cloud.cscfg ', 'rb').read())
    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)

Here is running result’s screenshot: enter image description here enter image description here

Upvotes: 2

Related Questions