f-32: disk: add boot multidisk handle
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
437766d812
commit
85c8c4e590
4 changed files with 48 additions and 24 deletions
|
|
@ -77,16 +77,21 @@ func (s *Server) startVM(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
disks := make([]dispatcher.VMDisk, len(req.Storage))
|
||||||
|
for i, s := range req.Storage {
|
||||||
|
disks[i] = dispatcher.VMDisk{Path: s.Path, Dev: s.Dev}
|
||||||
|
}
|
||||||
|
|
||||||
cmd := dispatcher.StartVMCommand{
|
cmd := dispatcher.StartVMCommand{
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
Subnet: primary.Subnet,
|
Subnet: primary.Subnet,
|
||||||
IP: primary.IP,
|
IP: primary.IP,
|
||||||
VolumePath: req.Storage[0].Path,
|
Disks: disks,
|
||||||
Memory: req.Memory,
|
Memory: req.Memory,
|
||||||
CPUs: req.CPUs,
|
CPUs: req.CPUs,
|
||||||
UEFI: req.UEFI,
|
UEFI: req.UEFI,
|
||||||
Password: req.Password,
|
Password: req.Password,
|
||||||
SSHKey: req.SSHKey,
|
SSHKey: req.SSHKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.dispatcher.Prepare(cmd); err != nil {
|
if err := s.dispatcher.Prepare(cmd); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -13,16 +13,21 @@ import (
|
||||||
"github.com/dgraph-io/badger/v4"
|
"github.com/dgraph-io/badger/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type VMDisk struct {
|
||||||
|
Path string
|
||||||
|
Dev string
|
||||||
|
}
|
||||||
|
|
||||||
type StartVMCommand struct {
|
type StartVMCommand struct {
|
||||||
Name string
|
Name string
|
||||||
Subnet string
|
Subnet string
|
||||||
IP string
|
IP string
|
||||||
VolumePath string
|
Disks []VMDisk
|
||||||
Memory int
|
Memory int
|
||||||
CPUs int
|
CPUs int
|
||||||
UEFI bool
|
UEFI bool
|
||||||
Password string
|
Password string
|
||||||
SSHKey string
|
SSHKey string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c StartVMCommand) Prepare(db *badger.DB, _ *configuration.Config) error {
|
func (c StartVMCommand) Prepare(db *badger.DB, _ *configuration.Config) error {
|
||||||
|
|
@ -44,7 +49,9 @@ func (c StartVMCommand) Prepare(db *badger.DB, _ *configuration.Config) error {
|
||||||
kv.AddInDB(db, "vm/"+c.Name+"/subnet", c.Subnet)
|
kv.AddInDB(db, "vm/"+c.Name+"/subnet", c.Subnet)
|
||||||
kv.AddInDB(db, "vm/"+c.Name+"/ip", c.IP)
|
kv.AddInDB(db, "vm/"+c.Name+"/ip", c.IP)
|
||||||
kv.AddInDB(db, "vm/"+c.Name+"/metadata_port", strconv.Itoa(port))
|
kv.AddInDB(db, "vm/"+c.Name+"/metadata_port", strconv.Itoa(port))
|
||||||
kv.AddInDB(db, "vm/"+c.Name+"/volume_path", c.VolumePath)
|
for _, d := range c.Disks {
|
||||||
|
kv.AddInDB(db, "vm/"+c.Name+"/disk/"+d.Dev, d.Path)
|
||||||
|
}
|
||||||
kv.AddInDB(db, "vm/"+c.Name+"/memory", strconv.Itoa(c.Memory))
|
kv.AddInDB(db, "vm/"+c.Name+"/memory", strconv.Itoa(c.Memory))
|
||||||
kv.AddInDB(db, "vm/"+c.Name+"/cpus", strconv.Itoa(c.CPUs))
|
kv.AddInDB(db, "vm/"+c.Name+"/cpus", strconv.Itoa(c.CPUs))
|
||||||
if c.UEFI {
|
if c.UEFI {
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ func StartVM(db *badger.DB, name string, cfg *configuration.Config) error {
|
||||||
Name: name,
|
Name: name,
|
||||||
TapID: d.tapID,
|
TapID: d.tapID,
|
||||||
Mac: d.mac,
|
Mac: d.mac,
|
||||||
VolumePath: d.volumePath,
|
VolumePath: d.disks[0].path,
|
||||||
Memory: d.memory,
|
Memory: d.memory,
|
||||||
CPUs: d.cpus,
|
CPUs: d.cpus,
|
||||||
SerialDir: cfg.QEMU.SerialDir,
|
SerialDir: cfg.QEMU.SerialDir,
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,11 @@ import (
|
||||||
"github.com/dgraph-io/badger/v4"
|
"github.com/dgraph-io/badger/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type diskEntry struct {
|
||||||
|
path string
|
||||||
|
dev string
|
||||||
|
}
|
||||||
|
|
||||||
type vmData struct {
|
type vmData struct {
|
||||||
subnetName string
|
subnetName string
|
||||||
vpcName string
|
vpcName string
|
||||||
|
|
@ -20,7 +25,7 @@ type vmData struct {
|
||||||
ip string
|
ip string
|
||||||
metadataPort string
|
metadataPort string
|
||||||
mac string
|
mac string
|
||||||
volumePath string
|
disks []diskEntry
|
||||||
memory int
|
memory int
|
||||||
cpus int
|
cpus int
|
||||||
uefi bool
|
uefi bool
|
||||||
|
|
@ -82,11 +87,18 @@ func loadVM(db *badger.DB, name string) (vmData, error) {
|
||||||
}
|
}
|
||||||
d.mac = mac
|
d.mac = mac
|
||||||
|
|
||||||
volumePath, err := kv.GetFromDB(db, "vm/"+name+"/volume_path")
|
diskEntries, err := kv.ListByPrefix(db, "vm/"+name+"/disk/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return d, fmt.Errorf("get volume_path: %w", err)
|
return d, fmt.Errorf("list disks: %w", err)
|
||||||
|
}
|
||||||
|
if len(diskEntries) == 0 {
|
||||||
|
return d, fmt.Errorf("no disks found for vm %q", name)
|
||||||
|
}
|
||||||
|
diskPrefix := "vm/" + name + "/disk/"
|
||||||
|
for key, path := range diskEntries {
|
||||||
|
dev := strings.TrimPrefix(key, diskPrefix)
|
||||||
|
d.disks = append(d.disks, diskEntry{path: path, dev: dev})
|
||||||
}
|
}
|
||||||
d.volumePath = volumePath
|
|
||||||
|
|
||||||
memoryStr, err := kv.GetFromDB(db, "vm/"+name+"/memory")
|
memoryStr, err := kv.GetFromDB(db, "vm/"+name+"/memory")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue