0
votes

I'm trying to create a pool based on standard marketplace ubuntu image. I'm using Azure 4.0.0, image refernce, vm config reference and other things are written based off docs.microsoft.com

Here's my code:

import azure.batch as batch
from azure.batch import BatchServiceClient
from azure.batch.batch_auth import SharedKeyCredentials
from azure.batch import models
import sys

account = 'mybatch'
key = 'Acj1hh7vMR6DSodYgYEghjce7mHmfgfdgodYgYEghjce7mHmfgodYgYEghjce7mHmfgCj/7f3Zs1rHdfgPsdlA=='
batch_url = 'https://mybatch.westeurope.batch.azure.com'

creds = SharedKeyCredentials(account, key)
batch_client = BatchServiceClient(creds, base_url = batch_url)


pool_id = 'mypool3'

if batch_client.pool.exists( pool_id ):
  print( 'pool exists' )
  sys.exit()

vmc = models.VirtualMachineConfiguration(
  image_reference = models.ImageReference(
    offer = 'UbuntuServer', 
    publisher = 'Canonical',
    sku = '16.04.0-LTS', 
    version = 'latest', 
    virtual_machine_image_id = None
  ) ,
  node_agent_sku_id = 'batch.node.ubuntu 16.04'
)

pool_config = models.CloudServiceConfiguration(os_family = '5')

new_pool = models.PoolAddParameter(
  id = pool_id, 
  vm_size = 'small', 
  cloud_service_configuration = pool_config, 
  target_dedicated_nodes = 1,
  virtual_machine_configuration = vmc
)

batch_client.pool.add(new_pool)

Here are some image values I took from the azure portal ( Add pool JSON Editor ):

>

"imageReference": {

"publisher": "Canonical",

"offer": "UbuntuServer",

"sku": "16.04.0-LTS"

},

But when I ran the code I get an error:

Traceback (most recent call last):
  File "a.py", line 80, in <module>
    batch_client.pool.add(new_pool)
  File "/root/miniconda/lib/python3.6/site-packages/azure/batch/operations/pool_operations.py", line 310, in add
    raise models.BatchErrorException(self._deserialize, response)
azure.batch.models.batch_error_py3.BatchErrorException: {'additional_properties': {}, 'lang': 'en-US', 'value': 'The value provided for one of the properties in the request body is invalid.\nRequestId:d8a1f7fa-6f40-4e4e-8f41-7958egas6efa\nTime:2018-12-05T16:18:44.5453610Z'}

What image values are wrong ? Is this possible to get more information on this error with RequestId ?


UPDATE

I found a newer example here which is using this helper select_latest_verified_vm_image_with_node_agent_sku to get the image ref. Same error The value provided for one of the properties in the request body is invalid.

2
You can take a look at this link.Charles Xu
@CharlesXu This example also gives me errors. And it doesn't say what SDK version it is written for. I tried to update the code to fix errors, but next line also gives me an error and so on. The last one was AttributeError: 'BatchServiceClientConfiguration' object has no attribute 'signed_session'. Anyway, the values for creating image reference are the same. Thanks for the link anyway.sr9yar
Ok, I also did the test. I will give the answer if I resolve the problem.Charles Xu

2 Answers

1
votes

I did the test with your code and get the same error. Then I research and change some things in the code. And the problem caused by two things.

First:

pool_config = models.CloudServiceConfiguration(os_family = '5')

You can take a look at the description of the models.CloudServiceConfiguration:

os_family: The Azure Guest OS family to be installed on the virtual
     machines in the pool. Possible values are: 2 - OS Family 2, equivalent to
     Windows Server 2008 R2 SP1. 3 - OS Family 3, equivalent to Windows Server
     2012. 4 - OS Family 4, equivalent to Windows Server 2012 R2. 5 - OS Family
     5, equivalent to Windows Server 2016. For more information, see Azure
     Guest OS Releases

Maybe this property is set for windows. You can take away this configuration.

Second:

vm_size = 'small', 

You should set the vmSize with a real VM size. For example, Standard_A1. See Choose a VM size for compute nodes in an Azure Batch pool.

Hope this will help you. If you need more help please give me the message.

0
votes

I think there are a lof of confusing examples on the net, or they simply match older version of SDK.

Digging deeper into the docs I found this.

cloud_service_configuration CloudServiceConfiguration The cloud service configuration for the pool. This property and virtualMachineConfiguration are mutually exclusive and one of the properties must be specified. This property cannot be specified if the Batch account was created with its poolAllocationMode property set to 'UserSubscription'.

In my case I could use only cloud_service_configuration = pool_config or virtual_machine_configuration = vmc, but not both at the same time.

This is the working code:

new_pool = models.PoolAddParameter(
  id = pool_id, 
  vm_size = 'BASIC_A1', 
  target_dedicated_nodes = 1,
  virtual_machine_configuration = vmc
)