Reputation: 873
I am trying to create a custom image from a VHD which I uploaded to the devtest lab.
I am using the following code to do that:
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)
It throws me the following error : Failed to parse URI named ImageName with value of '##customImageName##'.
Let me know what I am doing wrong? And where am I suppossed to enter the path to the VHD in the API. I cannot find any argument which takes the path!
Upvotes: 0
Views: 296
Reputation: 23792
I tried to create custom image
with the code you offered.
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)
then I reproduction your issue.
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
After researching,I found that the imageName
parameter above not just your VHD
name,it supposed to be the complete url
of your VHD
file in your storage name.
It looks like :
https://<your storage account>.blob.core.windows.net/<your container name>/<your vhd file name>
I changed the value of the imageName
then created custom image successfully.
Hope it helps you.Any concern,please feel free to let me kown.
Upvotes: 0
Reputation: 13974
It throws me the following error : Failed to parse URI named ImageName with value of '##customImageName##'.
According to the error message, it seems the imagename
value is a URI.
The image name should be a string.
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.
More information please refer to this link.
By the way, to troubleshoot this issue more efficiency, could you please post your whole script:)
Upvotes: 0