Reputation: 21
VM create fails with is osDisk error: msrestazure.azure_exceptions.CloudError: Changing property 'osDisk.image.uri' is not allowed.
Code snippet is as follows:
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'
),
)
image is defined in the python API and the URi defined works fine with the Azure CLI
API azure==2.0.0rc3
If it helps this is the transaction being sent to azure:
url: hps://management.azure.com/subscriptions/b97ddb69-f825-48b4-9e19-48eb3b4c8267/resourceGroups/dev-eu-vnet9-rg/providers/Microsoft.Compute/virtualMachines/centos67-api
header parameters: {'accept-language': 'en-US', 'Content-Type': 'application/json; charset=utf-8', 'x-ms-client-request-id': 'f65196f4-0e3b-11e6-a61b-b499baffc71a'}
body content: {'properties': {'storageProfile': {'osDisk': {'osType': 'Linux', 'createOption': 'fromImage', 'name': 'centos67-api', 'caching': 'None', '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'}]}}, 'location': 'eastus'}
Traceback (most recent call last): File "./azure_client.py", line 220, in result.wait() # async operation File "/usr/lib/python2.7/site-packages/msrestazure/azure_operation.py", line 639, in wait raise self._exception msrestazure.azure_exceptions.CloudError: Changing property 'osDisk.image.uri' is not allowed.
Upvotes: 1
Views: 1379
Reputation: 21
The issue has been resolved. Turned out the error returned is somewhat misleading. The issue was that there was that the target disk already existed and therefore couldn't be modified (i.e. change property error).
Once the target had a unique name the process worked properly and I was able to create VMs from my custom image.
Upvotes: 1
Reputation: 24138
According to the document, the class StorageProfile
construction function has three parameters include image_reference
, os_disk
and data_disk
. The parameter image
in your code should be the class azure.mgmt.compute.models.ImageReference
, not the class azure.mgmt.compute.models.VirtualHardDisk
.
As reference, here is the sample code from the 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,
),
)
Hope it helps. Any concern, please feel free to let me know.
Upvotes: 0