【问题标题】:How to create Azure Virtual machine with VM Extension using the python SDK如何使用 python SDK 创建带有 VM 扩展的 Azure 虚拟机
【发布时间】:2022-12-10 03:14:31
【问题描述】:

我想使用 python SDK 创建一个带有 VM 扩展(自定义脚本扩展)的 Azure 虚拟机。基本上,我想要一个 python 程序,它将使用 Azure SDK 管理库创建具有 VM 扩展的 VM,我能够在 Python 脚本中使用 Azure SDK 管理库来创建包含 Linux 虚拟机的资源组。 https://learn.microsoft.com/en-us/azure/developer/python/azure-sdk-example-virtual-machines?tabs=cmd

但是我需要带有 VM 扩展的虚拟机。

【问题讨论】:

  • 请编辑问题以将其限制为具有足够详细信息的特定问题,以确定适当的答案。

标签: python azure cloud azure-virtual-machine azure-sdk-python


【解决方案1】:

截至目前,我们没有与创建带有扩展的 VM 相关的适当文档。

  • 这是用于创建和更新扩展的SDK reference document

    VirtualMachineExtensionsOperations(客户端、配置、序列化器、反序列化器)

  • 这是创建扩展的示例代码

    begin_create_or_update(resource_group_name: str, vm_name: str, vm_extension_name: str, extension_parameters: “_models.VirtualMachineExtension”, **kwargs: Any) -> LROPoller['_models.VirtualMachineExtension']

  • 这是使用 python 创建虚拟机的 document

【讨论】:

  • 嗨@SaiSakethGuduru-MT,我们是否必须使用 begin_create_or_update() 运行它来创建实例或在创建实例之后?那就是我们是否将它作为参数添加到创建实例的函数调用中?
  • 老实说,我不确定要添加什么。 extension_parameters 是按要求列出的,所以我不确定要放什么。我们为 AADLoginForLinux 扩展添加了什么?
【解决方案2】:
compute_client.virtual_machines.begin_create_or_update(
RUNNER_RG,
resource_name_and_IP,
{
    "location": "eastus",
    "storage_profile": {
        "image_reference": {
            "id": image_id
        }
    },
    "hardware_profile": {
        "vm_size": "Standard_F8s_v2"
    },
    "os_profile": {
        "computer_name": resource_name_and_IP,
        "admin_username": "azuser",
        "linux_configuration": {
            "disable_password_authentication": True,
            "ssh": {
                "public_keys": [
                    {
                        "path": "/home/azuser/.ssh/authorized_keys",
                        # Add the public key for a key pair that can get access to SSH to the runners
                        "key_data": "ssh public key here"
                    }
                ]
            }
        }
    },
    "network_profile": {
        "network_interfaces": [
            {
                "id": nic_result.id,
                "properties": {"deleteOption": "Delete"}
            }
        ]
    },
    "identity": params_identity,
    "vm_azure_extension": "AADSSHLogin"
})

只是添加 vm_azure_extension 并没有添加扩展。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 2021-01-02
    相关资源
    最近更新 更多