VE API execute command or generate a string when creating the VM

Really

New Member
Mar 17, 2022
5
0
1
35
Hi,
Im using Proxmox VE, via API communication. I have a script that I use to create virtual machines (it works brilliantly).


The template I will create in advance to make everything work correctly will be with the program installed, but there remains the issue of implementing the API to create and configure the virtual machine. My question is:

how can i generate user + password and have them added in /etc/software/user.conf


I assume there is a way, via an API command, that I can run X command to the server and write the required file?


For the moment, the only solution I can and use is that the template itself has a pre-configuration, such as static needs and a password:

for example:

user32143, pass43294


However, this is bad practice. I want each new machine to have different accesses in this file: /etc/software/user.conf

Thanks
 
Hi Really,

if I understand you correctly you basically want write a file within the VM once it has been created (specifically the file "/etc/software/user.conf")? If so there might be two ways to accomplish that:
  1. Take a look at the /nodes/{node}/qemu/{vmid}/agent/exec endpoint [1]. You can execute generic commands within the VM via the guest agent. Note that I am uncertain this is really a good way to handle credentials, but it might be a starting point.
  2. I think a more standard way accomplishing that might be cloud-init. While I am not too familiar with it myself, to be honest with you, from what I can tell stuff like this is basically what it was made for. It has a "write_files" module [2]. There are also several examples on their website [3].
[1]: https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/qemu/{vmid}/agent/exec
[2]: https://cloudinit.readthedocs.io/en/latest/topics/modules.html#write-files
[3]: https://cloudinit.readthedocs.io/en/latest/topics/examples.html
 
Yes, you got me right. Thank you very much for your help.

Eventually I came up with a method that would build it like this:
1. A cron task that runs 2 bash scripts - previously added in the template system.
2. The bash script works through an external API that checks for the username/password data in question
3. Cron task update/add/delete.

It's actually about managing a PPTP VPN configuration to have a web managmend option

Thanks very much
 

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!