initial changes for API v2.0.0:

- added access manager api token to auth object
- update account page to show pool based resource quotas
- update config logic to use pool based resource quotas
- minor improvements and cleanup
This commit is contained in:
2026-05-26 20:28:21 +00:00
parent eb201de26b
commit c3fe936e05
21 changed files with 309 additions and 335 deletions
+17 -19
View File
@@ -83,13 +83,8 @@ func HandleGETInstancesFragment(c *gin.Context) {
}
func GetClusterResources(auth common.Auth) (map[uint]InstanceCard, map[string]Node, error) {
ctx := common.RequestContext{
Cookies: map[string]string{
"PVEAuthCookie": auth.Token,
"CSRFPreventionToken": auth.CSRF,
},
}
body := map[string]any{}
ctx := common.GetRequestContextFromCookies(auth)
body := []any{}
res, code, err := common.RequestGetAPI("/proxmox/cluster/resources", ctx, &body)
if err != nil {
return nil, nil, err
@@ -102,16 +97,17 @@ func GetClusterResources(auth common.Auth) (map[uint]InstanceCard, map[string]No
nodes := map[string]Node{}
// parse /proxmox/cluster/resources to separate instances and nodes
for _, v := range body["data"].([]any) {
for _, v := range body {
m := v.(map[string]any)
if m["type"] == "node" { // if type is node -> parse as Node object
switch m["type"] {
case "node": // if type is node -> parse as Node object
node := Node{}
err := mapstructure.Decode(v, &node)
if err != nil {
return nil, nil, err
}
nodes[node.Node] = node
} else if m["type"] == "lxc" || m["type"] == "qemu" { // if type is lxc or qemu -> parse as InstanceCard object
case "lxc", "qemu": // if type is lxc or qemu -> parse as InstanceCard object
instance := InstanceCard{}
err := mapstructure.Decode(v, &instance)
if err != nil {
@@ -127,9 +123,10 @@ func GetClusterResources(auth common.Auth) (map[uint]InstanceCard, map[string]No
// set instance's config link path
instance.ConfigPath = fmt.Sprintf("config?node=%s&type=%s&vmid=%d", instance.Node, instance.Type, instance.VMID)
// set the instance's console link path
if instance.Type == "qemu" {
switch instance.Type {
case "qemu":
instance.ConsolePath = fmt.Sprintf("%s/?console=kvm&vmid=%d&vmname=%s&node=%s&resize=off&cmd=&novnc=1", common.Global.PVE, instance.VMID, instance.Name, instance.Node)
} else if instance.Type == "lxc" {
case "lxc":
instance.ConsolePath = fmt.Sprintf("%s/?console=lxc&vmid=%d&vmname=%s&node=%s&resize=off&cmd=&xtermjs=1", common.Global.PVE, instance.VMID, instance.Name, instance.Node)
}
// set the instance's backups link path
@@ -138,7 +135,7 @@ func GetClusterResources(auth common.Auth) (map[uint]InstanceCard, map[string]No
instances[vmid] = instance
}
body = map[string]any{}
body = []any{}
res, code, err = common.RequestGetAPI("/proxmox/cluster/tasks", ctx, &body)
if err != nil {
return nil, nil, err
@@ -151,7 +148,7 @@ func GetClusterResources(auth common.Auth) (map[uint]InstanceCard, map[string]No
expected_state := map[uint]string{}
// iterate through recent user accessible tasks to find the task most recently made on an instance
for _, v := range body["data"].([]any) {
for _, v := range body {
// parse task as Task object
task := Task{}
err := mapstructure.Decode(v, &task)
@@ -179,10 +176,11 @@ func GetClusterResources(auth common.Auth) (map[uint]InstanceCard, map[string]No
continue
} else { // recent task is a start or stop task for user instance which is running or "OK"
if task.EndTime > most_recent_task[task.VMID] { // if the task's end time is later than the most recent one encountered
most_recent_task[task.VMID] = task.EndTime // update the most recent task
if task.Type == "qmstart" || task.Type == "vzstart" { // if the task was a start task, update the expected state to running
most_recent_task[task.VMID] = task.EndTime // update the most recent task
switch task.Type {
case "qmstart", "vzstart": // if the task was a start task, update the expected state to running
expected_state[task.VMID] = "running"
} else if task.Type == "qmstop" || task.Type == "vzstop" { // if the task was a stop task, update the expected state to stopped
case "qmstop", "vzstop": // if the task was a stop task, update the expected state to stopped
expected_state[task.VMID] = "stopped"
}
}
@@ -195,7 +193,7 @@ func GetClusterResources(auth common.Auth) (map[uint]InstanceCard, map[string]No
// get /status/current which is updated faster than /cluster/resources
instance := instances[vmid]
path := fmt.Sprintf("/proxmox/nodes/%s/%s/%d/status/current", instance.Node, instance.Type, instance.VMID)
body = map[string]any{}
body := map[string]any{}
res, code, err := common.RequestGetAPI(path, ctx, &body)
if err != nil {
return nil, nil, err
@@ -205,7 +203,7 @@ func GetClusterResources(auth common.Auth) (map[uint]InstanceCard, map[string]No
}
status := InstanceStatus{}
mapstructure.Decode(body["data"], &status)
mapstructure.Decode(body, &status)
instance.Status = status.Status
instances[vmid] = instance