尝试使用自定义imag创建映像时,Azure python vm create失败

2024-05-23 18:59:54 发布

您现在位置:Python中文网/ 问答频道 /正文

VM创建失败,出现is osDisk错误: msrestazure.azure_异常.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'
                ),
            )

映像是在pythonapi中定义的,定义的URi可以很好地与azurecli配合使用

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在

头参数:{'accept-language':'en-US','Content-Type':'application/json;charset=utf-8','x-ms-client-request-id':'f65196f4-0e3b-11e6-a61b-b499baffc71a'}

主要内容方面,主要是根据自己的主要经验,主要是按照自己的基本原则,主要是按照自己的标准,按照基本的标准,基本的基本原则,Linux''Linux','CreateOpti':'fromamamage','name':'centos67 api','缓存''的''缓存''的''''''的'''''''的'''''的形象,{'uri''''{2}}}},'HardwarEproProfile':{''''''标准的标准,标准的标准的标准的标准的标准的标准,基本的标准的标准的标准的标准的标准的标准的标准的金标准的金标准的标准的标准的标准的标准的标准的金金金''''''''''','adminPassword':'xxxxxxxx'},'networkProfile':{'networkInterfaces':[{id':'/subscriptions/b97ddb69-f825-48b4-9e19-48eb3b4c8267/resourceGroups/dev-eu-vnet9-rg/providers/Microsoft.Network/networkInterfaces/centos67-api'}]}},'location':'eastus'}

回溯(最近一次呼叫): 文件“./azure_客户端.py“,第220行,英寸 结果。等等()异步操作 文件“/usr/lib/python2.7/site-packages/msrestazure/azure”_操作.py“,639号线,等待 自我提升。例外 msrestazure.azure_异常.CloudError:更改属性'osDisk.image.uri'是不允许的。在


Tags: nameimageapi标准modelslinuxuriazure
2条回答

根据document,类StorageProfile构造函数有三个参数,包括image_referenceos_disk和{}。代码中的参数image应该是类^{},而不是类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,
    ),
)

希望有帮助。 有任何问题,请随时告诉我。在

问题已经解决了。结果返回的错误有点误导。问题是目标磁盘已经存在,因此无法修改(即更改属性错误)。在

一旦目标有了一个唯一的名称,进程就可以正常工作,我就可以从我的自定义映像创建vm。在

相关问题 更多 >