f-25: vms: add handle gestion
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
b84e0e9cbe
commit
dbe7e9dd52
2 changed files with 67 additions and 0 deletions
53
internal/qemu/start_linux.go
Normal file
53
internal/qemu/start_linux.go
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
//go:build linux
|
||||||
|
|
||||||
|
package qemu
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
|
"git.g3e.fr/syonad/two/internal/netns"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Name string
|
||||||
|
VpcName string
|
||||||
|
TapID int
|
||||||
|
Mac string
|
||||||
|
VolumePath string
|
||||||
|
Memory int
|
||||||
|
CPUs int
|
||||||
|
}
|
||||||
|
|
||||||
|
func Start(cfg Config) error {
|
||||||
|
memory := cfg.Memory
|
||||||
|
if memory == 0 {
|
||||||
|
memory = 512
|
||||||
|
}
|
||||||
|
|
||||||
|
cpus := cfg.CPUs
|
||||||
|
if cpus == 0 {
|
||||||
|
cpus = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
return netns.Call(cfg.VpcName, func() error {
|
||||||
|
cmd := exec.Command("qemu-system-x86_64",
|
||||||
|
"-enable-kvm",
|
||||||
|
"-cpu", "host",
|
||||||
|
"-m", fmt.Sprintf("%d", memory),
|
||||||
|
"-smp", fmt.Sprintf("%d", cpus),
|
||||||
|
"-serial", fmt.Sprintf("unix:/tmp/%s.sock,server,nowait", cfg.Name),
|
||||||
|
"-monitor", fmt.Sprintf("unix:/tmp/%s.mon-sock,server,nowait", cfg.Name),
|
||||||
|
"-qmp", fmt.Sprintf("unix:/tmp/%s.qmp-sock,server,nowait", cfg.Name),
|
||||||
|
"-display", "none",
|
||||||
|
"-drive", fmt.Sprintf("file=%s,if=virtio", cfg.VolumePath),
|
||||||
|
"-netdev", fmt.Sprintf("tap,id=net0,ifname=tap%d,script=no,downscript=no", cfg.TapID),
|
||||||
|
"-device", fmt.Sprintf("virtio-net-pci,netdev=net0,mac=%s", cfg.Mac),
|
||||||
|
"-daemonize",
|
||||||
|
)
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
return fmt.Errorf("qemu-system-x86_64: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
14
internal/qemu/start_other.go
Normal file
14
internal/qemu/start_other.go
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
//go:build !linux
|
||||||
|
|
||||||
|
package qemu
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Name, VpcName, Mac, VolumePath string
|
||||||
|
TapID, Memory, CPUs int
|
||||||
|
}
|
||||||
|
|
||||||
|
func Start(cfg Config) error {
|
||||||
|
return errors.New("vm: not supported on this platform")
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue