[SOLVED] Hi, i know proxmoxer is not developed by the proxmox team but

ospfeigrp

New Member
Apr 30, 2024
4
0
1
Is it possible to post from within a flask application for example how do i start a container on button press.? i guess what i am asking is how this is done with proxmoxer api i can't find an example.
 
Hey,

I'm not sure I understand what you want to do, but as long as you can reach the PVE API over the network it doesn't matter where you send requests from.
 
Hey,

I'm not sure I understand what you want to do, but as long as you can reach the PVE API over the network it doesn't matter where you send requests from.
Python:
@app.route("/stats")
def stats():
    names = []
    vmid = []
    status = []
    cpus = []
    for pve_node in proxmox.nodes.get():
        print("{0}:".format(pve_node['node']))
    for container in proxmox.nodes(pve_node['node']).lxc.get():
        names.append(container['name'])
        vmid.append(container['vmid'])
        status.append(container['status'])
        cpus.append(container['cpus'])
        print(container)
    return render_template("stats.html",names=names,vmid=vmid,status=status,cpus=cpus)

HTML:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<table>
  <thead>
    <th>VMID</th>
    <th>NAME</th>
    <th>STATUS</th>
    <th>CPUS</th>
    <th>START</th>
  </thead>

  <tbody>
  {% for i in range(vmid|length) %}
    <tr>
        <td>{{vmid[i]}}</td>
        <td>{{names[i]}}</td>
        <td>{{status[i]}}</td>
        <td>{{cpus[i]}}</td>
        <td><button type="button">{{names[i]}}</button></td>
    </tr>
  {% endfor %}
  </tbody>
</table>
</body>
</html>


Above as you can see is the route to get the containers all working ok and the jinja template also working.
What i am getting confused about is how to send the request with python for example while using the proxmoxer api i had a look in the docs but can't find an example of how this is done?
 
proxmox.nodes(pve_node['node']).lxc.get() this is sending the request, more specifically proxmoxer, among probably also other things, sends a request to [1] and gives you the result.
Or do you mean you want to send a request to your GET /stats endpoint? In that case you wouldn't use proxmoxer since you are interacting with your own API, not the PVE one.

[1] https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/lxc
 
proxmox.nodes(pve_node['node']).lxc.get() this is sending the request, more specifically proxmoxer, among probably also other things, sends a request to [1] and gives you the result.
Or do you mean you want to send a request to your GET /stats endpoint? In that case you wouldn't use proxmoxer since you are interacting with your own API, not the PVE one.
hmm, sorry i am still confused. getting the status is fine, the above python route and template returns this:
so all is good, my question is what needs to be sent to start container 100 (CT100) with proxmoxer api from flask?


Python:
@app.route("/startContainer")
def start():
    # what do i call here to start CT100
Screenshot from 2024-04-30 14-51-35.png
 
  • Like
Reactions: ospfeigrp

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!