[SOLVED] Manage pools via API

unam

Active Member
Nov 21, 2019
24
3
43
37
Hi,

Following my previous post concerning our custom deployments, I am trying to build a dev environment for our team.
The use case is :

- lxc rootfs creation with packer via Jenkins
- push rootfs on proxmox
- import rootfs as new lxc
- start some jobs into theses new containers

I am writing a script using pvesh to import the rootfs in proxmox.
The host will be shared between some developers and I was thinking about creatings pools with containers into. Every dev will have privileges on its own pool and will be able to manage containers into.

The final workflow will be to re-generate every containers on sunday.
For this, I need to get every id in each pool for deleting them and create again.

I already had a look at the pvesh tool and the api doc and started to play with :
Code:
pvesh set /pools/lxc-packer -vms 100
pvesh set /pools/lxc-packer -vms 101

When I try to get all id, is use
Code:
pvesh get /pools/lxc-packer/
But the output is huge and not script friendly to get only ids.

Question, is there any tool using pvesh or anything else to get id in specific pool ? Or some "already though" solution for my use case ?

Thanks for reading.

Regards,
 
Last edited:
you can use --output-format json to get properly formatted JSON, and then parse that (e.g. with jq, or whatever your scripting environment supports.

e.g.,
Code:
pvesh get /pools/lxc-packer --output-format json | jq '.members| map(select(.type == "lxc"))'

will return all the info of all the LXC containers in your pool.

Code:
pvesh get /pools/lxc-packer --output-format json | jq '.members| map(select(.type == "lxc").id?)'

will return an array of IDs as returned by the API (prefixed with "lxc/").

see 'man jq' for more details ;)
 
  • Like
Reactions: unam
Wow, thank you.
I already heard about jq but never used nor check what it was.

It's done for now, thank you I can play with the api and with the informations I need.

Regards,
 

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!