首页 文章

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

提问于
浏览
1

虚拟机创建失败,出现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的交易:

url :hps://management.azure.com/subscriptions/b97ddb69-f825-48b4-9e19-48eb3b4c8267/resourceGroups/dev-eu-vnet9-rg/providers/Microsoft.Compute/virtualMachines/centos67-api

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

body content :{'properties':{'storageProfile':{'osDisk':{'osType':'Linux','createOption':'fromImage','name':'centos67-api','caching':'None','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 ': {' vmSize ': ' Standard_DS1 '}, ' osProfile ': {' adminUsername ': ' cloud_user ', '计算机名': ' 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'}

回溯(最近一次调用最后一次):文件“./azure_client.py”,第220行,在result.wait()#async操作文件“/usr/lib/python2.7/site-packages/msrestazure/azure_operation.py” ,第639行,等待提升self._exception msrestazure.azure_exceptions.CloudError:不允许更改属性'osDisk.image.uri' .

2 回答

  • 0

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

    一旦目标具有唯一名称,该过程就能正常工作,并且我能够从我的自定义映像创建VM .

  • 1

    根据document,类 StorageProfile 构造函数有三个参数包括 image_referenceos_diskdata_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,
        ),
    )
    

    希望能帮助到你 . 如有任何疑虑,请随时告诉我 .

相关问题