Skip to content

Commit cb4a7c6

Browse files
committed
virtme-ng: introduce --console and --ssh shortcuts
Simplify the remote console and ssh options for the vng front-end: - to start a console or ssh server: $ vng --console [PORT] $ vng --ssh [PORT] - to start a console or ssh client session: $ vng --console-client [PORT] $ vng --ssh-client [PORT] Signed-off-by: Andrea Righi <arighi@nvidia.com>
1 parent 9fe51da commit cb4a7c6

File tree

2 files changed

+65
-36
lines changed

2 files changed

+65
-36
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ Requirements
129129
* Optionally, you may need virtiofsd 1.7.0 (or higher) for better filesystem
130130
performance inside the virtme-ng guests.
131131

132-
* Optionally, you may need `socat` for the `--server` and `--client` options,
133-
and the host's kernel should support VSOCK (`CONFIG_VHOST_VSOCK`).
132+
* Optionally, you may need `socat` for the `--console` and
133+
`--console-client` options, and the host's kernel should support VSOCK
134+
(`CONFIG_VHOST_VSOCK`).
134135

135136
Examples
136137
========
@@ -382,26 +383,26 @@ Examples
382383
- Connect to a simple remote shell (`socat` is required, VSOCK will be used):
383384
```
384385
# Start the vng instance with server support:
385-
$ vng --server
386+
$ vng --console
386387
387388
# In a separate terminal run the following command to connect to a remote shell:
388-
$ vng --client
389+
$ vng --console-client
389390
```
390391

391392
- Enable ssh in the vng guest:
392393
```
393394
# Start the vng instance with ssh server support:
394-
$ vng --server ssh
395+
$ vng --ssh
395396
396397
# Connect to the vng guest from the host via ssh:
397-
$ vng --client ssh
398+
$ vng --ssh-client
398399
```
399400

400401
- Generate some results inside the vng guest and copy them back to the
401402
host using scp:
402403
```
403404
# Start the vng instance with SSH server support:
404-
arighi@host~> vng --server ssh
405+
arighi@host~> vng --ssh
405406
...
406407
arighi@virtme-ng~> ./run.sh > result.txt
407408

virtme_ng/run.py

Lines changed: 57 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -487,32 +487,46 @@ def make_parser():
487487
)
488488

489489
g_remote = parser.add_argument_group(title="Remote Console")
490-
cli_srv_choices = ["console", "ssh"]
491490

492491
g_remote.add_argument(
493-
"--server",
492+
"--console",
494493
action="store",
495-
const=cli_srv_choices[0],
496494
nargs="?",
497-
choices=cli_srv_choices,
498-
help="Enable a server to communicate later from the host to the device using '--client'. "
495+
type=int,
496+
const=2222,
497+
metavar="PORT",
498+
help="Enable a server to communicate later from the host using '--console-client'. "
499499
+ "By default, a simple console will be offered using a VSOCK connection, and 'socat' for the proxy."
500500
)
501501

502502
g_remote.add_argument(
503-
"--client",
503+
"--console-client",
504504
action="store",
505-
const=cli_srv_choices[0],
506505
nargs="?",
507-
choices=cli_srv_choices,
508-
help="Connect to a VM launched with the '--server' option for a remote control.",
506+
type=int,
507+
const=2222,
508+
metavar="PORT",
509+
help="Connect to a VM launched with the '--console' option for a remote control.",
509510
)
510511

511512
g_remote.add_argument(
512-
"--port",
513+
"--ssh",
513514
action="store",
515+
nargs="?",
514516
type=int,
515-
help="Unique port to communicate with a VM.",
517+
const=2222,
518+
metavar="PORT",
519+
help="Enable SSH server to communicate later from the host to using '--ssh-client'."
520+
)
521+
522+
g_remote.add_argument(
523+
"--ssh-client",
524+
action="store",
525+
nargs="?",
526+
type=int,
527+
const=2222,
528+
metavar="PORT",
529+
help="Connect to a VM launched with the '--ssh' option for a remote control.",
516530
)
517531

518532
g_remote.add_argument(
@@ -992,23 +1006,35 @@ def _get_virtme_net_mac_address(self, args):
9921006
else:
9931007
self.virtme_param["net_mac_address"] = ""
9941008

995-
def _get_virtme_server(self, args):
996-
if args.server is not None:
997-
self.virtme_param["server"] = "--server " + args.server
1009+
def _get_virtme_console(self, args):
1010+
if args.console is not None and args.ssh is not None:
1011+
arg_fail('--console cannot be used with --ssh', show_usage=False)
1012+
1013+
if args.console is not None:
1014+
self.virtme_param["console"] = f"--server console --port {args.console}"
9981015
else:
999-
self.virtme_param["server"] = ""
1016+
self.virtme_param["console"] = ""
1017+
1018+
def _get_virtme_console_client(self, args):
1019+
if args.console_client is not None:
1020+
self.virtme_param["console_client"] = f"--client console --port {args.console_client}"
1021+
else:
1022+
self.virtme_param["console_client"] = ""
1023+
1024+
def _get_virtme_ssh(self, args):
1025+
if args.console is not None and args.ssh is not None:
1026+
arg_fail('--console cannot be used with --ssh', show_usage=False)
10001027

1001-
def _get_virtme_client(self, args):
1002-
if args.client is not None:
1003-
self.virtme_param["client"] = "--client " + args.client
1028+
if args.ssh is not None:
1029+
self.virtme_param["ssh"] = f"--server ssh --port {args.ssh}"
10041030
else:
1005-
self.virtme_param["client"] = ""
1031+
self.virtme_param["ssh"] = ""
10061032

1007-
def _get_virtme_port(self, args):
1008-
if args.port is not None:
1009-
self.virtme_param["port"] = "--port " + str(args.port)
1033+
def _get_virtme_ssh_client(self, args):
1034+
if args.ssh_client is not None:
1035+
self.virtme_param["ssh_client"] = f"--client ssh --port {args.ssh_client}"
10101036
else:
1011-
self.virtme_param["port"] = ""
1037+
self.virtme_param["ssh_client"] = ""
10121038

10131039
def _get_virtme_remote_cmd(self, args):
10141040
if args.remote_cmd is not None:
@@ -1190,9 +1216,10 @@ def run(self, args):
11901216
self._get_virtme_mods(args)
11911217
self._get_virtme_network(args)
11921218
self._get_virtme_net_mac_address(args)
1193-
self._get_virtme_server(args)
1194-
self._get_virtme_client(args)
1195-
self._get_virtme_port(args)
1219+
self._get_virtme_console(args)
1220+
self._get_virtme_console_client(args)
1221+
self._get_virtme_ssh(args)
1222+
self._get_virtme_ssh_client(args)
11961223
self._get_virtme_remote_cmd(args)
11971224
self._get_virtme_disk(args)
11981225
self._get_virtme_sound(args)
@@ -1234,9 +1261,10 @@ def run(self, args):
12341261
+ f'{self.virtme_param["mods"]} '
12351262
+ f'{self.virtme_param["network"]} '
12361263
+ f'{self.virtme_param["net_mac_address"]} '
1237-
+ f'{self.virtme_param["server"]} '
1238-
+ f'{self.virtme_param["client"]} '
1239-
+ f'{self.virtme_param["port"]} '
1264+
+ f'{self.virtme_param["console"]} '
1265+
+ f'{self.virtme_param["console_client"]} '
1266+
+ f'{self.virtme_param["ssh"]} '
1267+
+ f'{self.virtme_param["ssh_client"]} '
12401268
+ f'{self.virtme_param["remote_cmd"]} '
12411269
+ f'{self.virtme_param["disk"]} '
12421270
+ f'{self.virtme_param["sound"]} '

0 commit comments

Comments
 (0)