消息:从 blob 存储创建托管磁盘映像时缺少必需参数 'hyperVGeneration'(空)

Message: Required parameter 'hyperVGeneration' is missing (null) while creating a Managed Disk image from blob storage

描述错误 它没有创建磁盘,而是抛出 Message: Required parameter 'hyperVGeneration' is missing (null). 错误。

重现 重现该行为的步骤:

  1. 运行 下面代码
compute_client = get_client_from_cli_profile(ComputeManagementClient)
async_creation = compute_client.images.create_or_update(
    '7AQVDL2J',
    'test',
    {
        'location': 'westeurope',
        'storage_profile': {
           'os_disk': {
              'os_type': 'Linux',
              'os_state': "Generalized",
              'blob_uri': 'https://bg09.blob.core.windows.net/vm-images/non-existent.vhd',
              'caching': "ReadWrite",
           }
        }
    }
) 

预期行为 应该创建磁盘

错误

 Traceback (most recent call last):
  File "<stdin>", line 11, in <module>
  File "/usr/local/lib/python3.7/dist-packages/azure/mgmt/compute/v2020_06_01/operations/_images_operations.py", line 125, in create_or_update
    **operation_config
  File "/usr/local/lib/python3.7/dist-packages/azure/mgmt/compute/v2020_06_01/operations/_images_operations.py", line 81, in _create_or_update_initial
    raise exp
msrestazure.azure_exceptions.CloudError: Azure Error: InvalidParameter
Message: Required parameter 'hyperVGeneration' is missing (null).
Target: hyperVGeneration

Link 到 git 问题:https://github.com/Azure/azure-sdk-for-python/issues/12762

如果有人找到解决方法,请分享....

我可以重现您的问题,要解决它,我们需要在您创建图像时添加 hyper_vgeneration

您可以参考下面的示例,我这边效果很好。

from azure.mgmt.compute.models import DiskCreateOption
from azure.mgmt.compute import ComputeManagementClient
from azure.common.client_factory import get_client_from_cli_profile

compute_client = get_client_from_cli_profile(ComputeManagementClient)
async_creation = compute_client.images.create_or_update(
    'groupname',
    'test123',
    {
        'location': 'eastus',
        'storage_profile': {
           'os_disk': {
              'os_type': 'Linux',
              'os_state': "Generalized",
              'blob_uri': 'https://joystoragev2.blob.core.windows.net/vhds2/destDisk.vhd',
              'caching': "ReadWrite",
           }
        },
        'hyper_vgeneration': 'V1'
    }
)
image_resource = async_creation.result()
print(image_resource)