0
votes

I'm making a python app that launches a batch. I want, via user inputs, to create a pool. For simplicity, I'll just add all the applications present in the batch account to the pool. I'm not able to get the list of available application packages. This is the portion of code:

import azure.batch.batch_service_client as batch
from azure.common.credentials import ServicePrincipalCredentials

credentials = ServicePrincipalCredentials(
    client_id='xxxxx',
    secret='xxxxx',
    tenant='xxxx',
    resource="https://batch.core.windows.net/"
)
batch_client = batch.BatchServiceClient(
    credentials,
    base_url=self.AppData['CloudSettings'][0]['BatchAccountURL'])
# Get list of applications
batchApps = batch_client.application.list()

I can create a pool, so credentials are good and there are applications but the returned list is empty. Can anybody help me with this?

Thank you, Guido

Update:

I tried:

import azure.batch.batch_service_client as batch

batchApps = batch.ApplicationOperations.list(batch_client)

and

import azure.batch.operations as batch_operations

batchApps = batch_operations.ApplicationOperations.list(batch_client)

but they don't seem to work. batchApps is always empty. I don't think it's an authentication issue since I'd get an error otherwise. At this point I wonder if it just a bug in the python SDK?

The SDK version I'm using is:

  • azure.batch: 4.1.3

  • azure: 4.0.0

This is a screenshot of the empty batchApps var:

enter image description here

2
How are you determining there is nothing in the returned body? You should note the response is paged and it is possible a page is empty so you need to make sure to either follow next links. Also you should post the results of indivudal get operations to show that there are in fact results not being returned in the list. The version of the SDK will also be helpful.brklein
@brklein I added the info you requested. Does it look empty to you?guidout
The list looks empty. I was more looking for a get request of an application that you thought should have been listed to ensure the packages were listed/they existed in the right account. If you want to disclose the accountName/requestId I can go look at service logs to verify behavior as well.brklein
@brklein sorry I got busy. Sure, where do I get the requestId?guidout
Yes should get an error if the service doesn't give a response/returns with an auth error. Have you activated your app packages? docs.microsoft.com/en-us/rest/api/batchmanagement/…brklein

2 Answers

1
votes

Is this the link you are looking for:

hope this helps.

0
votes

I haven't tried lately using the Azure Python SDK but the way I solved this was to use the Azure REST API: https://docs.microsoft.com/en-us/rest/api/batchservice/application/list

For the authorization, I had to create an application and give it access to the Batch services and the I programmatically generated the token with the following request:

data = {'grant_type': 'client_credentials',
    'client_id': clientId,
    'client_secret': clientSecret,
    'resource': 'https://batch.core.windows.net/'}

postReply = requests.post('https://login.microsoftonline.com/' + tenantId + '/oauth2/token', data)