Skip to content

Commit 6316042

Browse files
authoredJan 28, 2025
gok vm: add -netdev command-line flag (#79)
1 parent 9a2d415 commit 6316042

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed
 

‎internal/gok/vmrun.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type vmRunConfig struct {
4646
sudo string
4747
targetStorageBytes int
4848
arch string
49+
netdev string
4950
}
5051

5152
func (r *vmRunConfig) effectiveGoarch() string {
@@ -62,6 +63,7 @@ func init() {
6263
vmRunCmd.Flags().StringVarP(&vmRunImpl.sudo, "sudo", "", "", "Whether to elevate privileges using sudo when required (one of auto, always, never, default auto)")
6364
vmRunCmd.Flags().IntVarP(&vmRunImpl.targetStorageBytes, "target_storage_bytes", "", 1258299392, "Size of the disk image in bytes")
6465
vmRunCmd.Flags().StringVarP(&vmRunImpl.arch, "arch", "", "", "architecture for which to build and run QEMU. One of 'amd64' or 'arm64'")
66+
vmRunCmd.Flags().StringVarP(&vmRunImpl.netdev, "netdev", "", "user,id=net0,hostfwd=tcp::8080-:80,hostfwd=tcp::8022-:22", "QEMU -netdev argument")
6567
vmRunCmd.Flags().BoolVarP(&vmRunImpl.keep, "keep", "", false, "keep ephemeral disk images around instead of deleting them when QEMU exits")
6668
vmRunCmd.Flags().BoolVarP(&vmRunImpl.dry, "dryrun", "", false, "Whether to actually run QEMU or merely print the command")
6769
vmRunCmd.Flags().BoolVarP(&vmRunImpl.graphic, "graphic", "", true, "Run QEMU in graphical mode?")
@@ -166,7 +168,7 @@ func (r *vmRunConfig) runQEMU(ctx context.Context, fullDiskImage string) error {
166168
"-watchdog-action", "reset",
167169
"-smp", strconv.Itoa(max(runtime.NumCPU(), 2)),
168170
"-device", "e1000,netdev=net0",
169-
"-netdev", "user,id=net0,hostfwd=tcp::8080-:80,hostfwd=tcp::8022-:22",
171+
"-netdev", r.netdev,
170172
"-m", "1024")
171173

172174
// Start in EFI mode (not legacy BIOS) so that we get a frame buffer (for

0 commit comments

Comments
 (0)