如何在 Azure 批处理池中使用 Azure 共享库 VM 映像



我已经从通用 VM 创建了一个共享映像库,我正在尝试在 Azure 批处理池创建中使用它。但我没有成功。我正在使用 C# 创建批处理池。以前有人这样做过吗?有人可以给我一些关于如何成功的提示吗?

是的,您在身份验证上是正确的,调用 Azure Batch Management 服务的应用程序使用 Azure Active Directory (Azure AD( 进行身份验证。

批处理管理 .NET 库公开用于处理批处理帐户、帐户密钥、应用程序和应用程序包的类型。批处理管理 .NET 库是一个 Azure 资源提供程序客户端,与 Azure 资源管理器一起使用,以编程方式管理这些资源。需要 Azure AD 才能对通过任何 Azure 资源提供程序客户端(包括批处理管理 .NET 库(和通过 Azure 资源管理器发出的请求进行身份验证。

在下面的文章中,您可以阅读有关注册应用程序和访问 Batch 客户端所需权限的更多信息:

https://learn.microsoft.com/en-us/azure/batch/batch-aad-auth-management

客户端应用程序使用应用程序 ID(也称为客户端 ID(在运行时访问 Azure AD。

使用正确的权限集向 Azure AD 进行身份验证后,可以使用以下代码来执行操作:

private static void CreateBatchPool(BatchClient batchClient, VirtualMachineConfiguration vmConfiguration)
{
try
{
CloudPool pool = batchClient.PoolOperations.CreatePool(
poolId: PoolId,
targetDedicatedComputeNodes: PoolNodeCount,
virtualMachineSize: PoolVMSize,
virtualMachineConfiguration: vmConfiguration);
pool.Commit();
}
...

参考:

https://learn.microsoft.com/en-us/azure/batch/batch-custom-images#create-a-pool-from-a-shared-image-using-c

您可以浏览下面的存储库以更好地了解它:

https://github.com/Azure-Samples/azure-batch-samples/blob/master/CSharp/AccountManagement/Program.cs

此外,要打开 BatchClient 连接,您需要传递 BatchTokenCredentials:

public static Microsoft.Azure.Batch.BatchClient Open (Microsoft.Azure.Batch.Auth.BatchTokenCredentials credentials);

附加参考:

https://github.com/paulo-santos/azure-batch-samples/blob/master/CSharp/BatchExplorer/Service/BatchService.cs

希望对您有所帮助。

若要使用共享映像库创建自定义池,需要 AAD 身份验证。可以注册服务主体来执行此操作,如文档使用 Active Directory 对 Batch 服务解决方案进行身份验证中所述。它具有 C# 中的示例代码。

我还写了一篇关于如何使用 sig 创建池的文章。示例代码是用Python编写的,但背后的想法是相同的。

最新更新