proxmox api import disk

klevcehnko

New Member
Apr 6, 2020
4
0
1
28
Hi, i trying to import ubuntu cloud init hard disk using proxmox api

is there any api command that can be used to execute following command:

qm importdisk <vmid> <path-to-file> <target-storage>
 
no, importdisk is CLI only. if your source file is on a PVE managed storage, you can use the config, move_disk and storage content API calls to achieve the same effect though.
 
no, importdisk is CLI only. if your source file is on a PVE managed storage, you can use the config, move_disk and storage content API calls to achieve the same effect though.

i've tried move_disk and storage content API calls to get wanted result but failed
can you give me cluses or more specified API calls to recreate following clients command if it not difficult for you

qm create 9001 --memory 2048 --net0 virtio,bridge=vmbr0 \
--agent 1 \
--autostart 1 \
--description temp-description \
--sshkeys ~/.ssh/prox.pub \
--citype nocloud \
--cipassword ubuntu \
--ipconfig0 ip=dhcp \
--ide2 kube:vm-9001-cloudinit

qm importdisk 9001 xenial-server-cloudimg-amd64-disk1.img kube --format=qcow2
qm set 9001 --scsihw virtio-scsi-pci --scsi0 kube:vm-9001-disk-0
qm resize 9001 scsi0 +5G
qm set 9001 --boot c --bootdisk scsi0
qm set 9001 --serial0 socket --vga serial0
 
put the file with a .qcow2 extension somewhere on a dir-based storage, so that pvesm list STORAGE lists it. if you want to re-use it for multiple VMs you can assign it a special VMID that is not actually used, e.g. vm-999999-disk-xenial-server-cloudimg-amd64.qcow2. this step is not possible via the API, you need to use ssh/NFS/... access.

Step 1: POST to nodes/NODE/qemu/VMID/config with the appropriate drive key set, e.g. scsi0 => STORAGE:VOLID

to add the volume to the VM config (this is the equivalent of qm set XXX -scsi0 STORAGE:VOLID, it will not actually do anything to the image but just add it to the config file.

Step 2: POST to nodes/NODE/qemu/VMID/move_disk to move it to the actual target storage and optionally, convert it to some other format. the source disk will be added as unused volume if it is owned by the VM and the 'delete' parameter is not set.

Step3: OPTIONALLY you can use the POST to the config API call from step 1 with delete => unusedX if it was added and you want to physically delete the imported source volume. if it was not added as unused volume and you want to delete it anyway, you can use DELETE on nodes/NODE/storage/STORAGE/content/VOLUME
 
  • Like
Reactions: Moayad
work on that feature is currently being finalized on the pve-devel list..
 
Hello,

I am on the 7.0.4 Beta version at the moment and I cannot seem to find information about that endpoint anywhere. Can you link me in the right direction where to find a implementation? I am willing to contribute to get that into the release.
 
if you want to keep uptodate, follow the pve-devel mailing list or git repositories or wait for a new feature to be mentioned in the changelog ;)
 
  • Like
Reactions: anzure

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!