mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-20 15:31:24 +02:00
feat(proxmox): support node-level routes and journalctl access
This change enables Proxmox node-level operations without requiring a specific
LXC container VMID.
**Features added:**
- New `/proxmox/journalctl/{node}` API endpoint for streaming node journalctl
- Route configuration support for Proxmox nodes (VMID = 0)
- `ReverseLookupNode` function for node discovery by hostname/IP/alias
- `NodeJournalctl` method for executing journalctl on nodes
**Behavior changes:**
- VMID parameter in journalctl endpoints is now optional
- Routes targeting nodes (without specific containers) are now valid
**Bug fixes:**
- Fixed error message variable reference in route validation
This commit is contained in:
@@ -147,6 +147,34 @@ func (c *Client) ReverseLookupResource(ip net.IP, hostname string, alias string)
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
|
||||
// ReverseLookupNode looks up a node by name or IP address.
|
||||
// Returns the node name if found.
|
||||
func (c *Client) ReverseLookupNode(hostname string, ip net.IP, alias string) string {
|
||||
shouldCheckHostname := hostname != ""
|
||||
shouldCheckIP := ip != nil && !ip.IsLoopback() && !ip.IsUnspecified()
|
||||
shouldCheckAlias := alias != ""
|
||||
|
||||
if shouldCheckHostname {
|
||||
hostname, _, _ = strings.Cut(hostname, ".")
|
||||
}
|
||||
|
||||
for _, node := range c.Cluster.Nodes {
|
||||
if shouldCheckHostname && node.Name == hostname {
|
||||
return node.Name
|
||||
}
|
||||
if shouldCheckIP {
|
||||
nodeIP := net.ParseIP(node.IP)
|
||||
if nodeIP != nil && nodeIP.Equal(ip) {
|
||||
return node.Name
|
||||
}
|
||||
}
|
||||
if shouldCheckAlias && node.Name == alias {
|
||||
return node.Name
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Key implements pool.Object
|
||||
func (c *Client) Key() string {
|
||||
return c.Cluster.ID
|
||||
|
||||
@@ -186,3 +186,14 @@ func (n *Node) NodeCommand(ctx context.Context, command string) (io.ReadCloser,
|
||||
|
||||
return pr, nil
|
||||
}
|
||||
|
||||
func (n *Node) NodeJournalctl(ctx context.Context, service string, limit int) (io.ReadCloser, error) {
|
||||
command := "journalctl -f"
|
||||
if service != "" {
|
||||
command = fmt.Sprintf("journalctl -u %q -f", service)
|
||||
}
|
||||
if limit > 0 {
|
||||
command = fmt.Sprintf("%s -n %d", command, limit)
|
||||
}
|
||||
return n.NodeCommand(ctx, command)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user