Hello everyone, I have a question about templates that I would like to ask. I hope everyone can give me an idea, thank you

ggea

Member
Jun 28, 2023
32
1
8
Due to usage scenarios, I cloned many virtual machines using a template within the cluster. However, when I tried to delete the template, I found that too many virtual machines were being cloned, causing the template to be being referenced. It was difficult to find which virtual machines were using the template one by one. Is there any API or command that can identify virtual machines using this template within the cluster and delete them in bulk?
 
You can grep for the ID of the template in the config files below /etc/pve/nodes.
I can find and obtain the template ID. What I want to know is how to find which virtual machines are using the template based on the template ID
 
The template ID is part of the storage configuration if the VM is a linked clone.
If the VM is a full clone it is independent and there is no reference to the template.
All of them are linked clones, because a template has been linked and cloned by many machines, so I want to use the template to find out which virtual machines are currently linked and cloned this template
 
Bash:
grep -r TEMPLATEID /etc/pve/nodes
Hello, thank you for your command. I can now obtain the list of virtual machines currently using this template, but because it is distributed on different physical machines, deleting it will cause an error. Is there a way to delete it uniformly on one machine?

Bash:
root@zmc-pve52:~# pvesh delete /nodes/zmc-master-pve51/qemu/123
proxy handler failed: Configuration file 'nodes/zmc-master-pve51/qemu-server/123.conf' does not exist
root@zmc-pve52:~# grep -r "base-122-disk" /etc/pve/nodes/
/etc/pve/nodes/zmc-master-pve51/qemu-server/190.conf:ide0: nas-nfs:122/base-122-disk-0.raw/190/vm-190-disk-0.qcow2,media=disk,size=32G
/etc/pve/nodes/zmc-master-pve51/qemu-server/191.conf:ide0: nas-nfs:122/base-122-disk-0.raw/191/vm-191-disk-0.qcow2,media=disk,size=32G
/etc/pve/nodes/zmc-pve52/qemu-server/192.conf:ide0: nas-nfs:122/base-122-disk-0.raw/192/vm-192-disk-0.qcow2,media=disk,size=32G
/etc/pve/nodes/zmc-pve52/qemu-server/187.conf:ide0: nas-nfs:122/base-122-disk-0.raw/187/vm-187-disk-0.qcow2,media=disk,size=32G
/etc/pve/nodes/zmc-pve52/qemu-server/123.conf:ide0: nas-nfs:122/base-122-disk-0.raw/123/vm-123-disk-0.qcow2,media=disk,size=32G
/etc/pve/nodes/zmc-pve52/qemu-server/122.conf:ide0: nas-nfs:122/base-122-disk-0.raw,media=disk,size=32G
root@zmc-pve52:~# grep -r "base-122-disk" /etc/pve/nodes/ | awk -F'/' 'match($NF, /[0-9]+/) {print substr($NF, RSTART, RLENGTH)}'
190
191
192
187
123
122
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!