diff --git a/internal/api/v1/proxmox/common.go b/internal/api/v1/proxmox/common.go index 18864910..d24764a5 100644 --- a/internal/api/v1/proxmox/common.go +++ b/internal/api/v1/proxmox/common.go @@ -2,5 +2,5 @@ package proxmoxapi type ActionRequest struct { Node string `uri:"node" binding:"required"` - VMID int `uri:"vmid" binding:"required"` + VMID uint64 `uri:"vmid" binding:"required"` } // @name ProxmoxVMActionRequest diff --git a/internal/api/v1/proxmox/stats.go b/internal/api/v1/proxmox/stats.go index 0220b628..1ab60b88 100644 --- a/internal/api/v1/proxmox/stats.go +++ b/internal/api/v1/proxmox/stats.go @@ -11,10 +11,7 @@ import ( "github.com/yusing/goutils/http/websocket" ) -type StatsRequest struct { - Node string `uri:"node" binding:"required"` - VMID int `uri:"vmid" binding:"required"` -} +type StatsRequest ActionRequest // @x-id "nodeStats" // @BasePath /api/v1 diff --git a/internal/idlewatcher/provider/proxmox.go b/internal/idlewatcher/provider/proxmox.go index 5357c399..f42cd11a 100644 --- a/internal/idlewatcher/provider/proxmox.go +++ b/internal/idlewatcher/provider/proxmox.go @@ -18,7 +18,7 @@ import ( type ProxmoxProvider struct { *proxmox.Node - vmid int + vmid uint64 lxcName string running bool } @@ -27,7 +27,7 @@ const proxmoxStateCheckInterval = 1 * time.Second var ErrNodeNotFound = gperr.New("node not found in pool") -func NewProxmoxProvider(ctx context.Context, nodeName string, vmid int) (idlewatcher.Provider, error) { +func NewProxmoxProvider(ctx context.Context, nodeName string, vmid uint64) (idlewatcher.Provider, error) { if nodeName == "" || vmid == 0 { return nil, errors.New("node name and vmid are required") } @@ -102,7 +102,7 @@ func (p *ProxmoxProvider) Watch(ctx context.Context) (<-chan watcher.Event, <-ch event := watcher.Event{ Type: events.EventTypeDocker, - ActorID: strconv.Itoa(p.vmid), + ActorID: strconv.FormatUint(p.vmid, 10), ActorName: p.lxcName, } for { diff --git a/internal/proxmox/client.go b/internal/proxmox/client.go index 674a02b6..be4cbce4 100644 --- a/internal/proxmox/client.go +++ b/internal/proxmox/client.go @@ -125,10 +125,10 @@ func (c *Client) UpdateResources(ctx context.Context) error { // GetResource gets a resource by kind and id. // kind: lxc or qemu // id: -func (c *Client) GetResource(kind string, id int) (*VMResource, error) { +func (c *Client) GetResource(kind string, id uint64) (*VMResource, error) { c.resourcesMu.RLock() defer c.resourcesMu.RUnlock() - resource, ok := c.resources[kind+"/"+strconv.Itoa(id)] + resource, ok := c.resources[kind+"/"+strconv.FormatUint(id, 10)] if !ok { return nil, ErrResourceNotFound } diff --git a/internal/proxmox/lxc.go b/internal/proxmox/lxc.go index 2670963d..d5352e60 100644 --- a/internal/proxmox/lxc.go +++ b/internal/proxmox/lxc.go @@ -41,7 +41,7 @@ const ( proxmoxTaskCheckInterval = 300 * time.Millisecond ) -func (n *Node) LXCAction(ctx context.Context, vmid int, action LXCAction) error { +func (n *Node) LXCAction(ctx context.Context, vmid uint64, action LXCAction) error { var upid proxmox.UPID if err := n.client.Post(ctx, fmt.Sprintf("/nodes/%s/lxc/%d/status/%s", n.name, vmid, action), nil, &upid); err != nil { return err @@ -82,7 +82,7 @@ func (n *Node) LXCAction(ctx context.Context, vmid int, action LXCAction) error } } -func (n *Node) LXCName(ctx context.Context, vmid int) (string, error) { +func (n *Node) LXCName(ctx context.Context, vmid uint64) (string, error) { var name nameOnly if err := n.client.Get(ctx, fmt.Sprintf("/nodes/%s/lxc/%d/status/current", n.name, vmid), &name); err != nil { return "", err @@ -90,7 +90,7 @@ func (n *Node) LXCName(ctx context.Context, vmid int) (string, error) { return name.Name, nil } -func (n *Node) LXCStatus(ctx context.Context, vmid int) (LXCStatus, error) { +func (n *Node) LXCStatus(ctx context.Context, vmid uint64) (LXCStatus, error) { var status statusOnly if err := n.client.Get(ctx, fmt.Sprintf("/nodes/%s/lxc/%d/status/current", n.name, vmid), &status); err != nil { return "", err @@ -98,17 +98,17 @@ func (n *Node) LXCStatus(ctx context.Context, vmid int) (LXCStatus, error) { return status.Status, nil } -func (n *Node) LXCIsRunning(ctx context.Context, vmid int) (bool, error) { +func (n *Node) LXCIsRunning(ctx context.Context, vmid uint64) (bool, error) { status, err := n.LXCStatus(ctx, vmid) return status == LXCStatusRunning, err } -func (n *Node) LXCIsStopped(ctx context.Context, vmid int) (bool, error) { +func (n *Node) LXCIsStopped(ctx context.Context, vmid uint64) (bool, error) { status, err := n.LXCStatus(ctx, vmid) return status == LXCStatusStopped, err } -func (n *Node) LXCSetShutdownTimeout(ctx context.Context, vmid int, timeout time.Duration) error { +func (n *Node) LXCSetShutdownTimeout(ctx context.Context, vmid uint64, timeout time.Duration) error { return n.client.Put(ctx, fmt.Sprintf("/nodes/%s/lxc/%d/config", n.name, vmid), map[string]interface{}{ "startup": fmt.Sprintf("down=%.0f", timeout.Seconds()), }, nil) diff --git a/internal/proxmox/lxc_stats.go b/internal/proxmox/lxc_stats.go index 541e57ab..d2e28652 100644 --- a/internal/proxmox/lxc_stats.go +++ b/internal/proxmox/lxc_stats.go @@ -42,7 +42,7 @@ import ( // // - format: "STATUS|CPU%%|MEM USAGE/LIMIT|MEM%%|NET I/O|BLOCK I/O" // - example: running|31.1%|9.6GiB/20GiB|48.87%|4.7GiB/3.3GiB|25GiB/36GiB -func (n *Node) LXCStats(ctx context.Context, vmid int, stream bool) (io.ReadCloser, error) { +func (n *Node) LXCStats(ctx context.Context, vmid uint64, stream bool) (io.ReadCloser, error) { if !stream { resource, err := n.client.GetResource("lxc", vmid) if err != nil { diff --git a/internal/proxmox/node.go b/internal/proxmox/node.go index 91e62b16..7b6e0a95 100644 --- a/internal/proxmox/node.go +++ b/internal/proxmox/node.go @@ -12,7 +12,7 @@ import ( type NodeConfig struct { Node string `json:"node"` - VMID *int `json:"vmid"` // unset: auto discover; explicit 0: node-level route; >0: lxc/qemu resource route + VMID *uint64 `json:"vmid"` // unset: auto discover; explicit 0: node-level route; >0: lxc/qemu resource route VMName string `json:"vmname,omitempty"` Services []string `json:"services,omitempty" aliases:"service"` Files []string `json:"files,omitempty" aliases:"file"` diff --git a/internal/route/route.go b/internal/route/route.go index 0b740431..9408745b 100644 --- a/internal/route/route.go +++ b/internal/route/route.go @@ -212,7 +212,7 @@ func (r *Route) validate() error { for _, p := range proxmoxProviders { // First check if hostname, IP, or alias matches a node (node-level route) if nodeName := p.Client().ReverseLookupNode(hostname, ip, r.Alias); nodeName != "" { - zero := 0 + zero := uint64(0) if r.Proxmox == nil { r.Proxmox = &proxmox.NodeConfig{} } @@ -226,7 +226,7 @@ func (r *Route) validate() error { // Then check if hostname, IP, or alias matches a VM resource resource, _ := p.Client().ReverseLookupResource(ip, hostname, r.Alias) if resource != nil { - vmid := int(resource.VMID) + vmid := resource.VMID if r.Proxmox == nil { r.Proxmox = &proxmox.NodeConfig{} } @@ -706,7 +706,7 @@ func (r *Route) MarshalZerologObject(e *zerolog.Event) { if r.Proxmox != nil { e.Str("proxmox", r.Proxmox.Node) if r.Proxmox.VMID != nil { - e.Int("vmid", *r.Proxmox.VMID) + e.Uint64("vmid", *r.Proxmox.VMID) } if r.Proxmox.VMName != "" { e.Str("vmname", r.Proxmox.VMName) diff --git a/internal/types/idlewatcher.go b/internal/types/idlewatcher.go index fdd5940c..e9bfa6fe 100644 --- a/internal/types/idlewatcher.go +++ b/internal/types/idlewatcher.go @@ -45,7 +45,7 @@ type ( } // @name IdlewatcherDockerConfig ProxmoxConfig struct { Node string `json:"node" validate:"required"` - VMID int `json:"vmid" validate:"required"` + VMID uint64 `json:"vmid" validate:"required"` } // @name IdlewatcherProxmoxNodeConfig ) @@ -69,14 +69,14 @@ func (c *IdlewatcherConfig) Key() string { if c.Docker != nil { return c.Docker.ContainerID } - return c.Proxmox.Node + ":" + strconv.Itoa(c.Proxmox.VMID) + return c.Proxmox.Node + ":" + strconv.FormatUint(c.Proxmox.VMID, 10) } func (c *IdlewatcherConfig) ContainerName() string { if c.Docker != nil { return c.Docker.ContainerName } - return "lxc-" + strconv.Itoa(c.Proxmox.VMID) + return "lxc-" + strconv.FormatUint(c.Proxmox.VMID, 10) } func (c *IdlewatcherConfig) Validate() error {