【问题标题】:Azure python vm create fails when trying to create image with custom image尝试使用自定义图像创建图像时 Azure python vm create 失败
【发布时间】:2016-08-22 07:06:08
【问题描述】:

VM 创建失败并出现 osDisk 错误: msrestazure.azure_exceptions.CloudError:不允许更改属性“osDisk.image.uri”。

代码sn-p如下:

 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 的事务:

网址: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'}

正文内容: {'properties': {'storageProfile': {'osDisk': {'osType': 'Linux', 'createOption': 'fromImage', 'name': ' centos67-api', '缓存': '无', 'vhd': {'uri': 'https://deveuvnet9rg9944.blob.core.windows.net/vhds/centos67-api.vhd'}, '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'}]}}, '位置':'东方'}

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

【问题讨论】:

标签: python azure command-line-interface


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    根据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,
        ),
    )
    

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

    【讨论】:

    • ImageReference 用于使用 Azure 商店中的已发布图像,而不是用于上传 Azure 的自定义图像。这工作得很好。不幸的是,我需要使用我们创建和上传的自定义图像
    • 这是 OSDisk 定义的一部分。查看镜像类 OSDisk(Model) 的定义:""" 描述操作系统磁盘。... :param image: 获取或设置源用户镜像 VirtualHardDisk。此 VirtualHardDisk 将在使用它附加到 VirtualHardDisk 之前被复制Machine.If SourceImage 提供,目标 VirtualHardDisk 不应该存在。 :type image: :class:VirtualHardDisk <azure.mgmt.compute.models.VirtualHardDisk> ...
    猜你喜欢
    • 1970-01-01
    • 2017-05-07
    • 2019-07-14
    • 1970-01-01
    • 2016-11-12
    • 2023-03-26
    • 1970-01-01
    • 2019-08-31
    • 2016-01-21
    相关资源
    最近更新 更多