mirror of
https://github.com/linka-cloud/d2vm.git
synced 2024-11-26 17:46:24 +00:00
run: fix flags not applied
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
parent
89f06e2f18
commit
bdee0559d4
@ -26,19 +26,19 @@ const (
|
|||||||
var (
|
var (
|
||||||
defaultArch string
|
defaultArch string
|
||||||
defaultAccel string
|
defaultAccel string
|
||||||
enableGUI *bool
|
enableGUI bool
|
||||||
disks Disks
|
disks Disks
|
||||||
data *string
|
data string
|
||||||
accel *string
|
accel string
|
||||||
arch *string
|
arch string
|
||||||
cpus *uint
|
cpus uint
|
||||||
mem *uint
|
mem uint
|
||||||
qemuCmd *string
|
qemuCmd string
|
||||||
qemuDetached *bool
|
qemuDetached bool
|
||||||
networking *string
|
networking string
|
||||||
publishFlags MultipleFlag
|
publishFlags MultipleFlag
|
||||||
deviceFlags MultipleFlag
|
deviceFlags MultipleFlag
|
||||||
usbEnabled *bool
|
usbEnabled bool
|
||||||
|
|
||||||
QemuCmd = &cobra.Command{
|
QemuCmd = &cobra.Command{
|
||||||
Use: "qemu [options] [image-path]",
|
Use: "qemu [options] [image-path]",
|
||||||
@ -65,37 +65,30 @@ func init() {
|
|||||||
defaultAccel = "hvf:tcg"
|
defaultAccel = "hvf:tcg"
|
||||||
}
|
}
|
||||||
flags := QemuCmd.Flags()
|
flags := QemuCmd.Flags()
|
||||||
// flags.Usage = func() {
|
|
||||||
// fmt.Printf("Options:")
|
flags.BoolVar(&enableGUI, "gui", false, "Set qemu to use video output instead of stdio")
|
||||||
// flags.PrintDefaults()
|
|
||||||
// fmt.Printf("")
|
|
||||||
// fmt.Printf("If not running as root note that '--networking bridge,br0' requires a")
|
|
||||||
// fmt.Printf("setuid network helper and appropriate host configuration, see")
|
|
||||||
// fmt.Printf("https://wiki.qemu.org/Features/HelperNetworking")
|
|
||||||
// }
|
|
||||||
enableGUI = flags.Bool("gui", false, "Set qemu to use video output instead of stdio")
|
|
||||||
|
|
||||||
// Paths and settings for disks
|
// Paths and settings for disks
|
||||||
flags.Var(&disks, "disk", "Disk config, may be repeated. [file=]path[,size=1G][,format=qcow2]")
|
flags.Var(&disks, "disk", "Disk config, may be repeated. [file=]path[,size=1G][,format=qcow2]")
|
||||||
data = flags.String("data", "", "String of metadata to pass to VM; error to specify both -data and -data-file")
|
flags.StringVar(&data, "data", "", "String of metadata to pass to VM; error to specify both -data and -data-file")
|
||||||
|
|
||||||
// VM configuration
|
// VM configuration
|
||||||
accel = flags.String("accel", defaultAccel, "Choose acceleration mode. Use 'tcg' to disable it.")
|
flags.StringVar(&accel, "accel", defaultAccel, "Choose acceleration mode. Use 'tcg' to disable it.")
|
||||||
arch = flags.String("arch", defaultArch, "Type of architecture to use, e.g. x86_64, aarch64, s390x")
|
flags.StringVar(&arch, "arch", defaultArch, "Type of architecture to use, e.g. x86_64, aarch64, s390x")
|
||||||
cpus = flags.Uint("cpus", 1, "Number of CPUs")
|
flags.UintVar(&cpus, "cpus", 1, "Number of CPUs")
|
||||||
mem = flags.Uint("mem", 1024, "Amount of memory in MB")
|
flags.UintVar(&mem, "mem", 1024, "Amount of memory in MB")
|
||||||
|
|
||||||
// Backend configuration
|
// Backend configuration
|
||||||
qemuCmd = flags.String("qemu", "", "Path to the qemu binary (otherwise look in $PATH)")
|
flags.StringVar(&qemuCmd, "qemu", "", "Path to the qemu binary (otherwise look in $PATH)")
|
||||||
qemuDetached = flags.Bool("detached", false, "Set qemu container to run in the background")
|
flags.BoolVar(&qemuDetached, "detached", false, "Set qemu container to run in the background")
|
||||||
|
|
||||||
// Networking
|
// Networking
|
||||||
networking = flags.String("networking", qemuNetworkingDefault, "Networking mode. Valid options are 'default', 'user', 'bridge[,name]', tap[,name] and 'none'. 'user' uses QEMUs userspace networking. 'bridge' connects to a preexisting bridge. 'tap' uses a prexisting tap device. 'none' disables networking.`")
|
flags.StringVar(&networking, "networking", qemuNetworkingDefault, "Networking mode. Valid options are 'default', 'user', 'bridge[,name]', tap[,name] and 'none'. 'user' uses QEMUs userspace networking. 'bridge' connects to a preexisting bridge. 'tap' uses a prexisting tap device. 'none' disables networking.`")
|
||||||
|
|
||||||
flags.Var(&publishFlags, "publish", "Publish a vm's port(s) to the host (default [])")
|
flags.Var(&publishFlags, "publish", "Publish a vm's port(s) to the host (default [])")
|
||||||
|
|
||||||
// USB devices
|
// USB devices
|
||||||
usbEnabled = flags.Bool("usb", false, "Enable USB controller")
|
flags.BoolVar(&usbEnabled, "usb", false, "Enable USB controller")
|
||||||
|
|
||||||
flags.Var(&deviceFlags, "device", "Add USB host device(s). Format driver[,prop=value][,...] -- add device, like -device on the qemu command line.")
|
flags.Var(&deviceFlags, "device", "Add USB host device(s). Format driver[,prop=value][,...] -- add device, like -device on the qemu command line.")
|
||||||
|
|
||||||
@ -107,7 +100,7 @@ func Qemu(cmd *cobra.Command, args []string) {
|
|||||||
vmUUID := uuid.New()
|
vmUUID := uuid.New()
|
||||||
// These envvars override the corresponding command line
|
// These envvars override the corresponding command line
|
||||||
// options. So this must remain after the `flags.Parse` above.
|
// options. So this must remain after the `flags.Parse` above.
|
||||||
*accel = GetStringValue("LINUXKIT_QEMU_ACCEL", *accel, "")
|
accel = GetStringValue("LINUXKIT_QEMU_ACCEL", accel, "")
|
||||||
|
|
||||||
path := args[0]
|
path := args[0]
|
||||||
|
|
||||||
@ -134,11 +127,11 @@ func Qemu(cmd *cobra.Command, args []string) {
|
|||||||
|
|
||||||
disks = append(Disks{DiskConfig{Path: path}}, disks...)
|
disks = append(Disks{DiskConfig{Path: path}}, disks...)
|
||||||
|
|
||||||
if *networking == "" || *networking == "default" {
|
if networking == "" || networking == "default" {
|
||||||
dflt := qemuNetworkingDefault
|
dflt := qemuNetworkingDefault
|
||||||
networking = &dflt
|
networking = dflt
|
||||||
}
|
}
|
||||||
netMode := strings.SplitN(*networking, ",", 2)
|
netMode := strings.SplitN(networking, ",", 2)
|
||||||
|
|
||||||
var netdevConfig string
|
var netdevConfig string
|
||||||
switch netMode[0] {
|
switch netMode[0] {
|
||||||
@ -171,18 +164,18 @@ func Qemu(cmd *cobra.Command, args []string) {
|
|||||||
|
|
||||||
config := QemuConfig{
|
config := QemuConfig{
|
||||||
Path: path,
|
Path: path,
|
||||||
GUI: *enableGUI,
|
GUI: enableGUI,
|
||||||
Disks: disks,
|
Disks: disks,
|
||||||
Arch: *arch,
|
Arch: arch,
|
||||||
CPUs: *cpus,
|
CPUs: cpus,
|
||||||
Memory: *mem,
|
Memory: mem,
|
||||||
Accel: *accel,
|
Accel: accel,
|
||||||
Detached: *qemuDetached,
|
Detached: qemuDetached,
|
||||||
QemuBinPath: *qemuCmd,
|
QemuBinPath: qemuCmd,
|
||||||
PublishedPorts: publishFlags,
|
PublishedPorts: publishFlags,
|
||||||
NetdevConfig: netdevConfig,
|
NetdevConfig: netdevConfig,
|
||||||
UUID: vmUUID,
|
UUID: vmUUID,
|
||||||
USB: *usbEnabled,
|
USB: usbEnabled,
|
||||||
Devices: deviceFlags,
|
Devices: deviceFlags,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,26 +25,26 @@ var (
|
|||||||
Run: Vbox,
|
Run: Vbox,
|
||||||
}
|
}
|
||||||
|
|
||||||
vboxmanageFlag *string
|
vboxmanageFlag string
|
||||||
vmName *string
|
vmName string
|
||||||
networks VBNetworks
|
networks VBNetworks
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flags := VboxCmd.Flags()
|
flags := VboxCmd.Flags()
|
||||||
// Display flags
|
// Display flags
|
||||||
enableGUI = flags.Bool("gui", false, "Show the VM GUI")
|
flags.Bool("gui", false, "Show the VM GUI")
|
||||||
|
|
||||||
// vbox options
|
// vbox options
|
||||||
vboxmanageFlag = flags.String("vboxmanage", "VBoxManage", "VBoxManage binary to use")
|
flags.StringVar(&vboxmanageFlag, "vboxmanage", "VBoxManage", "VBoxManage binary to use")
|
||||||
vmName = flags.String("name", "", "Name of the Virtualbox VM")
|
flags.StringVar(&vmName, "name", "", "Name of the Virtualbox VM")
|
||||||
|
|
||||||
// Paths and settings for disks
|
// Paths and settings for disks
|
||||||
flags.Var(&disks, "disk", "Disk config, may be repeated. [file=]path[,size=1G][,format=raw]")
|
flags.Var(&disks, "disk", "Disk config, may be repeated. [file=]path[,size=1G][,format=raw]")
|
||||||
|
|
||||||
// VM configuration
|
// VM configuration
|
||||||
cpus = flags.Uint("cpus", 1, "Number of CPUs")
|
flags.Uint("cpus", 1, "Number of CPUs")
|
||||||
mem = flags.Uint("mem", 1024, "Amount of memory in MB")
|
flags.Uint("mem", 1024, "Amount of memory in MB")
|
||||||
|
|
||||||
// networking
|
// networking
|
||||||
flags.Var(&networks, "networking", "Network config, may be repeated. [type=](null|nat|bridged|intnet|hostonly|generic|natnetwork[<devicename>])[,[bridge|host]adapter=<interface>]")
|
flags.Var(&networks, "networking", "Network config, may be repeated. [type=](null|nat|bridged|intnet|hostonly|generic|natnetwork[<devicename>])[,[bridge|host]adapter=<interface>]")
|
||||||
@ -57,12 +57,12 @@ func init() {
|
|||||||
func Vbox(cmd *cobra.Command, args []string) {
|
func Vbox(cmd *cobra.Command, args []string) {
|
||||||
path := args[0]
|
path := args[0]
|
||||||
|
|
||||||
vboxmanage, err := exec.LookPath(*vboxmanageFlag)
|
vboxmanage, err := exec.LookPath(vboxmanageFlag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Cannot find management binary %s: %v", *vboxmanageFlag, err)
|
log.Fatalf("Cannot find management binary %s: %v", vboxmanageFlag, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
name := *vmName
|
name := vmName
|
||||||
if name == "" {
|
if name == "" {
|
||||||
name = strings.TrimSuffix(filepath.Base(path), filepath.Ext(path))
|
name = strings.TrimSuffix(filepath.Base(path), filepath.Ext(path))
|
||||||
}
|
}
|
||||||
@ -80,12 +80,12 @@ func Vbox(cmd *cobra.Command, args []string) {
|
|||||||
log.Fatalf("modifyvm --acpi error: %v\n%s", err, out)
|
log.Fatalf("modifyvm --acpi error: %v\n%s", err, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, out, err = manage(vboxmanage, "modifyvm", name, "--memory", fmt.Sprintf("%d", *mem))
|
_, out, err = manage(vboxmanage, "modifyvm", name, "--memory", fmt.Sprintf("%d", mem))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("modifyvm --memory error: %v\n%s", err, out)
|
log.Fatalf("modifyvm --memory error: %v\n%s", err, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, out, err = manage(vboxmanage, "modifyvm", name, "--cpus", fmt.Sprintf("%d", *cpus))
|
_, out, err = manage(vboxmanage, "modifyvm", name, "--cpus", fmt.Sprintf("%d", cpus))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("modifyvm --cpus error: %v\n%s", err, out)
|
log.Fatalf("modifyvm --cpus error: %v\n%s", err, out)
|
||||||
}
|
}
|
||||||
@ -200,7 +200,7 @@ func Vbox(cmd *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var vmType string
|
var vmType string
|
||||||
if *enableGUI {
|
if enableGUI {
|
||||||
vmType = "gui"
|
vmType = "gui"
|
||||||
} else {
|
} else {
|
||||||
vmType = "headless"
|
vmType = "headless"
|
||||||
|
Loading…
Reference in New Issue
Block a user