Azure批处理池:如何通过Python使用自定义VM映像? [英] Azure Batch Pool: How do I use a custom VM Image via Python?

查看:105
本文介绍了Azure批处理池:如何通过Python使用自定义VM映像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Python创建我的Pool。我可以在使用市场上的映像(Ubuntu Server 16.04)时执行此操作,但是我想使用自定义映像(但也要使用Ubuntu Server 16.04)-我已经准备了所需的库和设置。

I want to create my Pool using Python. I can do this when using an image (Ubuntu Server 16.04) from the marketplace, but I want to use a custom image (but also Ubuntu Server 16.04) -- one which I have prepared with the desired libraries and setup.

这是我创建池的方式:

new_pool = batch.models.PoolAddParameter(
      id=pool_id,
      virtual_machine_configuration=batchmodels.VirtualMachineConfiguration(
          image_reference=image_ref_to_use, # ??
          node_agent_sku_id=sku_to_use),
      vm_size=_POOL_VM_SIZE,
      target_dedicated_nodes=_POOL_NODE_COUNT,
      start_task=start_task,
      max_tasks_per_node=_CORES_PER_NODE
)

我想像一下我需要使用 batch.models.ImageReference()创建我的图像引用...但是我不知道如何使用它。

I imaging that I need to use batch.models.ImageReference() to create my image reference... but I do not know how to use it.

是的,我检查了文档,它表示以下内容:

Yes, I checked the documentation, which says the following:


对Azure虚拟机的引用市场映像或自定义的
Azure虚拟机映像。

A reference to an Azure Virtual Machines Marketplace image or a custom Azure Virtual Machine image.

它列出的参数为:


  • 发布者(str)

  • 提供(str)

  • sku(str)

  • 版本(str)

  • virtual_machine_image_id(str)

  • publisher (str)
  • offer (str)
  • sku (str)
  • version (str)
  • virtual_machine_image_id (str)

但是,参数 virtual_machine_image_id 不存在...换句话说, batch.models.ImageReference(virtual_machine_image_id)

However, the parameter virtual_machine_image_id does not exists... In other words, batch.models.ImageReference(virtual_machine_image_id) is not allowed.

如何为我的泳池使用自定义图像?

How can I use a custom image for my Pool?

更新

所以我想出了如何使用自定义图片的方法……事实证明,无论我卸载了几次Azure python库并重新安装它们后, virtual_machine_image_id 永远无法使用。

So I figured out how to use a custom image... it turns out that no matter how many times I uninstall the azure python libraries and re-install them, the virtual_machine_image_id is never available.

然后我此处下载了该zip文件。打开它,检查 ImageReference 类,并观察其结果,在<$ c中可以使用 virtual_machine_image_id ImageReference 类的$ c> __ init __ 函数。然后,我下载了python wheel并使用pip进行安装。繁荣了它。

I then went here downloaded the zip. Opened it up, checked the ImageReference class and low-and-behold, the virtual_machine_image_id was available in the __init__ function of the ImageReference class. I then downloaded the python wheel and used pip to install it. Boom it worked.

或者我想。

然后我不得不为想弄清楚是什么而战。 node_agent_sku_id 是...仅通过手动创建池并查看 Batch Node Agent SKU ID 字段来管理。来找到它。

I then had to fight though trying to figure out what the node_agent_sku_id is... only by manually creating a Pool and seeing the Batch Node Agent SKU ID field did I manage to find it.

现在,我正在努力进行身份验证...

Now I am struggling with the Authentication...

我得到的错误是:


服务器无法验证请求。确保
Authorization标头的值正确构成,包括签名。

Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.

AuthenticationErrorDetail:外部使用不允许指定类型的身份验证
SharedKey Compute类型的资源是
链接的。

AuthenticationErrorDetail: The specified type of authentication SharedKey is not allowed when external resources of type Compute are linked.

azure.batch.models.batch_error.BatchErrorException:{'lang':
'en-US','value':'服务器无法通过身份验证请求。确保
正确构成Authorization标头的值,包括

签名.\nRequestId:f8c1a3b3-65c4-4efd-9c4f-75c5c253f992\nTime:2017-10-15T20:36 :06.7898187Z'}

azure.batch.models.batch_error.BatchErrorException: {'lang': 'en-US', 'value': 'Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.\nRequestId:f8c1a3b3-65c4-4efd-9c4f-75c5c253f992\nTime:2017-10-15T20:36:06.7898187Z'}

从错误中得知,我不允许我使用 SharedKeyCredentials

From the error, I understand that I am not allowed to use SharedKeyCredentials:

credentials = batchauth.SharedKeyCredentials(_BATCH_ACCOUNT_NAME,
                                             _BATCH_ACCOUNT_KEY)

batch_client = batch.BatchServiceClient(
    credentials,
    base_url=_BATCH_ACCOUNT_URL)

我该怎么办?

更新2

确定。用户 fpark 告诉我我需要使用:

OK. User fpark has informed me that I need to use:

from azure.batch import BatchServiceClient
from azure.common.credentials import ServicePrincipalCredentials

credentials = ServicePrincipalCredentials(
    client_id=CLIENT_ID,
    secret=SECRET,
    tenant=TENANT_ID,
    resource="https://batch.core.windows.net/"
)
    batch_client = BatchServiceClient(
    credentials,
    base_url=BATCH_ACCOUNT_URL
)

进行身份验证。不幸的是,上面的代码在此处,并且未提及 CLIENT_ID 等。

to authenticate. Unfortunately, that the code above is described here and makes no reference to what CLIENT_ID et. al are.

然后,我设法找到了另一本似乎相同的文档: https://azure-sdk-for-python.readthedocs.io/en/v2.0.0rc3/resourcemanagementauthentication.html

I then managed to find another piece of documentation which appears to be the same thing: https://azure-sdk-for-python.readthedocs.io/en/v2.0.0rc3/resourcemanagementauthentication.html

该页面将我指向另一个网页: https://docs.microsoft.com/zh-cn/azure/azure-resource-manager/resource-group-create-service -principal-portal

That page pointed me to another webpage: https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal

我遵循了该教程,并最终对我的应用程序进行了身份验证...

I followed that tutorial and managed to finally authenticate my application...

注意

在创建应用程序时,教程将告诉您:

When creating your application, the tutorial will tell you:


提供应用程序的名称和URL。选择Web应用程序/
API或本机作为要创建的应用程序类型。在
设置完值后,选择创建。

Provide a name and URL for the application. Select either Web app / API or Native for the type of application you want to create. After setting the values, select Create.

请勿选择本地,因为您将无法选择获取应用程序密钥...

DO NOT select Native as you will not have the option to get an application key...

推荐答案

必需的最低Azure批处理SDK

azure-batch 需要Python SDK v4.0.0或更高版本。通常,使用 pip install --upgrade azure-batch ,您应该只获取最新版本。如果这样不起作用,则可以添加-force-reinstall 选项以强制执行(使用-upgrade )。

The azure-batch Python SDK v4.0.0 or higher is required. Typically with pip install --upgrade azure-batch you should just get the newest version. If that doesn't work you can add the --force-reinstall option to pip to force it (with --upgrade).

节点代理Sku ID

关于 node_agent_sku_id ,您需要使用 list_node_agent_skus 操作以查看操作系统与支持的节点代理程序skus之间的映射。

Regarding the proper value for node_agent_sku_id, you need to use the list_node_agent_skus operation to see the mapping between operating systems and the node agent skus supported.

需要Azure Active Directory身份验证

关于身份验证问题,您必须使用 Azure Active Directory身份验证以使用此功能。

Regarding the auth issue, you must use Azure Active Directory authentication to use this feature. It will not work with shared key auth.

文档

更多信息可以可以在本指南中找到,包括启用该软件所需的所有先决条件自定义图片。

More information can be found in this guide, including all pre-requisites needed to enable custom images.

这篇关于Azure批处理池:如何通过Python使用自定义VM映像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆