首页 > 解决方案 > Azure Python SDK 计算客户端未使用托管磁盘参数

问题描述

我正在使用计算客户端创建一个 VM(使用 create_or_update),并且我希望 VM 有一个标准硬盘而不是高级 ssd 作为其操作系统磁盘。我应该能够在托管磁盘参数中指定它,但是当我这样做时,VM 仍然使用高级 SSD 创建。这是我的虚拟机参数。

vm_parameters = {
        'location': vm_location,
        'os_profile': {
            'computer_name': vm_name,
            'admin_username': vm_name,
            'admin_password': vm_password,
            'custom_data': startup_script
        },
        'hardware_profile': {
            'vm_size': 'Standard_B1ls'
        },
        'storage_profile': {
            'image_reference': {
                'publisher': 'Canonical',
                'offer': 'UbuntuServer',
                'sku': '16.04.0-LTS',
                'version': 'latest'
            },
            'os_disk': {
                'caching': 'None',
                'create_option': 'FromImage',
                'disk_size_gb': 30,
                'managed_disk_parameters': {
                    'storage_account_type': 'Standard_LRS'
                }
            }
        },
        'network_profile': {
            'network_interfaces': [{
                'id': nic_info.id
            }]
        },
        'tags': {
            'expiration_date': 'expirationdatehere'
        }
    }

仅将存储帐户类型指定为 Standard_LRS 不会改变任何内容。我应该怎么做才能让我的虚拟机使用标准硬盘而不是高级 ssd 作为其 os 磁盘创建?

标签: pythonazureazure-sdkazure-sdk-python

解决方案


如果您使用 Rest API 创建 VM,那么这里是创建 VM 的示例 JSOn 请求:

{
  "location": "westus",
  "properties": {
    "hardwareProfile": {
      "vmSize": "Standard_D1_v2"
    },
    "storageProfile": {
      "imageReference": {
        "id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}"
      },
      "osDisk": {
        "caching": "ReadWrite",
        "managedDisk": {
          "storageAccountType": "Standard_LRS"
        },
        "name": "myVMosdisk",
        "createOption": "FromImage"
      }
    },
    "osProfile": {
      "adminUsername": "{your-username}",
      "computerName": "myVM",
      "adminPassword": "{your-password}"
    },
    "networkProfile": {
      "networkInterfaces": [
        {
          "id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
          "properties": {
            "primary": true
          }
        }
      ]
    }
  }
}

这是相同的API:

PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM?api-version=2019-03-01

如果您正在寻找一种创建虚拟机的方法,那么您可以按照以下代码示例进行操作:

https://github.com/Azure-Samples/Hybrid-Compute-Python-Manage-VM/blob/master/example.py

希望能帮助到你。


推荐阅读