Skip to content

client-api/pmg-rust

Repository files navigation

pmg-rust

Rust SDK for the Proxmox Mail Gateway API. Generated from the upstream apidoc.js from Proxmox Mail Gateway via openapi-generator-cli with custom Mustache template overrides.

Not an official Proxmox project. Community SDK derived from the upstream apidoc.js. Always verify against the upstream API viewer. https://pmg.proxmox.com/.

Targets reqwest + serde. Requires Rust ≥ 1.75 (2021 edition).

Install

Published to crates.io on every GitHub release:

cargo add clientapi-pmg

Or pin the version explicitly:

# Cargo.toml
[dependencies]
clientapi-pmg = "*"

The import path is the snake_case form of the crate name, e.g. use clientapi_pve::apis::nodes_api;.

Usage

The Rust SDK uses module-level functions per tag — there's no Client struct facade because Rust modules don't bind to method receivers. Instead, hold a Configuration and pass it into each call:

use clientapi_pmg::apis::{configuration::Configuration, qemu_api, nodes_api};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut cfg = Configuration::new();
    cfg.base_path = "https://pmg1.example.com:8006/api2/json".into();
    cfg.api_key = Some(clientapi_pmg::apis::configuration::ApiKey {
        prefix: None,
        key: "PMGAPIToken=user@realm!tokenid=uuid-secret".into(),
    });

    let status = qemu_api::qemu_vm_status(&cfg, "pmg1", 100).await?;
    let nodes  = nodes_api::nodes_get_nodes(&cfg).await?;
    println!("{:?}", status);
    Ok(())
}

Compound configs

PVE encodes many fields as CLI-style shorthand strings (net0=virtio,bridge=vmbr0,firewall=1). Round-trip helpers are emitted for every compound config schema:

use clientapi_pmg::models::PveQemuNetConfig;

let cfg = PveQemuNetConfig {
    model: "virtio".into(),
    bridge: Some("vmbr0".into()),
    firewall: Some("1".into()),
    ..Default::default()
};
let shorthand = cfg.to_shorthand();
// → "virtio,bridge=vmbr0,firewall=1"

Indexed families

Numbered properties (net0..net31, mp0..mp255, …) are exposed on every model as a single Option<HashMap<u32, ItemType>> field with manual Serialize/Deserialize impls that round-trip the prefixed wire keys:

use std::collections::HashMap;

let mut nets: HashMap<u32, models::PveQemuNetField> = HashMap::new();
nets.insert(0, models::PveQemuNetField::default());
nets.insert(3, models::PveQemuNetField::default());

let req = QemuCreateVmRequest {
    nets: Some(nets),
    ..Default::default()
};
// Wire format: { "net0": ..., "net3": ... }

License

Apache 2.0 — see LICENSE.