简体   繁体   English

Azure VM 配置 - 自定义数据

[英]Azure VM provisioning - custom data

anyone proficient in azure SDK for python?任何人精通 python 的 azure SDK 吗? I'm trying to create many VM's using an image that I captured from another VM.我正在尝试使用从另一个 VM 捕获的图像创建许多 VM。 Questions:问题:

  1. How do I put the custom image for deploying?如何放置自定义映像以进行部署?
poller =  compute_client.virtual_machines.begin_create_or_update(RESOURCE_GROUP_NAME, VM_NAME,
    {
        "location": LOCATION,
        "storage_profile": {
            "image_reference": {
                "publisher": 'Canonical',
                "offer": "UbuntuServer",
                "sku": "18.04-LTS",
                "version": "latest"
            }
        }
}
  1. How do I give custom data(metadata) to the instances?如何为实例提供自定义数据(元数据)? (the metadata will change from time to time) (元数据会不时更改)

This is the article I am following, https://docs.microsoft.com/en-us/azure/developer/python/azure-sdk-example-virtual-machines?tabs=cmd这是我正在关注的文章, https://docs.microsoft.com/en-us/azure/developer/python/azure-sdk-example-virtual-machines?tabs=cmd

Any help is appreciated.任何帮助表示赞赏。

If you have captured a managed image from Azure VM, you can reference it with id in ImageReference when deploying a new VM as the following code.如果您已从 Azure VM 捕获托管映像,则可以在部署新 VM 时使用ImageReference中的id引用它,如下代码所示。 If you intend to deploy it from a.vhd file, you can refer to this .如果您打算从 .vhd 文件部署它,您可以参考.

poller = compute_client.virtual_machines.begin_create_or_update(RESOURCE_GROUP_NAME, VM_NAME,
    {
        "location": LOCATION,
        "storage_profile": {
           
            "image_reference": {
               "id": "/subscriptions/{subscription-id}/resourceGroups/{myResourceGroup}/providers/Microsoft.Compute/images/{existing-custom-image-name}"
            }
        },
    "hardware_profile": {
        "vm_size": "Standard_DS1_v2"
    },
    "os_profile": {
        "computer_name": VM_NAME,
        "admin_username": USERNAME,
        # "admin_password": PASSWORD,
        "custom_data": encoded_string,

You can specify a base-64 encoded string of custom data in OSProfile .您可以在OSProfile中指定自定义数据的 base-64 编码字符串。 I am using Python 3.9.4 .我正在使用Python 3.9.4

import base64

...

file = open("custom-data.sh", "rb")
a = file.read()
encoded_string = base64.b64encode(a).decode('utf-8')

...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM