code cleanup
This commit is contained in:
@@ -36,10 +36,6 @@ var MimeTypes = map[string]MimeType{
|
|||||||
Type: "image/svg+xml",
|
Type: "image/svg+xml",
|
||||||
Minifier: nil,
|
Minifier: nil,
|
||||||
},
|
},
|
||||||
"png": {
|
|
||||||
Type: "image/png",
|
|
||||||
Minifier: nil,
|
|
||||||
},
|
|
||||||
"js": {
|
"js": {
|
||||||
Type: "application/javascript",
|
Type: "application/javascript",
|
||||||
Minifier: nil,
|
Minifier: nil,
|
||||||
|
|||||||
@@ -40,10 +40,6 @@ var MimeTypes = map[string]MimeType{
|
|||||||
Type: "image/svg+xml",
|
Type: "image/svg+xml",
|
||||||
Minifier: svg.Minify,
|
Minifier: svg.Minify,
|
||||||
},
|
},
|
||||||
"png": {
|
|
||||||
Type: "image/png",
|
|
||||||
Minifier: nil,
|
|
||||||
},
|
|
||||||
"js": {
|
"js": {
|
||||||
Type: "application/javascript",
|
Type: "application/javascript",
|
||||||
Minifier: js.Minify,
|
Minifier: js.Minify,
|
||||||
|
|||||||
+20
-81
@@ -11,71 +11,11 @@ import (
|
|||||||
"github.com/go-viper/mapstructure/v2"
|
"github.com/go-viper/mapstructure/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Account struct {
|
|
||||||
User paas.User
|
|
||||||
Pools map[string]Pool
|
|
||||||
}
|
|
||||||
|
|
||||||
type Pool struct {
|
type Pool struct {
|
||||||
paas.Pool `mapstructure:",squash"`
|
paas.Pool `mapstructure:",squash"`
|
||||||
ResourceCharts map[string]map[string]any
|
ResourceCharts map[string]map[string]any
|
||||||
}
|
}
|
||||||
|
|
||||||
// numerical constraint
|
|
||||||
type Constraint struct {
|
|
||||||
Max int64
|
|
||||||
Used int64
|
|
||||||
Avail int64
|
|
||||||
}
|
|
||||||
|
|
||||||
// match constraint
|
|
||||||
type Match struct {
|
|
||||||
Name string
|
|
||||||
Match string
|
|
||||||
Max int64
|
|
||||||
Used int64
|
|
||||||
Avail int64
|
|
||||||
}
|
|
||||||
|
|
||||||
type NumericResource struct {
|
|
||||||
Type string
|
|
||||||
Name string
|
|
||||||
Multiplier int64
|
|
||||||
Base uint64
|
|
||||||
Compact bool
|
|
||||||
Unit string
|
|
||||||
Display bool
|
|
||||||
Global Constraint
|
|
||||||
Nodes map[string]Constraint
|
|
||||||
Total Constraint
|
|
||||||
Category string
|
|
||||||
}
|
|
||||||
|
|
||||||
type StorageResource struct {
|
|
||||||
Type string
|
|
||||||
Name string
|
|
||||||
Multiplier int64
|
|
||||||
Base uint64
|
|
||||||
Compact bool
|
|
||||||
Unit string
|
|
||||||
Display bool
|
|
||||||
Disks []string
|
|
||||||
Global Constraint
|
|
||||||
Nodes map[string]Constraint
|
|
||||||
Total Constraint
|
|
||||||
Category string
|
|
||||||
}
|
|
||||||
|
|
||||||
type ListResource struct {
|
|
||||||
Type string
|
|
||||||
Whitelist bool
|
|
||||||
Display bool
|
|
||||||
Global []Match
|
|
||||||
Nodes map[string][]Match
|
|
||||||
Total []Match
|
|
||||||
Category string
|
|
||||||
}
|
|
||||||
|
|
||||||
type ResourceChart struct {
|
type ResourceChart struct {
|
||||||
Type string
|
Type string
|
||||||
Display bool
|
Display bool
|
||||||
@@ -103,28 +43,23 @@ var Green = color.RGB{
|
|||||||
func HandleGETAccount(c *gin.Context) {
|
func HandleGETAccount(c *gin.Context) {
|
||||||
auth, err := common.GetAuthFromRequest(c)
|
auth, err := common.GetAuthFromRequest(c)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
account := Account{}
|
|
||||||
|
|
||||||
user, err := GetUserBasic(auth)
|
user, err := GetUserBasic(auth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.HandleNonFatalError(c, err)
|
common.HandleNonFatalError(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
account.User = user
|
|
||||||
|
|
||||||
pools, err := GetUserPools(auth)
|
pools, err := GetUserPools(auth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.HandleNonFatalError(c, err)
|
common.HandleNonFatalError(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
account.Pools = pools
|
|
||||||
|
|
||||||
account.FormatPoolResourceCharts()
|
|
||||||
|
|
||||||
c.HTML(http.StatusOK, "html/account.html", gin.H{
|
c.HTML(http.StatusOK, "html/account.html", gin.H{
|
||||||
"global": common.Global,
|
"global": common.Global,
|
||||||
"page": "account",
|
"page": "account",
|
||||||
"account": account,
|
"user": user,
|
||||||
|
"pools": pools,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
c.Redirect(http.StatusFound, "/login") // if user is not authed, redirect user to login page
|
c.Redirect(http.StatusFound, "/login") // if user is not authed, redirect user to login page
|
||||||
@@ -195,7 +130,7 @@ func GetUserPools(auth paas.Auth) (map[string]Pool, error) {
|
|||||||
// depending on type, decode the apool data into the corresponding resource type
|
// depending on type, decode the apool data into the corresponding resource type
|
||||||
switch t {
|
switch t {
|
||||||
case "numeric":
|
case "numeric":
|
||||||
n := NumericResource{}
|
n := paas.NumericResource{}
|
||||||
n.Type = t
|
n.Type = t
|
||||||
err_m := mapstructure.Decode(m, &n)
|
err_m := mapstructure.Decode(m, &n)
|
||||||
err_r := mapstructure.Decode(r, &n)
|
err_r := mapstructure.Decode(r, &n)
|
||||||
@@ -204,7 +139,7 @@ func GetUserPools(auth paas.Auth) (map[string]Pool, error) {
|
|||||||
}
|
}
|
||||||
pool.ResourceCharts[category][k] = n
|
pool.ResourceCharts[category][k] = n
|
||||||
case "storage":
|
case "storage":
|
||||||
n := StorageResource{}
|
n := paas.StorageResource{}
|
||||||
n.Type = t
|
n.Type = t
|
||||||
err_m := mapstructure.Decode(m, &n)
|
err_m := mapstructure.Decode(m, &n)
|
||||||
err_r := mapstructure.Decode(r, &n)
|
err_r := mapstructure.Decode(r, &n)
|
||||||
@@ -213,7 +148,7 @@ func GetUserPools(auth paas.Auth) (map[string]Pool, error) {
|
|||||||
}
|
}
|
||||||
pool.ResourceCharts[category][k] = n
|
pool.ResourceCharts[category][k] = n
|
||||||
case "list":
|
case "list":
|
||||||
n := ListResource{}
|
n := paas.ListResource{}
|
||||||
n.Type = t
|
n.Type = t
|
||||||
err_m := mapstructure.Decode(m, &n)
|
err_m := mapstructure.Decode(m, &n)
|
||||||
err_r := mapstructure.Decode(r, &n)
|
err_r := mapstructure.Decode(r, &n)
|
||||||
@@ -229,21 +164,25 @@ func GetUserPools(auth paas.Auth) (map[string]Pool, error) {
|
|||||||
pools[poolname] = pool
|
pools[poolname] = pool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = FormatPoolResourceCharts(&pools)
|
||||||
|
if err != nil {
|
||||||
|
return pools, err
|
||||||
|
}
|
||||||
|
|
||||||
return pools, nil
|
return pools, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (account *Account) FormatPoolResourceCharts() error {
|
func FormatPoolResourceCharts(pools *map[string]Pool) error {
|
||||||
pools := account.Pools
|
for poolname, pool := range *pools {
|
||||||
for poolname, pool := range pools {
|
|
||||||
// for each resource category
|
// for each resource category
|
||||||
for categoryname, category := range pool.ResourceCharts {
|
for categoryname, category := range pool.ResourceCharts {
|
||||||
// for each resource in each category
|
// for each resource in each category
|
||||||
for resourcename, resource := range category {
|
for resourcename, resource := range category {
|
||||||
// create a resource chart for resource depending on resource type
|
// create a resource chart for resource depending on resource type
|
||||||
switch t := resource.(type) {
|
switch t := resource.(type) {
|
||||||
case NumericResource:
|
case paas.NumericResource:
|
||||||
avail, prefix := paas.FormatNumber(paas.SafeUint64(t.Total.Avail*t.Multiplier), t.Base)
|
avail, prefix := paas.FormatNumber(paas.SafeUint64(t.Total.Avail*t.Multiplier), t.Base)
|
||||||
pools[poolname].ResourceCharts[categoryname][resourcename] = ResourceChart{
|
(*pools)[poolname].ResourceCharts[categoryname][resourcename] = ResourceChart{
|
||||||
Type: t.Type,
|
Type: t.Type,
|
||||||
Display: t.Display,
|
Display: t.Display,
|
||||||
Name: t.Name,
|
Name: t.Name,
|
||||||
@@ -254,9 +193,9 @@ func (account *Account) FormatPoolResourceCharts() error {
|
|||||||
Unit: t.Unit,
|
Unit: t.Unit,
|
||||||
ColorHex: InterpolateColorHSV(Green, Red, float64(t.Total.Used)/float64(t.Total.Max)).ToHTML(),
|
ColorHex: InterpolateColorHSV(Green, Red, float64(t.Total.Used)/float64(t.Total.Max)).ToHTML(),
|
||||||
}
|
}
|
||||||
case StorageResource:
|
case paas.StorageResource:
|
||||||
avail, prefix := paas.FormatNumber(paas.SafeUint64(t.Total.Avail*t.Multiplier), t.Base)
|
avail, prefix := paas.FormatNumber(paas.SafeUint64(t.Total.Avail*t.Multiplier), t.Base)
|
||||||
pools[poolname].ResourceCharts[categoryname][resourcename] = ResourceChart{
|
(*pools)[poolname].ResourceCharts[categoryname][resourcename] = ResourceChart{
|
||||||
Type: t.Type,
|
Type: t.Type,
|
||||||
Display: t.Display,
|
Display: t.Display,
|
||||||
Name: t.Name,
|
Name: t.Name,
|
||||||
@@ -267,7 +206,7 @@ func (account *Account) FormatPoolResourceCharts() error {
|
|||||||
Unit: t.Unit,
|
Unit: t.Unit,
|
||||||
ColorHex: InterpolateColorHSV(Green, Red, float64(t.Total.Used)/float64(t.Total.Max)).ToHTML(),
|
ColorHex: InterpolateColorHSV(Green, Red, float64(t.Total.Used)/float64(t.Total.Max)).ToHTML(),
|
||||||
}
|
}
|
||||||
case ListResource:
|
case paas.ListResource:
|
||||||
l := struct {
|
l := struct {
|
||||||
Type string
|
Type string
|
||||||
Display bool
|
Display bool
|
||||||
@@ -291,7 +230,7 @@ func (account *Account) FormatPoolResourceCharts() error {
|
|||||||
ColorHex: InterpolateColorHSV(Green, Red, float64(r.Used)/float64(r.Max)).ToHTML(),
|
ColorHex: InterpolateColorHSV(Green, Red, float64(r.Used)/float64(r.Max)).ToHTML(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pools[poolname].ResourceCharts[categoryname][resourcename] = l
|
(*pools)[poolname].ResourceCharts[categoryname][resourcename] = l
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ import (
|
|||||||
"github.com/go-viper/mapstructure/v2"
|
"github.com/go-viper/mapstructure/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// imported types from fabric
|
|
||||||
|
|
||||||
type InstanceConfig struct {
|
type InstanceConfig struct {
|
||||||
paas.Instance `mapstructure:",squash"`
|
paas.Instance `mapstructure:",squash"`
|
||||||
// overrides
|
// overrides
|
||||||
@@ -28,8 +26,8 @@ type GlobalConfig struct {
|
|||||||
|
|
||||||
type PoolConfig struct {
|
type PoolConfig struct {
|
||||||
CPU struct {
|
CPU struct {
|
||||||
Global []paas.MatchLimit
|
Global []paas.Match
|
||||||
Nodes map[string][]paas.MatchLimit
|
Nodes map[string][]paas.Match
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,7 +241,7 @@ func GetCPUTypes(vm paas.InstancePath, pool string, auth paas.Auth) (common.Sele
|
|||||||
}
|
}
|
||||||
|
|
||||||
// use node specific rules if present, otherwise use global rules
|
// use node specific rules if present, otherwise use global rules
|
||||||
var userCPU []paas.MatchLimit
|
var userCPU []paas.Match
|
||||||
if _, ok := poolCPUConfig.CPU.Nodes[vm.NodeName]; ok {
|
if _, ok := poolCPUConfig.CPU.Nodes[vm.NodeName]; ok {
|
||||||
userCPU = poolCPUConfig.CPU.Nodes[vm.NodeName]
|
userCPU = poolCPUConfig.CPU.Nodes[vm.NodeName]
|
||||||
} else {
|
} else {
|
||||||
@@ -269,7 +267,7 @@ func GetCPUTypes(vm paas.InstancePath, pool string, auth paas.Auth) (common.Sele
|
|||||||
return cputypes, fmt.Errorf("request to %s resulted in %+v", path, res)
|
return cputypes, fmt.Errorf("request to %s resulted in %+v", path, res)
|
||||||
}
|
}
|
||||||
supported := struct {
|
supported := struct {
|
||||||
data []paas.MatchLimit
|
data []paas.Match
|
||||||
}{}
|
}{}
|
||||||
err = mapstructure.Decode(body, supported)
|
err = mapstructure.Decode(body, supported)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -278,7 +276,7 @@ func GetCPUTypes(vm paas.InstancePath, pool string, auth paas.Auth) (common.Sele
|
|||||||
|
|
||||||
// for each node supported cpu type, if it is NOT in the user's config (aka is not blacklisted) then add it to the options
|
// for each node supported cpu type, if it is NOT in the user's config (aka is not blacklisted) then add it to the options
|
||||||
for _, cpu := range supported.data {
|
for _, cpu := range supported.data {
|
||||||
contains := slices.ContainsFunc(userCPU, func(c paas.MatchLimit) bool {
|
contains := slices.ContainsFunc(userCPU, func(c paas.Match) bool {
|
||||||
return c.Name == cpu.Name
|
return c.Name == cpu.Name
|
||||||
})
|
})
|
||||||
if !contains {
|
if !contains {
|
||||||
|
|||||||
@@ -9,11 +9,6 @@ import (
|
|||||||
"github.com/go-viper/mapstructure/v2"
|
"github.com/go-viper/mapstructure/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// used when requesting GET /access/domains
|
|
||||||
type GetRealmsBody struct {
|
|
||||||
Data []Realm `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// stores each realm's data
|
// stores each realm's data
|
||||||
type Realm struct {
|
type Realm struct {
|
||||||
Default int `json:"default"`
|
Default int `json:"default"`
|
||||||
|
|||||||
+1
-1
Submodule proxmoxaas-common-lib updated: 05519694e1...f4deeb1ab6
@@ -39,11 +39,11 @@
|
|||||||
<h2>Account</h2>
|
<h2>Account</h2>
|
||||||
<section class="w3-card w3-padding">
|
<section class="w3-card w3-padding">
|
||||||
<h3>Account Details</h3>
|
<h3>Account Details</h3>
|
||||||
<p id="username">Username: {{.account.User.Username.UserID}}@{{.account.User.Username.Realm}}</p>
|
<p id="username">Username: {{.user.Username.UserID}}@{{.user.Username.Realm}}</p>
|
||||||
<p id="email">Email: {{.account.User.Mail}}</p>
|
<p id="email">Email: {{.user.Mail}}</p>
|
||||||
<p>Password: <button class="w3-button" id="change-password" type="button" style="padding: 0em; height: 1.5em; line-height: 1.5em;">Change Password</button></p>
|
<p>Password: <button class="w3-button" id="change-password" type="button" style="padding: 0em; height: 1.5em; line-height: 1.5em;">Change Password</button></p>
|
||||||
</section>
|
</section>
|
||||||
{{range $poolname, $pool := .account.Pools}}
|
{{range $poolname, $pool := .pools}}
|
||||||
{{template "pool-resources" $pool}}
|
{{template "pool-resources" $pool}}
|
||||||
{{end}}
|
{{end}}
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
Reference in New Issue
Block a user