azure - 如何使用java sdk基于自定义VM镜像创建azure批处理池

标签 azure azure-batch

我想使用我通过批处理作业创建的自定义 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 的先决条件部分。 .

这是一个常见问题:

  1. Custom Image under AzureBatch ImageReference class not working
  2. Azure Batch Pool: How do I use a custom VM Image via Python?

关于azure - 如何使用java sdk基于自定义VM镜像创建azure批处理池,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55737186/

相关文章:

wpf - 启用侧面加载后,为什么 MSIX 不会在每次应用程序运行时自动检查更新?

python - Azure批量作业调度: Task doesn't run recurrently

azure - 从 Microsoft Azure 运行耗时的 .exe

azure - Azure BizSpark 费用会自动支付吗

azure - 某些值的平均值,由其他消息中的条目确定

python - Azure 批处理池 : How do I use a custom VM Image via Python?

azure - 使用 Microsoft Azure 作为计算集群

c# - 如何将使用 SqlServer 作为数据库服务器的应用程序部署到 Azure Batch

entity-framework - 修改 Entity Framework 迁移是否安全,以便以不同的方式执行而不是删除并重新创建索引?

azure - Azure 存储帐户的价格是每个帐户还是单一价格并且可以创建多个存储帐户?