About disk names in 'qm import disk'

fdcastel

Member
Sep 28, 2021
24
3
8
1. How could I get (e.g. in a bash script) the name of disk created after a successfull invocation of qm import disk ?

Bash:
# qm importdisk 201 ubuntu-20.04-server-cloudimg-amd64.img local-zfs
(...)
transferred 2.2 GiB of 2.2 GiB (100.00%)
Successfully imported disk as 'unused0:local-zfs:vm-201-disk-0'

How could I get that vm-201-disk-0 ? (preferably without grep / regex ;))

(I know the first disk will always be named "disk-0" but what if there are another disks in VM?)



2. There is a way to set the disk name during/after a qm import disk ?

E.g. Rename the above disk to vm-201-main-os

Feature request:
Add a --name option in qm import disk ?

Bash:
# qm importdisk 201 ubuntu-20.04-server-cloudimg-amd64.img local-zfs --name vm-201-main-os
 
"importdisk" is one of the few commands that have no API end-point.

Its not fully wired in as evident by the fact that it requires the path to image to be local to the host, i.e. you cant specify storage:template/iso/image.raw it must be /mnt/pve/storage/template/iso/image.raw

It would be nice if there was an API and storage integration. Having said that, you asked for no-grep or regex solution, so technically this squeezes by:


Code:
qm importdisk 100 /mnt/pve/images/template/iso/cirros-0.5.2-x86_64-disk.img local --format raw
....
Successfully imported disk as 'unused4:local:100/vm-100-disk-4.raw'

pvesh get /nodes/pve/qemu/100/config  --output-format json | jq -r 'last(to_entries[]|select(.key|startswith("unused"))).value'
local:100/vm-100-disk-4.raw


Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
Thanks @bbgeek17 for the detailed information. ;)



When I said PREFERABLY without grep / regex it was only to highlight that I was looking for a more "programmatically inclined" solution.

But your usage of jq to query the VM config is also very educative and useful.

I'm a complete noob in Proxmox VE (but I'm already in love with it!) and I didn't notice the --output-format argument for CLI apps.



I'm learning it just now and collecting some useful script on https://github.com/fdcastel/PVE-Automation

Please let me know if you know of any similar project.

Thanks again!

F.D.Castel.
 
pulling up import to the API is a feature currently being worked on btw!
 
  • Like
Reactions: fdcastel

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!