Reputation: 755
Using the CLI, there is a simple command to create am image from a VM:
az image create \
--resource-group myResourceGroup \
--name myImage --source myVM
But I am having a hard time achieving the same thing with the Python client lib. The method begin_create_or_update
from azure.mgmt.compute.v2020_06_01.operations.imagesoperations
seems to be the right one but misses the source
parameter.
What is the correct approach?
Upvotes: 1
Views: 250
Reputation: 755
So after a lot of experimentation I got it working like this.
vm = compute_client.virtual_machines.get(resource_group, instance_name)
compute_client.images.begin_create_or_update(resource_group, image_name,
Image(location=vm.location, source_virtual_machine=SubResource(id=vm.id))).wait(120)
The trick was to provide the Image
argument and within it the VM id as a SubResource
.
Upvotes: 1