0

我正在尝试从上传到 devtest 实验室的 VHD 创建自定义图像。

我正在使用以下代码来做到这一点:

from azure.mgmt.storage import StorageManagementClient
....
credentials = ServicePrincipalCredentials( client_id = '##', tenant = '##', secret = "##")
resource_client = DevTestLabsClient(credentials, subscriptID)

....
custom_image_properties = CustomImagePropertiesCustom(CustomImageOsType.windows, config.CustomImage.Name, True)
custom_image = CustomImage(vhd = custom_image_properties)
resource_client.custom_images.create_or_update(rgName,labName, imageName, custom_image)

它向我抛出以下错误:无法解析名为 ImageName 且值为“##customImageName##”的 URI。

让我知道我做错了什么?我应该在哪里输入 API 中的 VHD 路径。我找不到任何走这条路的论点!

4

2 回答 2

0

它向我抛出以下错误:无法解析名为 ImageName 且值为“##customImageName##”的 URI。

根据错误消息,该imagename值似乎是一个 URI。

图像名称应该是一个字符串。

create_or_update(resource_group_name, lab_name, name, custom_image, custom_headers=None, raw=False, **operation_config)


Parameters: 
resource_group_name (str) – The name of the resource group.
lab_name (str) – The name of the lab.
name (str) – The name of the custom image.

更多信息请参考此链接


顺便说一下,为了更高效地解决这个问题,你能不能把你的整个脚本贴出来:)

于 2017-09-27T07:51:30.153 回答
0

我尝试custom image使用您提供的代码进行创建。

from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.devtestlabs import DevTestLabsClient
from azure.mgmt.devtestlabs.models.custom_image_properties_custom import CustomImagePropertiesCustom
from azure.mgmt.devtestlabs.models.custom_image import CustomImage
from azure.mgmt.devtestlabs.models.dev_test_labs_client_enums import CustomImageOsType

client_id = <your client id>
tenant = <your tenant id>
secret = <your secret id>
subscriptID = <your subcript id>
imageName='jaygong.vhd'
name=<your custom image name as you want>
rgName = <your resource name>
labName = <your lab name>

credentials = ServicePrincipalCredentials(client_id=client_id, tenant=tenant , secret=secret)
resource_client = DevTestLabsClient(credentials, subscriptID)
custom_image_properties = CustomImagePropertiesCustom(CustomImageOsType.windows, imageName, True)
custom_image = CustomImage(vhd = custom_image_properties)
resource_client.custom_images.create_or_update(rgName,labName, name, custom_image)

然后我复制你的问题。

E:\Python27\python.exe E:/PythonWorkSpace/CreateVM/Create.py
Traceback (most recent call last):
  File "E:/PythonWorkSpace/CreateVM/Create.py", line 19, in <module>
    resource_client.custom_images.create_or_update(rgName,labName, imageName, custom_image)
  File "E:\Python27\lib\site-packages\azure\mgmt\devtestlabs\operations\custom_images_operations.py", line 293, in create_or_update
    get_long_running_status, long_running_operation_timeout)
  File "E:\Python27\lib\site-packages\msrestazure\azure_operation.py", line 350, in __init__
    raise CloudError(self._response)
msrestazure.azure_exceptions.CloudError: Azure Error: InvalidUrlProvided
Message: Failed to parse URI named ImageName with value of 'aaa'.

Process finished with exit code 1

经过研究,我发现imageName上面的参数不仅仅是你的VHD名字,它应该是complete urlVHD的存储名称中的文件。看起来像 :

https://<your storage account>.blob.core.windows.net/<your container name>/<your vhd file name>

我成功更改了imageName然后创建的自定义图像的值。

在此处输入图像描述

希望它可以帮助你。任何问题,请随时让我知道。

于 2017-09-29T03:26:56.767 回答