Compare commits

..

3 Commits

3 changed files with 58 additions and 11 deletions
+11 -10
View File
@@ -1,14 +1,14 @@
package paas_common_lib
package proxmoxaas_common_lib
type Pool struct {
PoolID string `json:"poolid"`
Path string `json:"-"` // typically /pool/poolid from proxmox, only used internally
Groups []Group `json:"groups"`
Resources map[string]any `json:"resources"`
Templates Templates `json:"templates"`
AllowedNodes map[string]bool `json:"nodes-allowed"`
VMIDRange VMID `json:"vmid-allowed"`
Backups Backups `json:"backups-allowed"` // measured in numbers
PoolID string `json:"poolid"`
Path string `json:"-"` // typically /pool/poolid from proxmox, only used internally
Groups []Group `json:"groups"`
Resources map[string]any `json:"resources"`
Templates Templates `json:"templates"`
AllowedNodes map[string]bool `json:"nodes-allowed"`
AllowedVMIDRange VMID `json:"vmid-allowed"`
AllowedBackups Backups `json:"backups-allowed"`
}
// proxmox typically formats as gid-realm for non pve realms
@@ -44,7 +44,8 @@ type VMID struct {
}
type Backups struct {
Max int `json:"max"`
MaxPerInstance int `json:"max-per-instance"`
MaxTotal int `json:"max-total"`
}
type Templates struct {
+46
View File
@@ -0,0 +1,46 @@
package proxmoxaas_common_lib
import (
"fmt"
"strings"
)
func (g Groupname) ToString() string {
return fmt.Sprintf("%s-%s", g.GroupID, g.Realm)
}
func (u Username) ToString() string {
return fmt.Sprintf("%s-%s", u.UserID, u.Realm)
}
// returns an error if the groupname format was not correct
// TODO: handle group names with x-y format where y is not a registered realm
// TODO: handle group names with x-y-z-... format
func ParseGroupname(groupname string) (Groupname, error) {
g := Groupname{}
x := strings.Split(groupname, "-")
if len(x) == 1 {
g.GroupID = groupname
g.Realm = "pve"
return g, nil
} else if len(x) == 2 {
g.GroupID = x[0]
g.Realm = x[1]
return g, nil
} else {
return g, fmt.Errorf("groupid did not follow the format <groupid> or <groupid>-<realm>")
}
}
// returns an error if the username format was not correct
func ParseUsername(username string) (Username, error) {
u := Username{}
x := strings.Split(username, "@")
if len(x) == 2 {
u.UserID = x[0]
u.Realm = x[1]
return u, nil
} else {
return u, fmt.Errorf("userid did not follow the format <userid>@<realm>")
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
package paas_common_lib
package proxmoxaas_common_lib
type Cluster struct {
Nodes map[string]*Node `json:"nodes"`