我想使用我通过批处理作业创建的自定义 ubuntu VM 镜像。我可以通过从 azure 门户本身选择自定义镜像来创建一个新池,但我想编写构建脚本以使用 azure 批处理 java sdk 执行相同的操作。这是我能想到的:
List<NodeAgentSku> skus = client.accountOperations().listNodeAgentSkus().findAll({ it.osType() == OSType.LINUX })
String skuId = null
ImageReference imageRef = new ImageReference().withVirtualMachineImageId('/subscriptions/$SUBSCRIPTION_ID/resourceGroups/$RESOURCE_GROUP_NAME/providers/Microsoft.Compute/images/$CUSTOM_VM_IMAGE_NAME')
for (NodeAgentSku sku : skus) {
for (ImageReference imgRef : sku.verifiedImageReferences()) {
if (imgRef.publisher().equalsIgnoreCase(osPublisher) && imgRef.offer().equalsIgnoreCase(osOffer) && imgRef.sku() == '18.04-LTS') {
skuId = sku.id()
break
}
}
}
VirtualMachineConfiguration configuration = new VirtualMachineConfiguration()
configuration.withNodeAgentSKUId(skuId).withImageReference(imageRef)
client.poolOperations().createPool(poolId, poolVMSize, configuration, poolVMCount)
但是我遇到了异常:
Caused by: com.microsoft.azure.batch.protocol.models.BatchErrorException: Status code 403, {
"odata.metadata":"https://analyticsbatch.eastus.batch.azure.com/$metadata#Microsoft.Azure.Batch.Protocol.Entities.Container.errors/@Element","code":"AuthenticationFailed","message":{
"lang":"en-US","value":"Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.\nRequestId:bf9bf7fd-2ef5-497b-867c-858d081137e6\nTime:2019-04-17T23:08:17.7144177Z"
},"values":[
{
"key":"AuthenticationErrorDetail","value":"The specified type of authentication SharedKey is not allowed when external resources of type Compute are linked."
}
]
}
我绝对认为我获取 skuId 的方式是错误的。由于 client.accountOperations().listNodeAgentSkus() 没有列出自定义镜像,我只是想根据我用来创建自定义镜像的 ubuntu 版本提供 skuId 。
那么使用 java sdk 为 azure 批处理帐户使用自定义 VM 镜像创建池的正确方法是什么?
最佳答案
您必须使用 Azure Active Directory 凭据才能创建包含自定义镜像的池。它位于 Batch Custom Image doc 的先决条件部分。 .
这是一个常见问题:
关于azure - 如何使用java sdk基于自定义VM镜像创建azure批处理池,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55737186/