虚拟机创建因osDisk错误而失败: msrestazure.azure_exceptions.CloudError:更改属性&#; osDisk.image.uri'是不允许的。
代码段如下:
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'
),
)
image在python API中定义,定义的URi与Azure CLI
一起正常工作API azure == 2.0.0rc3
如果这有助于将此事务发送到azure:
网址:hps://management.azure.com/subscriptions/b97ddb69-f825-48b4-9e19-48eb3b4c8267/resourceGroups/dev-eu-vnet9-rg/providers/Microsoft.Compute/ virtualMachines / centos67-API
标题参数:{'接受语言':' en-US','内容类型':&#39 ;应用/ JSON; charset = utf-8',' x-ms-client-request-id':' f65196f4-0e3b-11e6-a61b-b499baffc71a'}
正文内容:{'属性':{' storageProfile':{' osDisk':{' osType&# 39;:' Linux',' createOption':' fromImage',' name':' centos67-api', '缓存':'无'' vhd':{' uri':' https://deveuvnet9rg9944.blob.core.windows.net/vhds/centos67-api.vhd' },'图片':{' uri':' https://deveuvnet9rg9944.blob.core.windows.net/vm-images/Centos67-Azure.vhd'}}},' hardwareProfile':{&# 39; vmSize':' Standard_DS1'},' osProfile':{' adminUsername':' cloud_user',' computerName& #39;:' centos67-api',' adminPassword':' xxxxxxxx'},' networkProfile':{' networkInterfaces&# 39;:[{' id':' /subscriptions/b97ddb69-f825-48b4-9e19-48eb3b4c8267/resourceGroups/dev-eu-vnet9-rg/providers/Microsoft.Network/networkInterfaces/centos67 -api'}]}},' location':' eastus'}
追踪(最近一次通话): 文件" ./ azure_client.py",第220行,in result.wait()#async操作 文件" /usr/lib/python2.7/site-packages/msrestazure/azure_operation.py" ;,第639行,等待 提升self._exception msrestazure.azure_exceptions.CloudError:更改属性&#; osDisk.image.uri'是不允许的。
答案 0 :(得分:1)
问题已经解决。原来返回的错误有点误导。问题是目标磁盘已经存在,因此无法修改(即更改属性错误)。
一旦目标具有唯一名称,该过程就能正常运行,并且我能够从自定义图像中创建VM。
答案 1 :(得分:0)
根据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,
),
)
希望它有所帮助。 如有任何疑虑,请随时告诉我。