我想使用 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 扩展的虚拟机。
截至目前,我们还没有与创建具有扩展名的 VM 相关的适当文档。
这里是用于创建和更新扩展的SDK 参考文档
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']
文档。
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 并没有添加扩展。
ext = compute_client.virtual_machine_extensions.begin_create_or_update(
RESOURCE_GROUP_NAME,
vm_name,
vm_extension_name="NvidiaGpuDriverLinux",
extension_parameters={
"type": "Microsoft.Compute/virtualMachines/extensions",
"location": LOCATION,
"apiVersion": "2015-06-15",
"properties": {
"publisher": "Microsoft.HpcCompute",
"type": "NvidiaGpuDriverLinux",
"typeHandlerVersion": "1.9",
"autoUpgradeMinorVersion": True,
"settings": {},
},
},
)
ext.result()