Search code examples
pythonazureazure-worker-roles

How do I get the location of Local Storage for an Azure Worker Role written in Python?


I'm attempting to deploy an Azure Worker Role written in Python to our account. It's in Python to include a specific library (moviepy) needed to accomplish the task at hand. However, moviepy expects filenames as strings in the arguments for its objects. In C#, there is a method buried in the Azure libraries

LocalResource localResource = RoleEnvironment.GetLocalResource(workerRoleStorageName);

that returns an object with the necessary path in a property. However, the documentation for the Python Azure library fails to mention any such method, or indeed, any mention of anything similar. I've attempted to bumble my way through the library (via Intellisense) to find it, but have failed insofar.

We have already created the Local Storage in the Cloud Service Deployment project VS creates. Does anyone have any experience with accessing Azure Local Storage from a Python Worker Role, or even a link addressing how to do so?


Solution

  • According to the offical reference for WorkerRole Schema, as below.

    %ROLEROOT% is an environment variable maintained by Azure and it represents the root folder location for your role. The \%ROLEROOT%\Approot folder represents the application folder for your role.

    So you can try to get the storage root location of WorkerRole on Azure via the code below.

    import os
    roleroot = os.environ.get('ROLEROOT')