[SOLVED] Running "POST /api2/json/nodes/{node}/qemu/{vmid}/clone" from my python program

newhere

New Member
Aug 13, 2020
4
0
1
29
Hello everyone,

I am new to Proxmox and I wanted to create a VM from my python program. I was able to get a connection from my python interpreter and information about running VMs within each node and now I would like to use a python script to create a VM but I really don't know how to get started, plz help!


Thanks guys!
 
did you already look at the examples here: https://pve.proxmox.com/wiki/Proxmox_VE_API
and the api docs here: https://pve.proxmox.com/pve-docs/api-viewer/index.html
?

if yes, what exactly do you have problems with?



Okay I was able to create my VM using the python wrapper but I am having issues creating a local disk from which the vm will boot from.
Below is the way I created the VM and this part works perfectly fine:

from proxmoxer import ProxmoxAPI
prox = ProxmoxAPI(host='IP', port=8006, user='username', password='pass', verify_ssl=False)
node = prox.nodes('nodeName')
getattr(node, 'qemu').create(vmid=234, name='hellothere', memory=1024, cpu='kvm64', cores=1, sockets=1, cdrom='local:iso/ubuntu-18.04.3-live-server-amd64.iso', ostype='l26', net0='virtio,tag=608', pool='DEV', scsi0='lab-ceph:vm-234-disk-0,backup=1,cache=writeback,size=10G,ssd=1', scsihw='virtio-scsi-pci', hotplug=1, tablet=1, vga='qxl')


and now I am trying to add the storage for this VM so it can boot but I am getting errors, below is the command I am trying.
getattr(node, 'storage').content.post(vmid=234, filename='vm-234-disk-0', size='10G', storage='lab-ceph', format='raw')

When I run the above command, I get this:
proxmoxer.core.ResourceException: 501 Not Implemented: Method 'POST /nodes/prox5-cmi-010/storage/content' not implemented - b'{"data":null}'

I am referring to the proxmox api documentation: https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/storage/{storage}/content
Screen Shot 2020-08-18 at 4.41.56 PM.png
Can anybody please help me! please please....
Thanks!
 
hi,

the answer is in the post:

/nodes/{node}/storage/{storage}/content so it should be /nodes/prox5-cmi-010/storage/{storage_name}/content. replace {storage_name} with the actual name of your storage
 
hi,

the answer is in the post:

/nodes/{node}/storage/{storage}/content so it should be /nodes/prox5-cmi-010/storage/{storage_name}/content. replace {storage_name} with the actual name of your storage


No I don't have Commercial Support Subscription. I am experimenting this to convince my company to use your software. I am trying to create a python webform which will be used to create, clone, and modify VMs hosted by the virtualizer. I am sure if I happen to make it work without having to use bash scripts, there's a change my company will move forward using Proxmox as their main virtualizer.

I understand your point about replacing the storage_name in the path you specified but, as you may know, since the storage doesn't exist yet, you can't put it in a path, below is the error you will get trying so:

Here's the commands I typed:
1- getattr(node, 'storage/vm-136-disk-0').content.post(vmid=136, filename='vm-136-disk-0', size='10G', storage='lab-ceph', format='raw')
500 Internal Server Error: storage 'vm-136-disk-0' does not exist - b'{"data":null}'

2- getattr(node, 'storage')('vm-136-disk-0').create(vmid=136, filename='vm-136-disk-0', size='10G', format='raw')
501 Not Implemented: Method 'POST /nodes/prox5-cmi-010/storage/vm-136-disk-0' not implemented - b'{"data":null}'

2- getattr(node, 'storage')('vm-136-disk-0').content.create(vmid=136, filename='vm-136-disk-0', size='10G', format='raw')
500 Internal Server Error: storage 'vm-136-disk-0' does not exist - b'{"data":null}'

Maybe I am missing something and I would truly appreciate you guys help.
 
here the {storage} is the name of your storage, not the volume in the storage.
so if your storage is called lab-ceph, then the API path needs to be /nodes/prox5-cmi-010/storage/lab-ceph/content

i hope it's more clear now
 
  • Like
Reactions: newhere
here the {storage} is the name of your storage, not the volume in the storage.
so if your storage is called lab-ceph, then the API path needs to be /nodes/prox5-cmi-010/storage/lab-ceph/content

i hope it's more clear now

Thank You very much Oguz, I sincerely appreciated your help. Once again thank you!