尝试使用自定义映像创建映像时,Azure python vm创建失败
虚拟机创建失败,出现osDisk错误: msrestazure.azure_exceptions.CloudError:不允许更改属性'osDisk.image.uri'。尝试使用自定义映像创建映像时,Azure python vm创建失败
代码片段如下:
storage_profile=azure.mgmt.compute.models.StorageProfile(
os_disk=azure.mgmt.compute.models.OSDisk(
caching=azure.mgmt.compute.models.CachingTypes.none,
create_option=azure.mgmt.compute.models.DiskCreateOptionTypes.from_image,
name=OS_DISK_NAME,
os_type='Linux',
vhd=azure.mgmt.compute.models.VirtualHardDisk(
uri='https://{0}.blob.core.windows.net/vhds/{1}.vhd'.format(
STORAGE_NAME,
OS_DISK_NAME,
),
),
image=azure.mgmt.compute.models.VirtualHardDisk(
uri='https://xxxxxxxxx.blob.core.windows.net/vm-images/Centos67-Azure.vhd'
),
)
图像是Python API中定义和定义的URI正常工作与Azure的CLI
API蔚蓝== 2.0.0rc3
如果它有助于这项交易被发送到azure:
url:hps://management.azure.com/subscriptions/b 97ddb69-f825-48b4-9e19-48eb3b4c8267/resourceGroups的/ dev-EU-vnet9-RG /提供商/ Microsoft.Compute/virtualMachines/centos67-API
头参数:{ '接受语言':“烯美国','Content-Type':'application/json;字符集= UTF-8' , 'X-MS-客户请求-ID': 'f65196f4-0e3b-11E6-A61B-b499baffc71a'}
体含量:{ '属性':{ 'storageProfile': {'osDisk':{'osType':'Linux','createOption':'fromImage','name':'centos67-api','caching':'None','vhd':{'uri':' '''','image':{'uri':'https://deveuvnet9rg9944.blob.core.windows.net/vm-images/Centos67-Azure.vhd'}}},'hardwareProfile':{'vmSize':'Standard_DS1'},'osProfile':{'adminUsername':'cloud_user','computerName' :'centos67-api','adminPassword':'xxxxxxxx'},'networkProfile':{'networkInterfaces':[{'id':'/ subscriptions/b97ddb69-f825-48b4-9e19-48eb3b4c8267/resourceGroups/dev-eu -vnet9-rg/providers/Microsoft.Network/networkInterfaces/centos67-api'}]}},'location':'eastus'}
Traceback(最近呼叫的最后一个): 文件“./azure_client.py”,第220行,在 result.wait()#异步操作 文件“/usr/lib/python2.7/site-packages/msrestazure/ azure_operation.py“,第639行,等待 raise self._exception msrestazure.azure_exceptions.CloudError:不允许更改属性'osDisk.image.uri'。
按照document,类StorageProfile
建设中的作用有三个参数包括:image_reference
,os_disk
和data_disk
。代码中的参数image
应该是类azure.mgmt.compute.models.ImageReference
,而不是类azure.mgmt.compute.models.VirtualHardDisk
。
作为参考,这里是从document的示例代码。
storage_profile=azure.mgmt.compute.models.StorageProfile(
os_disk=azure.mgmt.compute.models.OSDisk(
caching=azure.mgmt.compute.models.CachingTypes.none,
create_option=azure.mgmt.compute.models.DiskCreateOptionTypes.from_image,
name=OS_DISK_NAME,
vhd=azure.mgmt.compute.models.VirtualHardDisk(
uri='https://{0}.blob.core.windows.net/vhds/{1}.vhd'.format(
STORAGE_NAME,
OS_DISK_NAME,
),
),
),
image_reference = azure.mgmt.compute.models.ImageReference(
publisher=IMAGE_PUBLISHER,
offer=IMAGE_OFFER,
sku=IMAGE_SKU,
version=IMAGE_VERSION,
),
)
希望它有帮助。 任何问题,请随时让我知道。
ImageReference用于使用来自Azure Store的已发布图像,而不是用于上传自定义图像的Azure。这很好。不幸的是,我需要使用我们创建并上传的定制图像 –
这是OSDisk定义的一部分。看看定义图像 类OSDisk(模型): “”” 描述了操作系统磁盘 ... :PARAM形象:获取或设置源用户图像VirtualHardDisk这 VirtualHardDisk将被复制。之前使用它附加到虚拟 Machine.If SourceImage设置,目的地VirtualHardDisk 不应存在 :类型图像:类:'VirtualHardDisk
问题已解决。原来,返回的错误有点令人误解。问题是目标磁盘已经存在,因此无法修改(即更改属性错误)。
一旦目标具有唯一名称,该过程就可以正常工作,并且可以从我的自定义映像创建虚拟机。
来自OSDisk的类定义: –
根据REST API [创建或更新虚拟机](https://msdn.microsoft.com/en-us/library/azure/mt163591.aspx)的文档,请求主体内容不包括'storageProfile'的'osDisk'属性'image'。 –