### Example: Create and Get SDN Zone Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/advanced-features.md Demonstrates the process of creating a new VXLAN-based SDN zone and then retrieving it using the Proxmox VE API client. ```go cluster, _ := client.Cluster(ctx) _ = cluster.NewSDNZone(ctx, &proxmox.SDNZoneOptions{ ID: "vxlan-1", Type: "vxlan", Nodes: "pve1,pve2,pve3", }) zone := cluster.SDNZone(ctx, "vxlan-1") ``` -------------------------------- ### Run SDN Walkthrough Example Source: https://github.com/luthermonson/go-proxmox/blob/main/examples/sdn/README.md Sets up environment variables and executes the Go example for the SDN walkthrough. Ensure you have a Proxmox VE cluster and a valid API token. ```shell export PROXMOX_URL="https://lab.example.test:8006/api2/json" export PROXMOX_TOKENID="root@pam!sdn-example" export PROXMOX_SECRET="" cd examples/sdn go run . ``` -------------------------------- ### Resource Traversal Example Source: https://github.com/luthermonson/go-proxmox/blob/main/AGENTS.md Illustrates the resource traversal pattern in the Proxmox client library, starting from the client to access cluster, nodes, virtual machines, and their configurations. ```go cluster, err := client.Cluster(ctx) node, err := client.Node(ctx, "node-name") vm, err := node.VirtualMachine(ctx, 100) config, err := vm.Config(ctx) ``` -------------------------------- ### Production Client Setup with CA Bundle and API Token Source: https://github.com/luthermonson/go-proxmox/blob/main/README.md Illustrates a production-ready client setup using a specific CA bundle for verification and an API token. mTLS is optional and can be configured separately. ```go caBundle, _ := os.ReadFile("/etc/ssl/certs/pve-cluster.pem") pool := x509.NewCertPool() pool.AppendCertsFromPEM(caBundle) client := proxmox.NewClient("https://pve.example.com:8006/api2/json", proxmox.WithAPIToken("automation@pve!ci", ""), proxmox.WithRootCAs(pool), proxmox.WithTimeout(30*time.Second), // optional mTLS: // proxmox.WithClientCertificate(clientCert), ) ``` -------------------------------- ### Resource Traversal: SDN Controller Example Source: https://github.com/luthermonson/go-proxmox/blob/main/README.md Demonstrates how to get a handle to a specific resource (SDN Controller) from a parent resource (Cluster) and perform operations like updating and deleting. This pattern applies to many other resource types. ```go cluster, _ := client.Cluster(ctx) // SDN controllers — getter on the parent, operations on the instance. ctrl := cluster.SDNController("evpn-1") if err := ctrl.Update(ctx, &proxmox.SDNControllerOptions{ASN: proxmox.IntOrBool(65000)}); panic(err) } _, _ = ctrl.Delete(ctx) // Same pattern for VM/container snapshots, firewall rules, ceph OSDs/pools/mons, // HA resources, ACME accounts, custom CPU models, fabrics, IPAMs, prefix-lists, etc. ``` -------------------------------- ### Perform Common go-proxmox Operations Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/overview.md Demonstrates basic operations such as listing nodes, getting cluster information, accessing specific nodes and VMs, and managing VM states (start, stop, reboot). ```go ctx := context.Background() // List all nodes nodes, _ := client.Nodes(ctx) // Get cluster info cluster, _ := client.Cluster(ctx) // Access a specific node node, _ := client.Node(ctx, "pve") status, _ := node.Status(ctx) // List VMs on a node vms, _ := node.VirtualMachines(ctx) // Get a specific VM handle vm, _ := node.VirtualMachine(ctx, 100) config, _ := vm.Config(ctx) // Start/stop/reboot a VM vm.Start(ctx) vm.Shutdown(ctx) vm.Reboot(ctx) ``` -------------------------------- ### Example: Wait for Migration Task Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/vm-container-api.md Shows how to initiate a VM migration and wait for its completion within a given timeout, logging any errors. ```go task, _ := vm.Migrate(ctx, "pve2", nil) if err := task.Wait(ctx, 30*time.Minute); err != nil { log.Fatalf("Migration failed: %v", err) } ``` -------------------------------- ### Manage Virtual Machines Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/README.md Shows how to interact with a specific virtual machine, including retrieving its configuration and starting it. Requires an existing VM and a configured client. ```go import "context" import "time" node, _ := client.Node(ctx, "pve") vm, _ := node.VirtualMachine(ctx, 100) config, _ := vm.Config(ctx) task, _ := vm.Start(ctx) task.Wait(ctx, 5*time.Minute) ``` -------------------------------- ### Example: Delete a Virtual Machine Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/vm-container-api.md Demonstrates the process of stopping a virtual machine and then permanently deleting it. ```go vm, _ := node.VirtualMachine(ctx, 100) _ = vm.Stop(ctx) task, _ := vm.Delete(ctx) // Permanent ``` -------------------------------- ### Container.Start Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/vm-container-api.md Starts a stopped container. ```APIDOC ## Container.Start ### Description Starts a stopped container. ### Method POST (Assumed, based on operation) ### Endpoint /nodes/{node}/lxc/{vmid}/status/start ### Parameters #### Path Parameters - **node** (string) - Required - The node where the container resides. - **vmid** (int) - Required - The ID of the container. ### Response #### Success Response (200) - **task_id** (string) - The ID of the task created for starting the container. ``` -------------------------------- ### Start Container Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/vm-container-api.md Starts a stopped container. Returns a Task object representing the operation. ```go func (c *Container) Start(ctx context.Context) (*Task, error) ``` -------------------------------- ### Get Container Configuration Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/vm-container-api.md Retrieves the configuration details of a container. ```go func (c *Container) Config(ctx context.Context) (*ContainerConfig, error) ``` -------------------------------- ### VirtualMachine.Current Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/vm-container-api.md Gets a snapshot of the current VM configuration and its basic state. ```APIDOC ## VirtualMachine.Current ### Description Gets current VM configuration snapshot and basic state. ### Method GET ### Endpoint /nodes/{node}/qemu/{vmid}/status/current ### Response #### Success Response (200) - **`*VirtualMachineCurrent`** (object) - Current VM configuration and state. ``` -------------------------------- ### Access and Manage Virtual Machines with go-proxmox Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/overview.md Demonstrates obtaining a handle to a specific virtual machine and performing actions such as starting, stopping, rebooting, or retrieving its configuration. ```go // VM operations are similar node, _ := client.Node(ctx, "pve") vm := node.VirtualMachine(ctx, 100) // Returns *VirtualMachine handle vm.Start(ctx) vm.Config(ctx) ``` -------------------------------- ### Run the Proxmox Proxy Server Source: https://github.com/luthermonson/go-proxmox/blob/main/examples/term-and-vnc/README.md Start the Go server using `go run main.go`. The server will be accessible at `https://localhost:8523` with SSL enabled. ```bash go run main.go ``` -------------------------------- ### Configure Client with LeveledLogger Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/configuration.md This example shows how to initialize a LeveledLogger with a specific log level (e.g., LevelDebug) and pass it to the Proxmox client using WithLogger. This enables filtered logging for client operations. ```go logger := &proxmox.LeveledLogger{Level: proxmox.LevelDebug} client := proxmox.NewClient(url, proxmox.WithAPIToken("root@pam!token", "secret"), proxmox.WithLogger(logger), ) ``` -------------------------------- ### Install Go Dependencies Source: https://github.com/luthermonson/go-proxmox/blob/main/examples/term-and-vnc/README.md Run `go mod tidy` to download and manage the necessary Go modules for the project. This command ensures all dependencies are correctly resolved. ```bash go mod tidy ``` -------------------------------- ### Get VM Configuration Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/vm-container-api.md Retrieves the complete configuration for a virtual machine. Use this to access details like name, memory, and CPU cores. ```Go vm, _ := node.VirtualMachine(ctx, 100) config, _ := vm.Config(ctx) fmt.Printf("VM %d: %s\n", vm.VMID, config.Name) fmt.Printf("Memory: %d MB, Cores: %d\n", config.Memory, config.Cores) ``` -------------------------------- ### Get Node Subdirectories Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/node-api.md Lists available sub-resources on a node, filtered by token permissions. Use this to discover available resource types like 'qemu', 'lxc', or 'storage'. ```go func (n *Node) Subdirs(ctx context.Context) ([]string, error) ``` ```go subdirs, _ := node.Subdirs(ctx) fmt.Println(subdirs) // [qemu lxc storage firewall ...] ``` -------------------------------- ### Creating a New SDN Zone Source: https://github.com/luthermonson/go-proxmox/blob/main/migration/v0.6.0.md Example of creating a new SDN zone, demonstrating that the Nodes field on the write side (SDNZoneOptions) remains a plain string, expecting a comma-joined format. ```go _ = cluster.NewSDNZone(ctx, &proxmox.SDNZoneOptions{ Name: "vxlan-1", Type: "vxlan", Nodes: "pve1,pve2,pve3", }) ``` -------------------------------- ### Example Pointer Field Comment Source: https://github.com/luthermonson/go-proxmox/blob/main/AGENTS.md Illustrates the required comment format for pointer fields tied to Proxmox defaults. This helps future readers understand the rationale behind using a pointer and the default value it represents. ```go // CPUUnits — PVE default 1024 (cgroup v1) / 100 (cgroup v2). Plain int // would default to 0 and override the server's CPU weight on edit. See #199. CPUUnits *int `json:"cpuunits,omitempty"` ``` -------------------------------- ### Configure client with default retries Source: https://github.com/luthermonson/go-proxmox/blob/main/README.md Installs a retry mechanism for transient failures like 502, 503, and 429 errors, using default settings for attempts and backoff. ```go client := proxmox.NewClient(url, proxmox.WithAPIToken("automation@pve!ci", ""), proxmox.WithRetry(), // defaults: 3 attempts, 200ms–5s backoff ) ``` -------------------------------- ### Setting Network Device Configuration Source: https://github.com/luthermonson/go-proxmox/blob/main/migration/v0.7.0.md When updating or creating a virtual machine, device configurations like network interfaces are passed using the option-pair shape. This example shows how to set the 'net1' configuration for a virtual machine. ```go _, err := vm.Config(ctx, proxmox.VirtualMachineOption{Name: "net1", Value: "virtio,bridge=vmbr0,tag=42"}, ) ``` -------------------------------- ### Handle Task Status and Waiting Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/INDEX.md Demonstrates how to get the status of a task and wait for its completion with a timeout. Assumes a task object and context are available. ```go task, _ := vm.Clone(ctx, newID, nil) status, _ := task.Status(ctx) // Check progress _ = task.Wait(ctx, timeout) // Block until done ``` -------------------------------- ### Discover Permissions with Subdirs Method Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/overview.md Shows how to use the `Subdirs()` method on a node to discover available resource types (e.g., 'qemu', 'lxc') that the current token has access to, before attempting to list them. ```go node, _ := client.Node(ctx, "pve") subdirs, _ := node.Subdirs(ctx) // ["qemu", "lxc", "storage", ...] if slices.Contains(subdirs, "qemu") { vms, _ := node.VirtualMachines(ctx) } ``` -------------------------------- ### Configure Proxmox Environment Variables Source: https://github.com/luthermonson/go-proxmox/blob/main/examples/term-and-vnc/README.md Create a `.env` file in the root directory to store Proxmox connection details and VM information. Ensure these values are correct for your Proxmox setup. ```plaintext PROXMOX_USERNAME=root@pam PROXMOX_PASSWORD=password PROXMOX_URL=https://192.168.0.200:8006/api2/json PROXMOX_NODE=proxmox5 PROXMOX_VM=216 ``` -------------------------------- ### Basic Login with Username and Password Source: https://github.com/luthermonson/go-proxmox/blob/main/README.md Demonstrates how to create a client and authenticate using a username and password. Ensure the Proxmox API is accessible and credentials are correct. ```go package main import ( "context" "fmt" "github.com/luthermonson/go-proxmox" ) func main() { credentials := proxmox.Credentials{ Username: "root@pam", Password: "12345", } client := proxmox.NewClient("https://localhost:8006/api2/json", proxmox.WithCredentials(&credentials), ) version, err := client.Version(context.Background()) if err != nil { panic(err) } fmt.Println(version.Release) // 7.4 } ``` -------------------------------- ### GET Request Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/client-core.md Performs a GET request to the specified API path and unmarshals the JSON response. ```APIDOC ## Get ### Description Performs a GET request and unmarshals the JSON response. ### Signature ```go func (c *Client) Get(ctx context.Context, p string, v interface{}) error ``` ### Parameters #### Path Parameters * **ctx** (context.Context) - Required - Request context * **p** (string) - Required - API path * **v** (interface{}) - Optional - Pointer to unmarshal response into ### Example ```go var nodes []proxmox.NodeStatus if err := client.Get(ctx, "/api2/json/nodes", &nodes); err != nil { log.Fatal(err) } ``` ``` -------------------------------- ### GET Request with Parameters Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/client-core.md Performs a GET request with query parameters and unmarshals the response. The parameters are encoded as URL query parameters. ```APIDOC ## GetWithParams ### Description Performs a GET request with query parameters and unmarshals the response. The `d` parameter is encoded as URL query parameters. ### Signature ```go func (c *Client) GetWithParams(ctx context.Context, p string, d interface{}, v interface{}) error ``` ### Parameters #### Path Parameters * **ctx** (context.Context) - Required - Request context * **p** (string) - Required - API path * **d** (interface{}) - Optional - Struct to encode as query parameters * **v** (interface{}) - Optional - Pointer to unmarshal response into ### Example ```go opts := struct { Filter string `url:"filter"` }{ Filter: "running", } var result []interface{} client.GetWithParams(ctx, "/api2/json/cluster/resources", opts, &result) ``` ``` -------------------------------- ### Perform GET Request Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/client-core.md Executes a GET request to a specified API path and unmarshals the JSON response into the provided interface. Suitable for retrieving data. ```go var nodes []proxmox.NodeStatus if err := client.Get(ctx, "/api2/json/nodes", &nodes); err != nil { log.Fatal(err) } ``` -------------------------------- ### Client Configuration with API Token and Options Source: https://github.com/luthermonson/go-proxmox/blob/main/README.md Shows how to configure the client for a lab environment using an API token, skipping SSL verification, and setting a timeout. For production, use proper CA bundles and avoid skipping verification. ```go package main import ( "context" "fmt" "time" "github.com/luthermonson/go-proxmox" ) func main() { client := proxmox.NewClient("https://localhost:8006/api2/json", proxmox.WithAPIToken("root@pam!mytoken", "somegeneratedapitokenguidefromtheproxmoxui"), proxmox.WithInsecureSkipVerify(), // lab only proxmox.WithTimeout(30*time.Second), // http.DefaultClient has no timeout ) version, err := client.Version(context.Background()) if err != nil { panic(err) } fmt.Println(version.Release) // 6.3 } ``` -------------------------------- ### Handle Specific Proxmox API Errors Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/INDEX.md Provides examples of how to check for and handle common Proxmox API errors such as unauthorized access or resource not found. Requires importing the 'log' package. ```go if err != nil { if proxmox.IsNotAuthorized(err) { log.Fatal("Auth failed") } if proxmox.IsNotFound(err) { log.Fatal("Resource not found") } log.Fatal("Error:", err) } ``` -------------------------------- ### Perform GET Request with Query Parameters Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/client-core.md Executes a GET request with URL query parameters, useful for filtering or specifying options for the request. The parameters are encoded from the provided struct. ```go opts := struct { Filter string `url:"filter"` }{"running"} var result []interface{} client.GetWithParams(ctx, "/api2/json/cluster/resources", opts, &result) ``` -------------------------------- ### Client Initialization Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/client-core.md Demonstrates how to create a new Proxmox API client with optional configurations. ```APIDOC ## NewClient ### Description Creates and returns a new Proxmox API client. ### Signature ```go func NewClient(baseURL string, opts ...Option) *Client ``` ### Parameters #### Path Parameters * **baseURL** (string) - Required - The Proxmox API endpoint URL, typically `https://hostname:8006/api2/json` * **opts** ([]Option) - Optional - Variable number of configuration options ### Returns * **Client** (*Client) - A configured HTTP client for the Proxmox API. ### Example ```go client := proxmox.NewClient( "https://pve.example.com:8006/api2/json", proxmox.WithAPIToken("root@pam!mytoken", "secret"), proxmox.WithTimeout(30*time.Second), ) ``` ``` -------------------------------- ### Create a New Virtual Machine with go-proxmox Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/overview.md Shows how to create a new virtual machine by specifying its ID, name, memory, and core count using the `NewVirtualMachine` method. ```go ctx := context.Background() // Create a new VM task, _ := node.NewVirtualMachine(ctx, &proxmox.VirtualMachineCreateOptions{ VMID: 101, Name: "my-vm", Memory: 2048, Cores: 2, }) ``` -------------------------------- ### Node.APTPackageVersions Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/node-api.md Lists version information for installed packages. ```APIDOC ## Node.APTPackageVersions ### Description Lists version information for installed packages. ### Method GET ### Endpoint /nodes/{node}/apt/packages ### Parameters #### Path Parameters - **node** (string) - Required - The name of the node ### Response #### Success Response (200) - **APTPackageVersion** (array) - List of installed packages with version information ``` -------------------------------- ### Initialize Proxmox Client with API Token Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/README.md Demonstrates how to create a new Proxmox client instance using an API token for authentication. This is useful for programmatic access to Proxmox VE. ```go import "github.com/luthermonson/go-proxmox" import "context" import "fmt" client := proxmox.NewClient( "https://pve.example.com:8006/api2/json", proxmox.WithAPIToken("root@pam!automation", "secret"), ) nodes, _ := client.Nodes(context.Background()) for _, node := range nodes { fmt.Printf("%s: %s\n", node.Name, node.Status) } ``` -------------------------------- ### Get Container Status Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/vm-container-api.md Retrieves the current status of a container. ```go func (c *Container) Status(ctx context.Context) (*ContainerStatus, error) ``` -------------------------------- ### Configure Client with OTP and Eager Authentication Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/configuration.md Use `WithOTP` for two-factor authentication codes and `WithEagerAuth` to trigger session creation during client initialization. This helps mitigate brute-force delays at startup. ```go client := proxmox.NewClient( "https://pve.example.com:8006/api2/json", proxmox.WithCredentials(&proxmox.Credentials{ Username: "admin", Password: "password", }), proxmox.WithOTP("123456"), proxmox.WithEagerAuth(), ) ``` -------------------------------- ### Get Node Status Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/node-api.md Retrieves the current status information for the node. ```go func (n *Node) Status(ctx context.Context) (*NodeStatus, error) ``` -------------------------------- ### List and Iterate Over Virtual Machines Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/INDEX.md Illustrates how to retrieve a list of all virtual machines on a node and then iterate through them to display their status. Requires importing the 'fmt' and 'slices' packages. ```go vms, _ := node.VirtualMachines(ctx) for _, vm := range vms { status, _ := vm.Status(ctx) fmt.Printf("%d: %s\n", vm.VMID, status.Status) } ``` -------------------------------- ### Get a Specific Container Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/node-api.md Obtain a handle to a specific container using its VMID. ```go func (n *Node) Container(ctx context.Context, vmid int) (*Container, error) ``` -------------------------------- ### Get Group Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/cluster-api.md Returns a handle to a specific group based on its group ID. ```go func (c *Client) Group(ctx context.Context, groupid string) (*Group, error) ``` -------------------------------- ### Get User Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/cluster-api.md Returns a handle to a specific user based on their user ID. ```go func (c *Client) User(ctx context.Context, userid string) (*User, error) ``` -------------------------------- ### APTRepositories Type Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/types.md Represents the complete APT configuration. Returned by Node.APTRepositories(). ```go type APTRepositories struct { Digest string // Etag for concurrent edits Files []*APTRepositoryFile Errors []*APTRepositoryError Infos []*APTRepositoryInfo StandardRepos []*APTStandardRepo // PVE catalog of well-known repos } ``` -------------------------------- ### Get Container Current State Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/vm-container-api.md Retrieves the current running state information for a container. ```go func (c *Container) Current(ctx context.Context) (*ContainerCurrent, error) ``` -------------------------------- ### Create User Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/cluster-api.md Creates a new user with the provided configuration. Requires a context and a NewUser object. ```go func (c *Client) NewUser(ctx context.Context, user *NewUser) error ``` -------------------------------- ### Get a Specific Firewall Rule Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/node-api.md Fetches a specific firewall rule by its position on the node. ```go func (n *Node) FirewallRule(ctx context.Context, pos int) (*FirewallRule, error) ``` -------------------------------- ### Client Configuration with Functional Options Source: https://github.com/luthermonson/go-proxmox/blob/main/AGENTS.md Demonstrates initializing a Proxmox client using functional options. Options like WithHTTPClient, WithCredentials, and WithAPIToken can be passed to NewClient. TLS and transport options are deferred until finalizeOptions runs. ```go client, err := proxmox.NewClient(baseURL, proxmox.WithHTTPClient(customHTTPClient), proxmox.WithCredentials("user", "pass")) if err != nil { log.Fatal(err) } ``` -------------------------------- ### Get Cluster Backup Information Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/advanced-features.md Fetches the cluster-wide backup configuration and status. Requires a context. ```go func (cl *Cluster) BackupInfo(ctx context.Context) (*BackupInfo, error) ``` -------------------------------- ### SDNController.Config Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/advanced-features.md Get controller configuration. Retrieves the current configuration details for a specific SDN controller. ```APIDOC ## SDNController.Config ### Description Get controller configuration. ### Method GET ### Endpoint /cluster/sdn/controllers/{controller}/config ### Parameters #### Path Parameters - **`controller`** (string) - Required - The ID of the SDN controller. #### Query Parameters - **`ctx`** (context.Context) - Required - Context for the request. ### Response #### Success Response (200) - **`config`** (map[string]string) - Controller configuration details. #### Response Example ```json { "config": { "id": "bgp-controller-1", "type": "bgp" } } ``` ``` -------------------------------- ### Initialize go-proxmox Client with Credentials and 2FA Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/overview.md Suitable for interactive use, this method supports username/password authentication and Two-Factor Authentication (2FA) codes. It can also eagerly authenticate at startup. ```go import "github.com/luthermonson/go-proxmox" // Credential auth (for interactive use with 2FA support) client := proxmox.NewClient( "https://pve.example.com:8006/api2/json", proxmox.WithCredentials(&proxmox.Credentials{ Username: "admin", Password: "password", }), proxmox.WithOTP("123456"), // 2FA code proxmox.WithEagerAuth(), // auth at startup ) ``` -------------------------------- ### Configure SDN Zone and VNet Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/README.md Illustrates setting up Software-Defined Networking (SDN) in Proxmox by creating a new VXLAN zone and a virtual network within that zone. This is for advanced network configurations. ```go import "context" cluster, _ := client.Cluster(ctx) _ = cluster.NewSDNZone(ctx, &proxmox.SDNZoneOptions{ ID: "vxlan-1", Type: "vxlan", Nodes: "pve1,pve2", }) zone := cluster.SDNZone(ctx, "vxlan-1") _ = zone.NewVNet(ctx, &proxmox.SDNVNetOptions{ ID: "vnet-1", Zone: "vxlan-1", Vlan: 100, }) ``` -------------------------------- ### SDNVNet.Config Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/advanced-features.md Get VNet configuration. Retrieves the current configuration details for a specific virtual network. ```APIDOC ## SDNVNet.Config ### Description Get VNet configuration. ### Method GET ### Endpoint /cluster/sdn/vnets/{vnet}/config ### Parameters #### Path Parameters - **`vnet`** (string) - Required - The ID of the virtual network. #### Query Parameters - **`ctx`** (context.Context) - Required - Context for the request. ### Response #### Success Response (200) - **`config`** (map[string]string) - VNet configuration details. #### Response Example ```json { "config": { "id": "vnet1", "zone": "zone1", "vlan": 100 } } ``` ``` -------------------------------- ### SDNZone.Config Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/advanced-features.md Get zone configuration. Retrieves the current configuration details for a specific SDN zone. ```APIDOC ## SDNZone.Config ### Description Get zone configuration. ### Method GET ### Endpoint /cluster/sdn/zones/{zone}/config ### Parameters #### Path Parameters - **`zone`** (string) - Required - The ID of the SDN zone. #### Query Parameters - **`ctx`** (context.Context) - Required - Context for the request. ### Response #### Success Response (200) - **`config`** (map[string]string) - Zone configuration details. #### Response Example ```json { "config": { "id": "zone1", "type": "vxlan", "nodes": "pve1,pve2" } } ``` ``` -------------------------------- ### Initialize go-proxmox Client with API Token Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/overview.md Use this method for daemons or CI environments. It requires the Proxmox API URL, the token ID, and the secret. ```go import "github.com/luthermonson/go-proxmox" // Token auth (recommended for daemons/CI) client := proxmox.NewClient( "https://pve.example.com:8006/api2/json", proxmox.WithAPIToken("root@pam!automation", "secret-uuid"), proxmox.WithTimeout(30*time.Second), ) ``` -------------------------------- ### Node.APTRepositories Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/node-api.md Retrieves the complete APT configuration. ```APIDOC ## Node.APTRepositories ### Description Retrieves the complete APT configuration (/etc/apt/sources.list and sources.list.d). ### Method GET ### Endpoint /nodes/{node}/apt/repositories ### Parameters #### Path Parameters - **node** (string) - Required - The name of the node ### Response #### Success Response (200) - **APTRepositories** (object) - Current repositories with digest for concurrent edits ``` -------------------------------- ### Get Authentication Domain Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/cluster-api.md Returns a handle to a specific authentication domain based on its realm identifier. ```go func (c *Client) Domain(ctx context.Context, realm string) (*Domain, error) ``` -------------------------------- ### APTRepositoryFile Type Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/types.md Represents a single APT sources file, such as /etc/apt/sources.list. ```go type APTRepositoryFile struct { Path string // File path (e.g., "/etc/apt/sources.list") FileType string // "list" or "sources" Digest []int // Per-file digest Repositories []*APTRepository } ``` -------------------------------- ### Get Role Permissions Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/cluster-api.md Retrieves the permissions for a specific role ID. Returns a Permission object. ```go func (c *Client) Role(ctx context.Context, roleid string) (Permission, error) ``` -------------------------------- ### Create and Wait for a New Virtual Machine Task Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/INDEX.md Shows the pattern for creating a new virtual machine and then waiting for the associated task to complete within a specified duration. ```go task, _ := node.NewVirtualMachine(ctx, opts) _ = task.Wait(ctx, 5*time.Minute) ``` -------------------------------- ### Get Replication Job Status Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/node-api.md Retrieves the status and control information for a specific replication job on the node. ```go func (n *Node) Replication(ctx context.Context, id string) (*NodeReplicationJob, error) ``` -------------------------------- ### Configure Client with Credentials Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/configuration.md Use `WithCredentials` to authenticate using username and password. This option triggers automatic ticket-based session management. ```go client := proxmox.NewClient( "https://pve.example.com:8006/api2/json", proxmox.WithCredentials(&proxmox.Credentials{ Username: "root@pam", Password: "secretpassword", }), ) ``` -------------------------------- ### Client.NewUser Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/cluster-api.md Creates a new user with the provided configuration. It requires a context and a NewUser struct. ```APIDOC ## Client.NewUser ### Description Creates a new user. ### Method Not specified (likely a Go method call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **user** (*NewUser) - Required - User configuration. ### Request Example None ### Response #### Success Response None (returns error) #### Response Example None ``` -------------------------------- ### Cluster.BulkAction Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/advanced-features.md Performs bulk actions across multiple resources in the cluster, such as stopping, starting, or rebooting VMs and nodes. ```APIDOC ## Cluster.BulkAction ### Description Performs bulk action (e.g., stop all VMs, reboot nodes). ### Method POST (Assumed based on action) ### Endpoint `/cluster/bulk` (Assumed structure) ### Parameters #### Request Body - **action** (string) - Required - Action: "stop", "start", "reboot", "shutdown". - **nodes** (string) - Required - Target: "all" or comma-joined node list. ``` -------------------------------- ### Manage SDN Controller with go-proxmox Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/overview.md Illustrates how to obtain a handle to an SDN controller and perform operations like updating its configuration or deleting it. ```go // Example: SDN controller update cluster, _ := client.Cluster(ctx) ctrl := cluster.SDNController("evpn-1") // Returns *SDNController handle ctrl.Update(ctx, &proxmox.SDNControllerOptions{ASN: 65000}) ctrl.Delete(ctx) ``` -------------------------------- ### Get Ceph Cluster Handle Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/advanced-features.md Provides access to Ceph distributed storage cluster operations. Requires a context. ```go func (cl *Cluster) Ceph() *Ceph ``` -------------------------------- ### Get Cluster Firewall Handle Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/advanced-features.md Returns a handle to manage cluster-level firewall rules and options. Requires a context. ```go func (cl *Cluster) Firewall() *ClusterFirewall ``` -------------------------------- ### Create a New Virtual Machine Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/node-api.md Use this method to create a new virtual machine on a Proxmox node. Configure VM settings like ID, name, memory, and CPU cores. ```go func (n *Node) NewVirtualMachine(ctx context.Context, options *VirtualMachineCreateOptions) (*Task, error) ``` ```go opts := &proxmox.VirtualMachineCreateOptions{ VMID: 100, Name: "ubuntu-20", Memory: 2048, Cores: 2, } task, err := node.NewVirtualMachine(ctx, opts) if err != nil { log.Fatal(err) } // Wait for task completion... ``` -------------------------------- ### Get a Specific Task Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/node-api.md Obtains a handle to a specific task using its unique UPID (Unique Process ID). ```go func (n *Node) Task(ctx context.Context, upid string) (*Task, error) ``` -------------------------------- ### Create New SDN Controller Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/advanced-features.md Initializes a new SDN controller. Requires context and SDNControllerOptions specifying controller details like ID, type, and BGP ASN if applicable. ```go func (cl *Cluster) NewSDNController(ctx context.Context, options *SDNControllerOptions) error ``` -------------------------------- ### SDNZone.Subnet Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/advanced-features.md Get specific subnet. Retrieves a handle to a specific subnet within an SDN zone, identified by its CIDR notation. ```APIDOC ## SDNZone.Subnet ### Description Get specific subnet. ### Method GET ### Endpoint /cluster/sdn/zones/{zone}/subnets/{subnet} ### Parameters #### Path Parameters - **`zone`** (string) - Required - The ID of the SDN zone. - **`subnet`** (string) - Required - The CIDR notation of the subnet. #### Query Parameters - **`ctx`** (context.Context) - Required - Context for the request. ### Response #### Success Response (200) - **`subnet`** (*SDNSubnet) - Handle to the specific subnet. #### Response Example ```json { "subnet": "10.0.0.0/24", "gateway": "10.0.0.1" } ``` ``` -------------------------------- ### Configure Custom Logger Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/overview.md Demonstrates how to provide a custom structured logger to the client for detailed debug output. ```go logger := &proxmox.LeveledLogger{Level: proxmox.LevelDebug} client := proxmox.NewClient(url, proxmox.WithAPIToken(tokenID, secret), proxmox.WithLogger(logger), ) ``` -------------------------------- ### Get Node Firewall Subdirectories Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/node-api.md Lists firewall sub-resources available on a node, provided the token has the necessary firewall permissions. ```go func (n *Node) FirewallSubdirs(ctx context.Context) ([]string, error) ``` -------------------------------- ### Node.NewVirtualMachine Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/node-api.md Creates a new virtual machine on the node. Requires a context and virtual machine configuration options. ```APIDOC ## Node.NewVirtualMachine ### Description Creates a new virtual machine. ### Method POST ### Endpoint /nodes/{node}/qemu ### Parameters #### Path Parameters - **node** (string) - Required - The node name. #### Request Body - **VMID** (int) - Required - Virtual machine ID (100-999999999). - **Name** (string) - Required - VM name. - **Memory** (int) - Optional - RAM in MB (default 512). - **Cores** (int) - Optional - CPU cores. - **Sockets** (int) - Optional - CPU sockets. - **OSType** (string) - Optional - guest OS type: l26, w32, w64. - **Boot** (string) - Optional - Boot order (e.g., "cdn"). - **Bootdisk** (string) - Optional - Disk to boot from. - **Onboot** (int) - Optional - Start on node boot (0 or 1). ### Request Example ```json { "VMID": 100, "Name": "ubuntu-20", "Memory": 2048, "Cores": 2 } ``` ### Response #### Success Response (200) - **Task** (*Task) - Async task handle. #### Response Example ```json { "id": "qemu/100/exec/12345" } ``` ``` -------------------------------- ### Get Specific Ceph Pool Handle Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/advanced-features.md Returns a handle to a specific Ceph pool by its name. Requires a context and the pool name. ```go func (ceph *Ceph) Pool(ctx context.Context, name string) (*CephPool, error) ``` -------------------------------- ### Load Root Certificates from File Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/configuration.md Reads a PEM-encoded CA bundle from a file and adds certificates to the root pool. The file is read at NewClient time. ```go client := proxmox.NewClient( "https://pve.example.com:8006/api2/json", proxmox.WithAPIToken("root@pam!ci", "secret"), proxmox.WithRootCAFile("/etc/ssl/certs/pve-cluster.pem"), ) ``` -------------------------------- ### Get Specific SDN Controller Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/advanced-features.md Fetches a handle to a specific SDN controller by its identifier. This allows for inspection and management of controller configurations. ```go func (cl *Cluster) SDNController(ctx context.Context, controller string) (*SDNController, error) ``` -------------------------------- ### VirtualMachine.MonitorCommand Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/vm-container-api.md Sends a command to the QEMU monitor of a running virtual machine and returns the response. ```APIDOC ## VirtualMachine.MonitorCommand ### Description Sends a QEMU monitor command to the VM and returns the response. Requires VM to be running and qemu-monitor access permission. ### Method POST (Assumed, based on operation) ### Endpoint /nodes/{node}/qemu/{vmid}/monitor ### Parameters #### Path Parameters - **node** (string) - Required - The node where the VM resides. - **vmid** (int) - Required - The ID of the VM. #### Request Body - **command** (string) - Required - The QEMU monitor command to execute (e.g., `info status`). ### Request Example ```json { "command": "info status" } ``` ### Response #### Success Response (200) - **response** (string) - The output from the QEMU monitor command. ``` -------------------------------- ### Virtual Machine Configuration Before v0.7.0 Source: https://github.com/luthermonson/go-proxmox/blob/main/migration/v0.7.0.md This snippet demonstrates the structure of a VirtualMachineConfig before version 0.7.0, where fields were direct values. ```go cfg := &proxmox.VirtualMachineConfig{ Memory: StringOrInt(4096), Cores: 4, Sockets: 2, OSType: "l26", Bios: "ovmf", SCSIHW: "virtio-scsi-pci", CPUUnits: 1024, } ``` -------------------------------- ### Get Specific 2FA Entry Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/cluster-api.md Retrieves details of a specific 2FA entry for a user. Requires user ID and entry ID. ```go func (c *Client) TFAEntry(ctx context.Context, userid, id string) (*TFAEntryInfo, error) ``` -------------------------------- ### Get Permissions Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/cluster-api.md Retrieves permissions for a specific user or API token. Requires query options including path and user ID. ```go func (c *Client) Permissions(ctx context.Context, o *PermissionsOptions) (Permissions, error) ``` -------------------------------- ### Configure Client with API Token Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/configuration.md Use `WithAPIToken` for authentication with an API token, recommended for automated use. It does not require session management or support 2FA. ```go client := proxmox.NewClient( "https://pve.example.com:8006/api2/json", proxmox.WithAPIToken("root@pam!automation", "uuid-secret-from-pve-ui"), ) ``` -------------------------------- ### Get Specific Ceph OSD Handle Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/advanced-features.md Returns a handle to a specific Ceph OSD by its ID. Requires a context and the OSD integer ID. ```go func (ceph *Ceph) OSD(ctx context.Context, osd int) (*CephOSD, error) ``` -------------------------------- ### Get Specific SDN Virtual Network Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/advanced-features.md Fetches a handle to a specific virtual network (VNet) by its identifier. This allows for detailed inspection and modification. ```go func (cl *Cluster) SDNVNet(ctx context.Context, vnet string) (*SDNVNet, error) ``` -------------------------------- ### Get Specific SDN Zone Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/advanced-features.md Fetches a handle to a specific SDN zone using its unique identifier. Allows for subsequent operations on that zone. ```go func (cl *Cluster) SDNZone(ctx context.Context, zone string) (*SDNZone, error) ``` -------------------------------- ### Send QEMU Monitor Command Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/vm-container-api.md Sends a QEMU monitor command to a running VM and returns the response. Requires appropriate permissions and caution when using custom commands. ```go func (vm *VirtualMachine) MonitorCommand(ctx context.Context, command string) (string, error) ``` -------------------------------- ### Initialize Proxmox API Client Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/client-core.md Creates a new Proxmox API client with a base URL and optional configuration options like API token authentication and request timeout. ```go client := proxmox.NewClient( "https://pve.example.com:8006/api2/json", proxmox.WithAPIToken("root@pam!mytoken", "secret"), proxmox.WithTimeout(30*time.Second), ) ``` -------------------------------- ### Check VM Access Permission using Subdirs Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/INDEX.md Demonstrates how to check if the current user has permission to access virtual machine resources by examining the 'subdirs' returned by the node. Requires importing the 'slices' package. ```go subdirs, _ := node.Subdirs(ctx) if slices.Contains(subdirs, "qemu") { // Can access VMs } ``` -------------------------------- ### Get VNC WebSocket Path Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/vm-container-api.md Returns the API path for establishing a VNC WebSocket connection to the VM. This path is used in conjunction with the Client.VNCWebSocket method. ```go func (vm *VirtualMachine) VNCProxyPath() string ``` -------------------------------- ### Get Terminal WebSocket Path Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/vm-container-api.md Returns the API path for establishing a terminal WebSocket connection to the VM. This path is used in conjunction with the Client.TermWebSocket method. ```go func (vm *VirtualMachine) TermProxyPath() string ``` -------------------------------- ### APTRepository Type Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/types.md Represents a single repository entry within an APT sources file. ```go type APTRepository struct { Enabled bool FileType string // "list" or "sources" Types []string // e.g., ["deb", "deb-src"] URIs []string Suites []string // e.g., ["bookworm"] Components []string // e.g., ["main", "contrib"] Options []*APTRepositoryOption Comment string } ``` -------------------------------- ### Get Node Status Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/node-api.md Retrieves current node status including CPU, memory, and disk usage. Requires a context and a client-side Node object. ```go node, _ := client.Node(ctx, "pve") status, _ := node.Status(ctx) fmt.Printf("CPU: %.1f%%, Memory: %d MB / %d MB\n", status.CPU * 100, status.MemUsed / 1024 / 1024, status.MaxMem / 1024 / 1024) ``` -------------------------------- ### VirtualMachine.Start Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/vm-container-api.md Powers on a virtual machine. This operation has no effect if the VM is already running. ```APIDOC ## VirtualMachine.Start ### Description Powers on the VM. No-op if already running. ### Method POST ### Endpoint /nodes/{node}/qemu/{vmid}/status/start ### Response #### Success Response (200) - **`*Task`** (object) - Async startup task. ``` -------------------------------- ### Create VM Snapshot Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/vm-container-api.md Creates a new snapshot of a virtual machine's current state. The snapshot creation is an asynchronous task. ```Go vm, _ := node.VirtualMachine(ctx, 100) task, _ := vm.NewSnapshot(ctx, "backup-before-update", "") _ = task.Wait(ctx, 5*time.Minute) ``` -------------------------------- ### Get Specific HA Group Handle Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/advanced-features.md Obtains a handle for a specific HA group by its name. Use this handle to manage the group's configuration and settings. ```go func (ha *HA) Group(ctx context.Context, group string) (*HAGroup, error) ``` -------------------------------- ### VirtualMachine.Snapshots Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/vm-container-api.md Lists all available snapshots for a given virtual machine. ```APIDOC ## VirtualMachine.Snapshots ### Description Lists all snapshots of this VM. ### Method GET ### Endpoint /nodes/{node}/qemu/{vmid}/snapshot ### Response #### Success Response (200) - **`[]*VirtualMachineSnapshot`** (array) - List of snapshot handles. ``` -------------------------------- ### Get HA Manager Handle Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/advanced-features.md Provides access to the High Availability (HA) cluster manager. Use this handle to interact with HA status, resources, and groups. ```go func (cl *Cluster) HA() *HA ``` -------------------------------- ### Get Specific Cluster Storage Handle Source: https://github.com/luthermonson/go-proxmox/blob/main/_autodocs/api-reference/cluster-api.md Obtain a handle to a specific cluster storage by its name. This allows for detailed inspection or management of a particular storage resource. ```go storage, err := client.ClusterStorage(ctx, "local-lvm") if err != nil { log.Fatal(err) } // Process storage object ``` -------------------------------- ### Permission Discovery via Subdirs Source: https://github.com/luthermonson/go-proxmox/blob/main/README.md Shows how to use the `Subdirs` method on resources like Nodes and Clusters to discover accessible sub-resources for a given API token. This helps in probing permissions without triggering 403 errors. ```go node, _ := client.Node(ctx, "pve1") subdirs, _ := node.Subdirs(ctx) // ["qemu", "lxc", "storage", ...] filtered by ACL fw, _ := node.FirewallSubdirs(ctx) // ["rules", "options", "log"] if reachable cluster, _ := client.Cluster(ctx) sdnAreas, _ := cluster.SDNSubdirs(ctx) // ["vnets", "zones", "controllers", ...] ```