我正在尝试基于标准市场ubuntu映像创建一个池。我正在使用Azure 4.0.0,image refernce,vm config reference,其他内容都是基于docs.microsoft.com
编写的这是我的代码:
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)
以下是我从azure门户(添加池JSON编辑器)中获取的一些图像值:
>
“ imageReference”:{
“发布者”:“规范”,
“优惠”:“ UbuntuServer”,
“ sku”:“ 16.04.0-LTS”
},
但是当我运行代码时,我得到一个错误:
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'}
哪些图像值错误?是否可以通过RequestId获得有关此错误的更多信息?
更新
我发现一个newer example here正在使用此助手select_latest_verified_vm_image_with_node_agent_sku来获取图像参考。相同错误The value provided for one of the properties in the request body is invalid.
答案 0 :(得分:1)
我对您的代码进行了测试,并得到了相同的错误。然后,我研究并更改代码中的某些内容。而问题则由两件事引起。
第一:
pool_config = models.CloudServiceConfiguration(os_family = '5')
您可以查看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
也许此属性是为Windows设置的。您可以取消此配置。
第二:
vm_size = 'small',
您应将vmSize
设置为实际的VM大小。例如, Standard_A1 。参见Choose a VM size for compute nodes in an Azure Batch pool。
希望这会对您有所帮助。如果您需要更多帮助,请给我消息。
答案 1 :(得分:0)
我认为网上有很多令人困惑的示例,或者它们仅与旧版SDK相匹配。
深入研究我发现的this文档。
cloud_service_configuration CloudServiceConfiguration云 池的服务配置。 此属性和 virtualMachineConfiguration是互斥的,并且是其中之一 必须指定属性。如果 创建批次帐户,并将其poolAllocationMode属性设置为 “用户订阅”。
就我而言,我只能使用
cloud_service_configuration = pool_config
或 virtual_machine_configuration = vmc
,但不能同时使用。
这是工作代码:
new_pool = models.PoolAddParameter(
id = pool_id,
vm_size = 'BASIC_A1',
target_dedicated_nodes = 1,
virtual_machine_configuration = vmc
)