Compare commits
2 Commits
3ed570f60a
...
d887444e41
Author | SHA1 | Date | |
---|---|---|---|
d887444e41 | |||
e0fc7253ac |
24
app/model.go
24
app/model.go
@@ -253,31 +253,31 @@ func (instance *Instance) RebuildBoot() {
|
|||||||
eligibleBoot[string(k)] = true
|
eligibleBoot[string(k)] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
x := strings.Split(instance.configBoot, "order=") // should be a;b;c;d ...
|
bootOrder := PVEObjectStringToMap(instance.configBoot)["order"]
|
||||||
if len(x) == 2 {
|
|
||||||
y := strings.Split(x[1], ";")
|
if len(bootOrder) != 0 {
|
||||||
for _, bootTarget := range y {
|
for bootTarget := range strings.SplitSeq(bootOrder, ";") { // iterate over elements selected for boot, add them to Enabled, and remove them from eligible boot target
|
||||||
_, isEligible := eligibleBoot[bootTarget]
|
_, isEligible := eligibleBoot[bootTarget]
|
||||||
if val, ok := instance.Volumes[VolumeID(bootTarget)]; ok && isEligible { // if the item is eligible and is in volumes
|
if val, ok := instance.Volumes[VolumeID(bootTarget)]; ok && isEligible { // if the item is eligible and is in volumes
|
||||||
instance.Boot.Enabled = append(instance.Boot.Enabled, val)
|
instance.Boot.Enabled = append(instance.Boot.Enabled, val)
|
||||||
eligibleBoot[bootTarget] = false
|
delete(eligibleBoot, bootTarget)
|
||||||
} else if val, ok := instance.Nets[NetID(bootTarget)]; ok && isEligible { // if the item is eligible and is in nets
|
} else if val, ok := instance.Nets[NetID(bootTarget)]; ok && isEligible { // if the item is eligible and is in nets
|
||||||
instance.Boot.Enabled = append(instance.Boot.Enabled, val)
|
instance.Boot.Enabled = append(instance.Boot.Enabled, val)
|
||||||
eligibleBoot[bootTarget] = false
|
delete(eligibleBoot, bootTarget)
|
||||||
} else {
|
} else { // item is not eligible for boot but is included in the boot order
|
||||||
log.Printf("Encountered non-eligible boot target %s in instance %s\n", bootTarget, instance.Name)
|
log.Printf("Encountered enabled but non-eligible boot target %s in instance %s\n", bootTarget, instance.Name)
|
||||||
eligibleBoot[bootTarget] = false
|
delete(eligibleBoot, bootTarget)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for bootTarget, isEligible := range eligibleBoot {
|
for bootTarget, isEligible := range eligibleBoot { // iterate over remaining items, add them to Disabled
|
||||||
if val, ok := instance.Volumes[VolumeID(bootTarget)]; ok && isEligible { // if the item is eligible and is in volumes
|
if val, ok := instance.Volumes[VolumeID(bootTarget)]; ok && isEligible { // if the item is eligible and is in volumes
|
||||||
instance.Boot.Disabled = append(instance.Boot.Disabled, val)
|
instance.Boot.Disabled = append(instance.Boot.Disabled, val)
|
||||||
} else if val, ok := instance.Nets[NetID(bootTarget)]; ok && isEligible { // if the item is eligible and is in nets
|
} else if val, ok := instance.Nets[NetID(bootTarget)]; ok && isEligible { // if the item is eligible and is in nets
|
||||||
instance.Boot.Disabled = append(instance.Boot.Disabled, val)
|
instance.Boot.Disabled = append(instance.Boot.Disabled, val)
|
||||||
} else {
|
} else { // item is not eligible and is not already in the boot order, skip adding to model
|
||||||
log.Printf("Encountered non-eligible boot target %s in instance %s\n", bootTarget, instance.Name)
|
log.Printf("Encountered disabled and non-eligible boot target %s in instance %s\n", bootTarget, instance.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -232,14 +232,11 @@ func MergeCTDisksAndUnused(cc *proxmox.ContainerConfig) map[string]string {
|
|||||||
func GetVolumeInfo(host *Node, volume string) (*Volume, error) {
|
func GetVolumeInfo(host *Node, volume string) (*Volume, error) {
|
||||||
volumeData := Volume{}
|
volumeData := Volume{}
|
||||||
|
|
||||||
storageID := strings.Split(volume, ":")[0]
|
volumeObj := PVEObjectStringToMap(volume)
|
||||||
volumeID := strings.Split(volume, ",")[0]
|
volumeFile := volumeObj[""]
|
||||||
mp := ""
|
volumeStorage := strings.Split(volumeFile, ":")[0]
|
||||||
if strings.Contains(volume, "mp=") {
|
|
||||||
x := strings.Split(volume, "mp=")[1]
|
storage, err := host.pvenode.Storage(context.Background(), volumeStorage)
|
||||||
mp = strings.Split(x, ",")[0]
|
|
||||||
}
|
|
||||||
storage, err := host.pvenode.Storage(context.Background(), storageID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &volumeData, nil
|
return &volumeData, nil
|
||||||
}
|
}
|
||||||
@@ -250,38 +247,58 @@ func GetVolumeInfo(host *Node, volume string) (*Volume, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range content {
|
for _, c := range content {
|
||||||
if c.Volid == volumeID {
|
if c.Volid == volumeFile {
|
||||||
volumeData.Storage = storageID
|
volumeData.Storage = volumeStorage
|
||||||
volumeData.Format = c.Format
|
volumeData.Format = c.Format
|
||||||
volumeData.Size = uint64(c.Size)
|
volumeData.Size = uint64(c.Size)
|
||||||
volumeData.File = volumeID
|
volumeData.File = volumeFile
|
||||||
volumeData.MP = mp
|
volumeData.MP = volumeObj["mp"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &volumeData, nil
|
return &volumeData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetNetInfo(net string) (*Net, error) {
|
func GetNetInfo(netstring string) (*Net, error) {
|
||||||
n := Net{}
|
n := Net{}
|
||||||
|
|
||||||
for _, val := range strings.Split(net, ",") {
|
netobj := PVEObjectStringToMap(netstring)
|
||||||
if strings.HasPrefix(val, "rate=") {
|
|
||||||
rate, err := strconv.ParseUint(strings.TrimPrefix(val, "rate="), 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return &n, err
|
|
||||||
}
|
|
||||||
n.Rate = rate
|
|
||||||
} else if strings.HasPrefix(val, "tag=") {
|
|
||||||
vlan, err := strconv.ParseUint(strings.TrimPrefix(val, "tag="), 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return &n, err
|
|
||||||
}
|
|
||||||
n.VLAN = vlan
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
n.Value = net
|
rate, err := strconv.ParseUint(netobj["rate"], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return &n, err
|
||||||
|
}
|
||||||
|
n.Rate = rate
|
||||||
|
|
||||||
|
vlan, err := strconv.ParseUint(netobj["tag"], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return &n, err
|
||||||
|
}
|
||||||
|
n.VLAN = vlan
|
||||||
|
|
||||||
|
n.Value = netstring
|
||||||
|
|
||||||
return &n, nil
|
return &n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// most pve objects (nets, disks, pcie, etc) have the following similar format:
|
||||||
|
// objname: v1,k2=v2,k3=v3,k4=v4 ...
|
||||||
|
// this function maps such strings to a map so that each individual key or value can be found more quickly
|
||||||
|
// in pcie or disks, the first value often does not have a key name, in such cases the key will be empty string ""
|
||||||
|
func PVEObjectStringToMap(objectstring string) map[string]string {
|
||||||
|
objectmap := map[string]string{}
|
||||||
|
for v := range strings.SplitSeq(objectstring, ",") {
|
||||||
|
key := ""
|
||||||
|
val := ""
|
||||||
|
if strings.Contains(v, "=") {
|
||||||
|
x := strings.Split(v, "=")
|
||||||
|
key = x[0]
|
||||||
|
val = x[1]
|
||||||
|
} else {
|
||||||
|
key = ""
|
||||||
|
val = v
|
||||||
|
}
|
||||||
|
objectmap[key] = val
|
||||||
|
}
|
||||||
|
return objectmap
|
||||||
|
}
|
||||||
|
30
go.mod
30
go.mod
@@ -3,32 +3,30 @@ module proxmoxaas-fabric
|
|||||||
go 1.24
|
go 1.24
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gin-gonic/gin v1.10.0
|
github.com/gin-gonic/gin v1.10.1
|
||||||
github.com/luthermonson/go-proxmox v0.2.2
|
github.com/luthermonson/go-proxmox v0.2.2
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/buger/goterm v1.0.4 // indirect
|
github.com/buger/goterm v1.0.4 // indirect
|
||||||
github.com/bytedance/sonic v1.13.2 // indirect
|
github.com/bytedance/sonic v1.14.0 // indirect
|
||||||
github.com/bytedance/sonic/loader v0.2.4 // indirect
|
github.com/bytedance/sonic/loader v0.3.0 // indirect
|
||||||
github.com/cloudwego/base64x v0.1.5 // indirect
|
github.com/cloudwego/base64x v0.1.5 // indirect
|
||||||
github.com/cloudwego/iasm v0.2.0 // indirect
|
|
||||||
github.com/diskfs/go-diskfs v1.6.0 // indirect
|
github.com/diskfs/go-diskfs v1.6.0 // indirect
|
||||||
github.com/djherbis/times v1.6.0 // indirect
|
github.com/djherbis/times v1.6.0 // indirect
|
||||||
github.com/elliotwutingfeng/asciiset v0.0.0-20240214025120-24af97c84155 // indirect
|
github.com/elliotwutingfeng/asciiset v0.0.0-20250521213949-458fd813c616 // indirect
|
||||||
github.com/gabriel-vasile/mimetype v1.4.9 // indirect
|
github.com/gabriel-vasile/mimetype v1.4.9 // indirect
|
||||||
github.com/gin-contrib/sse v1.1.0 // indirect
|
github.com/gin-contrib/sse v1.1.0 // indirect
|
||||||
github.com/go-playground/locales v0.14.1 // indirect
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
github.com/go-playground/validator/v10 v10.26.0 // indirect
|
github.com/go-playground/validator/v10 v10.27.0 // indirect
|
||||||
github.com/goccy/go-json v0.10.5 // indirect
|
github.com/goccy/go-json v0.10.5 // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/gorilla/websocket v1.5.3 // indirect
|
github.com/gorilla/websocket v1.5.3 // indirect
|
||||||
github.com/jinzhu/copier v0.4.0 // indirect
|
github.com/jinzhu/copier v0.4.0 // indirect
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
github.com/klauspost/compress v1.18.0 // indirect
|
github.com/klauspost/compress v1.18.0 // indirect
|
||||||
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
|
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
|
||||||
github.com/knz/go-libedit v1.10.1 // indirect
|
|
||||||
github.com/leodido/go-urn v1.4.0 // indirect
|
github.com/leodido/go-urn v1.4.0 // indirect
|
||||||
github.com/magefile/mage v1.15.0 // indirect
|
github.com/magefile/mage v1.15.0 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
@@ -36,17 +34,15 @@ require (
|
|||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||||
github.com/pierrec/lz4/v4 v4.1.22 // indirect
|
github.com/pierrec/lz4/v4 v4.1.22 // indirect
|
||||||
github.com/pkg/xattr v0.4.10 // indirect
|
github.com/pkg/xattr v0.4.12 // indirect
|
||||||
github.com/sirupsen/logrus v1.9.4-0.20230606125235-dd1b4c2e81af // indirect
|
|
||||||
github.com/stretchr/testify v1.10.0 // indirect
|
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
github.com/ugorji/go/codec v1.3.0 // indirect
|
||||||
github.com/ulikunitz/xz v0.5.12 // indirect
|
github.com/ulikunitz/xz v0.5.12 // indirect
|
||||||
golang.org/x/arch v0.17.0 // indirect
|
golang.org/x/arch v0.19.0 // indirect
|
||||||
golang.org/x/crypto v0.38.0 // indirect
|
golang.org/x/crypto v0.40.0 // indirect
|
||||||
golang.org/x/net v0.40.0 // indirect
|
golang.org/x/net v0.42.0 // indirect
|
||||||
golang.org/x/sys v0.33.0 // indirect
|
golang.org/x/sys v0.34.0 // indirect
|
||||||
golang.org/x/text v0.25.0 // indirect
|
golang.org/x/text v0.27.0 // indirect
|
||||||
google.golang.org/protobuf v1.36.6 // indirect
|
google.golang.org/protobuf v1.36.6 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user