Proxmox /nodes/<node>/apt/repositories API is weird

divStar

New Member
Jun 13, 2024
13
2
3
Hello,

First I want to say, that I am really happy and grateful to be able and allowed to use such a great piece of software (Proxmox). I am pretty new to it, so I apologize if this is an oversight on my part.

I have decided to build a Terraform / OpenTofu based configuration script, that does some initial set up like:
  • Create user
  • Create API token
  • Import ZFS pool
  • Import ZFS dataset for ISO and other images
  • Install scripts
  • Modify repositories
I am having issues especially with the last one on the list because https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/apt/repositories does not follow any CRUD standards. It's also quite complicated to enable/disable repositories based on the index - it'd be much easier to do so based on the handle.

Furthermore if I use the PUT endpoint to create a standard repository, it's added over and over again and instead of being added to its own sources.list file within /etc/apt/sources.list.d/, it's added to /etc/apt/sources.list. Since pve-enterprise.list is its own list (and IMO rightfully so) and within the directory mentioned above, I don't understand why this isn't handled the same in all cases.

Here's a suggestion to make this piece of API useful:
  • GET /nodes/{node}/apt/repositories
    • Lists all configured repositories with their details (handle, URL, status, etc.)
    • Response should include standard-repositories (with everything relevant) and possibly custom repositories
  • POST /nodes/{node}/apt/repositories
    • Creates a new repository configuration
    • Properly creates a new file in /etc/apt/sources.list.d/
    • Requires body with repository details (URI, version, filename?)
  • GET /nodes/{node}/apt/repositories/{handle}
    • Returns details for specific repository
    • Would look similar to e.g. the GET without the {handle} ID, but limited to one repository only
  • PUT /nodes/{node}/apt/repositories/{handle}
    • Updates existing repository configuration
    • Can enable/disable repository
    • Updates proper file in /etc/apt/sources.list.d/ by prepending a # (just as it does now)
  • DELETE /nodes/{node}/apt/repositories/{handle}
    • Removes repository configuration
    • Cleanly deletes corresponding file from /etc/apt/sources.list.d/
    • Could also delete just the line in that file
This is just a suggestion and as long as the API isn't consistent, I suppose I could just use commands via ssh_resource to do just that. The only downside of this workaround is, that I have to know the VERSION_CODENAME and the proper URI.

Thank you for reading and I am eager to hear what other, probably much more experienced users, think about this.
 
Last edited:
Hi,
API changes to existing endpoints would break existing use cases. The reason handles are not used for most operations is because you can have arbitrary repositories configured, not just the standard ones identified by handles.

The no-subscription and test repositories are placed in /etc/apt/sources.list directly, to be in-line with the pre-existing documentation: https://pve.proxmox.com/wiki/Package_Repositories#sysadmin_no_subscription_repo

Feel free to open an enhancement request about the re-adding issue: https://bugzilla.proxmox.com/
 
Thank you for the response.

For the time being I decided to use the ssh_resource approach.

Additive API changes to existing endpoints don't necessarily mean breaking changes (e.g. additional properties in responses or optional properties in requests).

Since the package repositories documentation outlines, that the repos are supposed to be added to the sources.list file (even though it isn't recommended, see e.g. https://wiki.debian.org/SourcesList#Using__a_text_editor), there must have been a reason to so, which is why I currently decided against filing a bug.