python - 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 磁盘创建?
解决方案
如果您使用 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
希望能帮助到你。
推荐阅读
- html - 如何在我的网站上相邻放置两个嵌入式链接?
- pine-script - Pinescript 错误:期待“行尾没有续行”// SWING 策略
- winapi - 如何在 C++ 中从 .dll 中导入和导出 HINSTANCE?
- javascript - Javascript(计数<elements.length)不起作用
- azure - Azure AD B2C 在使用 dotnet core 5.0 构建的后端 Web API 中进行身份验证
- java - 在 Java 中使用文件
- pygame - 如何使我的变量在我单击 pygame 中的按钮时仅增加一个,以及如何使文本更新
- google-bigquery - 数据流作业+大查询
- sql - 尽管使用了 distinct 函数,但没有获得唯一值
- assembly - 如何在一个将自己缝合到自己的尾部的程序中,无限地环绕在 64KB 代码段中?