Frequently Asked Question

Proxmox API - Storage
Last Updated 1 days ago

To retrieve storage information from a Proxmox VE cluster using curl and an API token, you must interact with the Proxmox VE API. The API uses a specific authentication mechanism where the token is passed via the Authorization header in the format PVEAPIToken=@!.

Here is the step-by-step process to achieve this for the host pve91-lab1.gen on port 8006.

1. Identify Your API Token Details

Before running the command, ensure you have the following details from your Proxmox Web UI (Datacenter -> Permissions -> Users):

  • Username: The user ID (e.g., admin or gen-support).
  • Realm: The authentication realm (usually pve or pam).
  • Token ID: The specific token identifier (e.g., gen-support@pve!my-token-id).
  • Token Secret: The actual secret key associated with that token.

The full token string for the header is constructed as: PVEAPIToken=@!

Note: In many Proxmox setups, the "Token ID" field in the UI already includes the @realm part. If so, use the value exactly as shown in the "Token ID" column.

2. Construct the API Endpoint

The endpoint to list all storage nodes is: https://pve91-lab1.gen:8006/api2/json/storage

3. Execute the Curl Command

Run the following command in your terminal. Replace the placeholder values with your actual credentials.

curl -k -s -X GET \
  -H "Authorization: PVEAPIToken=admin@pve!my-token-id" \
  "https://pve91-lab1.gen:8006/api2/json/storage"

Explanation of Flags:

  • -k: Allows insecure SSL connections (useful if your Proxmox node uses a self-signed certificate, which is common in lab environments).
  • -s: Silent mode (suppresses progress meter).
  • -X GET: Specifies the HTTP method.
  • -H "Authorization: ...": Passes the API token for authentication.
  • "https://...": The target API endpoint.

4. Interpreting the Response

The command will return a JSON object containing details of all configured storages (e.g., local, nfs, ceph, lvm).

Example response structure:

{
  "data": [
    {
      "storage": "local",
      "type": "dir",
      "path": "/var/lib/vz",
      "nodes": ["pve91-lab1"]
    },
    {
      "storage": "nfs-storage",
      "type": "nfs",
      "path": "/mnt/pve/nfs-storage",
      "nodes": ["pve91-lab1"]
    }
  ]
}

5. Troubleshooting

If the command fails, check the following:

  • Authentication Error (401): Verify the Authorization header format. Ensure there are no spaces around the ! in the token ID. Ensure the user has the Sys.Audit privilege or specific storage read permissions.
  • Connection Refused: Ensure the Proxmox node is reachable on port 8006 and that the firewall allows the connection.
  • SSL Certificate Errors: If you do not use the -k flag, ensure the server's SSL certificate is trusted by your system.
  • Invalid Endpoint: Ensure you are using /api2/json/storage and not /api2/json/nodes//storage unless you want to filter by a specific node.

Practical Example: Filtering for Specific Storage

If you only want to see the status of a specific storage (e.g., local), you can filter the JSON output using jq (if installed):

curl -k -s -X GET \
  -H "Authorization: PVEAPIToken=admin@pve!my-token-id" \
  "https://pve91-lab1.gen:8006/api2/json/storage" | jq '.data[] | select(.storage == "local")'

To retrieve storage information from a Proxmox VE cluster using curl and an API token, you must interact with the Proxmox REST API. The specific endpoint for listing all storages is /api2/json/storage.


This website relies on temporary cookies to function, but no personal data is ever stored in the cookies.
OK
Powered by GEN UK CLEAN GREEN ENERGY

Loading ...