我尝试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 url
你VHD
的存储名称中的文件。看起来像 :
https://<your storage account>.blob.core.windows.net/<your container name>/<your vhd file name>
我成功更改了imageName
然后创建的自定义图像的值。
希望它可以帮助你。任何问题,请随时让我知道。