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
Doesn't seem like it. :(

That one critical missing API piece has effectively ceased our integration of Proxmox directly into our web application.

We're just using a bunch of shell scripts now instead, as that actually can do the job (aka "ssh FOO somescript.sh"). Unlike the API.
 
mail-archive.com also has a third-party archive for example
 
Doesn't seem like it. :(

That one critical missing API piece has effectively ceased our integration of Proxmox directly into our web application.

We're just using a bunch of shell scripts now instead, as that actually can do the job (aka "ssh FOO somescript.sh"). Unlike the API.

not sure what you mean - importing is available via the API nowadays:

qm create 600 --net0 virtio,bridge=vmbr0 --name vm600 --serial0 socket --boot order=scsi0 --scsihw virtio-scsi-pci --ostype l26 --scsi0 pvedir:0,import-from=/path/to/dir/vm600.raw

(same also applies to qm set, and the corresponding create/update API calls)

import-from can reference either an absolute path, or a regular volume ID on some storage.

@dcsapak is currently working on adding OVA/OVF import to the API/UI (patches on list), and I guess as a next step uploading VM disk images would also be easy to allow, we'll just have to think through all the implications first.
 
mail-archive.com also has a third-party archive for example
Thanks, that seems to work. :)

I went looking for a searchable archive of pve-devel a few weeks ago, but nothing turned up that seemed to be still getting recent mailing list posts.

How feasible is it to add a link (maybe this?) to the Proxmox Developers web page?

That'd be helpful for future people trying to figure stuff out. :)
 
Last edited:
To me, when you show a `qm` command that's (to me) not the API.
I think the point was that "qm" is using the API in the background. So you should be able to "reverse-engineer" the call to the direct API. The options would translate into parameters.
But, I believe, it would still have to refer to the image accessible locally to PVE. I.e. not from user's laptop.


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
"qm" is using the API in the background

For several of the import disk steps, that's indeed what it does. For uploading the image content though, it doesn't. Instead, it runs qemu-img locally to load in the disk data from a local source.

There doesn't seem to be a way of uploading the data (via the API) from a remote system.
 
There doesn't seem to be a way of uploading the data (via the API) from a remote system.
You are correct, thats what I meant when I said "it has to be local to PVE". Meaning, either in ISO image store, local disk, or custom NFS mounted path.

At the moment, think of it as Openstack image in Glance.

Best,


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 

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!